diff --git a/README b/README index 978f24f..68d6066 100644 --- a/README +++ b/README @@ -10,7 +10,6 @@ SYNOPSIS URIS http://github.com/ahoward/systemu - http://rubyforge.org/projects/codeforpeople/ INSTALL diff --git a/README.erb b/README.erb index 889a15e..ecfa107 100644 --- a/README.erb +++ b/README.erb @@ -9,7 +9,6 @@ SYNOPSIS URIS http://github.com/ahoward/systemu - http://rubyforge.org/projects/codeforpeople/ INSTALL diff --git a/Rakefile b/Rakefile index bce655c..7ed6a78 100644 --- a/Rakefile +++ b/Rakefile @@ -1,26 +1,38 @@ -This.rubyforge_project = 'codeforpeople' +require 'rbconfig' + This.author = "Ara T. Howard" This.email = "ara.t.howard@gmail.com" This.homepage = "https://github.com/ahoward/#{ This.lib }" +desc('Write "Ruby" to a file "LICENSE"') task :license do open('LICENSE', 'w'){|fd| fd.puts "Ruby"} end +desc('Print all available tasks') task :default do puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort) end +desc('Run all tests') task :test do run_tests! end namespace :test do + desc('Run tests in a sub-directory "unit" of the test directory') task(:unit){ run_tests!(:unit) } + desc('Run tests in a sub-directory "functional" of the test directory') task(:functional){ run_tests!(:functional) } + desc('Run tests in a sub-directory "integration" of the test directory') task(:integration){ run_tests!(:integration) } end +## +# Run all or a sub-set of the scripts ending in "_test.rb" within the "test" dir +# +# The parameter "which" can be utilized to request that only tests within a +# sub-directory of a certain name of "test" shall be executed. def run_tests!(which = nil) which ||= '**' test_dir = File.join(This.dir, "test") @@ -59,7 +71,7 @@ def run_tests!(which = nil) end end - +desc('Write the "systemu.gemspec" file') task :gemspec do ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem'] ignore_directories = ['pkg'] @@ -145,7 +157,6 @@ task :gemspec do spec.extensions.push(*<%= extensions.inspect %>) - spec.rubyforge_project = <%= This.rubyforge_project.inspect %> spec.author = <%= This.author.inspect %> spec.email = <%= This.email.inspect %> spec.homepage = <%= This.homepage.inspect %> @@ -160,6 +171,7 @@ task :gemspec do This.gemspec = gemspec end +desc('Clean the "pkg" directory and (re-)create the gem file') task :gem => [:clean, :gemspec] do Fu.mkdir_p(This.pkgdir) before = Dir['*.gem'] @@ -171,6 +183,7 @@ task :gem => [:clean, :gemspec] do This.gem = File.join(This.pkgdir, File.basename(gem)) end +desc('Re-generate the "README" file from the samples and the template') task :readme do samples = '' prompt = '~ > ' @@ -214,12 +227,12 @@ task :readme do open("README", "w"){|fd| fd.puts template} end - +desc('Remove all files from the "pkg" directory') task :clean do Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)} end - +desc('Clean existing gems, (re-)create gem and publish') task :release => [:clean, :gemspec, :gem] do gems = Dir[File.join(This.pkgdir, '*.gem')].flatten raise "which one? : #{ gems.inspect }" if gems.size > 1 @@ -230,12 +243,6 @@ task :release => [:clean, :gemspec, :gem] do puts system(cmd) abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? - - cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }" - puts cmd - puts - system(cmd) - abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero? end @@ -243,8 +250,7 @@ end BEGIN { -# support for this rakefile -# + # support for this rakefile $VERBOSE = nil require 'ostruct' @@ -253,28 +259,26 @@ BEGIN { require 'rbconfig' require 'pp' -# fu shortcut -# + # create a shortcut "Fu" for FileUtils Fu = FileUtils -# cache a bunch of stuff about this rakefile/environment -# + # cache a bunch of stuff about this Rakefile and its environment This = OpenStruct.new This.file = File.expand_path(__FILE__) This.dir = File.dirname(This.file) This.pkgdir = File.join(This.dir, 'pkg') -# grok lib -# + # determine the library's name lib = ENV['LIB'] unless lib + # drop anything after (including) the last '-' from the directory name to + # derive the library's name lib = File.basename(Dir.pwd).sub(/[-].*$/, '') end This.lib = lib -# grok version -# + # determine the library's version version = ENV['VERSION'] unless version require "./lib/#{ This.lib }" @@ -284,62 +288,78 @@ BEGIN { end This.version = version -# see if dependencies are export by the module -# + # see if dependencies are export by the module if This.object.respond_to?(:dependencies) This.dependencies = This.object.dependencies end -# we need to know the name of the lib an it's version -# + # the library's name and version are mandatory to be known abort('no lib') unless This.lib abort('no version') unless This.version -# discover full path to this ruby executable -# - c = Config::CONFIG + # discover the full path to this ruby executable + c = ::RbConfig::CONFIG bindir = c["bindir"] || c['BINDIR'] ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby' ruby_ext = c['EXEEXT'] || '' ruby = File.join(bindir, (ruby_install_name + ruby_ext)) This.ruby = ruby -# some utils -# + ## + # Module with utility methods used by the Rakefile module Util + ## + # Indent a string "s" with a number "n" of spaces + # + # The string will be un-intended with #unindent before the new indentation + # is being conducted. def indent(s, n = 2) s = unindent(s) ws = ' ' * n s.gsub(%r/^/, ws) end + ## + # Unindent a string "s" + # + # The indentation of the string is determined by the leading whitespaces of + # the first non-empty, non-entirely-whitespace line. def unindent(s) indent = nil s.each_line do |line| - next if line =~ %r/^\s*$/ - indent = line[%r/^\s*/] and break + next if line =~ %r/^\s*$/ + indent = line[%r/^\s*/] and break + end + indent ? s.gsub(%r/^#{ indent }/, "") : s end - indent ? s.gsub(%r/^#{ indent }/, "") : s - end + extend self end -# template support -# + ## + # Class for loading and executing ERB template code class Template + ## + # Create a new instance from a block returning the template's code def initialize(&block) @block = block @template = block.call.to_s end + + ## + # Execute the ERB template's block with an optional binding + # + # If no binding is given the binding of the blocked which got passed to the + # initializer will be used. def expand(b=nil) ERB.new(Util.unindent(@template)).result((b||@block).binding) end + alias_method 'to_s', 'expand' end def Template(*args, &block) Template.new(*args, &block) end -# colored console output support -# + # colored console output support This.ansi = { :clear => "\e[0m", :reset => "\e[0m", @@ -369,6 +389,7 @@ BEGIN { :on_cyan => "\e[46m", :on_white => "\e[47m" } + def say(phrase, *args) options = args.last.is_a?(Hash) ? args.pop : {} options[:color] = args.shift.to_s.to_sym unless args.empty? @@ -388,7 +409,6 @@ BEGIN { Kernel.send(method, parts.join) end -# always run out of the project dir -# + # always run out of the project dir itself Dir.chdir(This.dir) } diff --git a/lib/systemu.rb b/lib/systemu.rb index aa12fe4..c55fd8f 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'tmpdir' require 'socket' require 'fileutils' @@ -11,29 +9,32 @@ def systemu(*a, &b) SystemUniversal.new(*a, &b).systemu end end class SystemUniversal -# -# constants -# + # + # constants + # SystemUniversal::VERSION = '2.6.5' unless SystemUniversal.send(:const_defined?, :VERSION) def SystemUniversal.version() SystemUniversal::VERSION end def version() SystemUniversal::VERSION end def SystemUniversal.description "universal capture of stdout and stderr and handling of child process pid for windows, *nix, etc." end -# -# class methods -# + # + # instance variables + # @host = Socket.gethostname @ppid = Process.ppid @pid = Process.pid @turd = ENV['SYSTEMU_TURD'] @ruby = nil + # + # class methods + # def self.ruby return @ruby if @ruby - c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end + c = ::RbConfig::CONFIG ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT'] @ruby = if system(ruby, '-e', '42') ruby @@ -50,10 +51,9 @@ def quote(*words) end end -# -# instance methods -# - + # + # instance methods + # def initialize argv, opts = {}, &block getopt = getopts opts @@ -180,8 +180,6 @@ def quietly def child_program config <<-program - # encoding: utf-8 - PIPE = STDOUT.dup begin config = Marshal.load(IO.read('#{ config }',:mode=>"rb")) diff --git a/systemu.gemspec b/systemu.gemspec index bfe834c..7c04f05 100644 --- a/systemu.gemspec +++ b/systemu.gemspec @@ -38,7 +38,6 @@ Gem::Specification::new do |spec| spec.extensions.push(*[]) - spec.rubyforge_project = "codeforpeople" spec.author = "Ara T. Howard" spec.email = "ara.t.howard@gmail.com" spec.homepage = "https://github.com/ahoward/systemu" diff --git a/test/systemu_test.rb b/test/systemu_test.rb index 6d4bf2b..ac1e6b0 100644 --- a/test/systemu_test.rb +++ b/test/systemu_test.rb @@ -31,6 +31,16 @@ end end + testing 'query systemu version' do + # query systemu's version through the class itself + assert { SystemU.version =~ /\d+\.\d+\.\d+/ } + # query systemu's version through a class instance + assert do + a = SystemU.new('ls') + a.version =~ /\d+\.\d+\.\d+/ + end + end + end