From 4aa328a0b3497561074f89cf4a273fa159e025c9 Mon Sep 17 00:00:00 2001 From: markuspg Date: Tue, 14 Jun 2022 09:25:17 -0700 Subject: [PATCH 1/8] Adjust section comments --- lib/systemu.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/systemu.rb b/lib/systemu.rb index aa12fe4..edd9416 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -11,25 +11,28 @@ 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 @@ -50,10 +53,9 @@ def quote(*words) end end -# -# instance methods -# - + # + # instance methods + # def initialize argv, opts = {}, &block getopt = getopts opts From a1f3f0d78653256272f633e8d965d13b8fb46c52 Mon Sep 17 00:00:00 2001 From: markuspg Date: Tue, 14 Jun 2022 09:31:53 -0700 Subject: [PATCH 2/8] Replace deprecated Config by RbConfig It seems RbConfig was introduced somewhere around Ruby 2.0. So now that Ruby 3.1 is around its predecessor Config should be ready to be dropped. --- Rakefile | 4 +++- lib/systemu.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index bce655c..6f5e6e6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +require 'rbconfig' + This.rubyforge_project = 'codeforpeople' This.author = "Ara T. Howard" This.email = "ara.t.howard@gmail.com" @@ -297,7 +299,7 @@ BEGIN { # discover full path to this ruby executable # - c = Config::CONFIG + c = ::RbConfig::CONFIG bindir = c["bindir"] || c['BINDIR'] ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby' ruby_ext = c['EXEEXT'] || '' diff --git a/lib/systemu.rb b/lib/systemu.rb index edd9416..7b63e26 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -36,7 +36,7 @@ def SystemUniversal.description 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 From f9537a8716833b84c7012580c774938c286e2c36 Mon Sep 17 00:00:00 2001 From: markuspg Date: Tue, 14 Jun 2022 18:49:59 +0200 Subject: [PATCH 3/8] Add descriptions to all rake tasks --- Rakefile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 6f5e6e6..dc73b71 100644 --- a/Rakefile +++ b/Rakefile @@ -5,21 +5,27 @@ 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 @@ -61,7 +67,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'] @@ -162,6 +168,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'] @@ -173,6 +180,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 = '~ > ' @@ -216,12 +224,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 From cd163ce6907248661db222033dac425f702c5503 Mon Sep 17 00:00:00 2001 From: markuspg Date: Tue, 14 Jun 2022 19:05:32 +0200 Subject: [PATCH 4/8] Fix misleading indentation error in Util.unindent --- Rakefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index dc73b71..50b4976 100644 --- a/Rakefile +++ b/Rakefile @@ -326,11 +326,12 @@ BEGIN { 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 From 0e98a5d703dcd72102b3df1d8a4d419582acb41c Mon Sep 17 00:00:00 2001 From: markuspg Date: Wed, 15 Jun 2022 17:16:15 +0200 Subject: [PATCH 5/8] Drop references to now defunct RubyForge --- README | 1 - README.erb | 1 - Rakefile | 8 -------- systemu.gemspec | 1 - 4 files changed, 11 deletions(-) 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 50b4976..ab4fa8b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,5 @@ require 'rbconfig' -This.rubyforge_project = 'codeforpeople' This.author = "Ara T. Howard" This.email = "ara.t.howard@gmail.com" This.homepage = "https://github.com/ahoward/#{ This.lib }" @@ -153,7 +152,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 %> @@ -240,12 +238,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 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" From 0d5666908bbc9df1dbb5dac2639819bdd4ed4d23 Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 17 Jun 2022 15:13:39 +0200 Subject: [PATCH 6/8] Extend and unify documentation of Rakefile --- Rakefile | 65 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/Rakefile b/Rakefile index ab4fa8b..7ed6a78 100644 --- a/Rakefile +++ b/Rakefile @@ -28,6 +28,11 @@ namespace :test do 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") @@ -245,8 +250,7 @@ end BEGIN { -# support for this rakefile -# + # support for this rakefile $VERBOSE = nil require 'ostruct' @@ -255,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 }" @@ -286,19 +288,16 @@ 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 -# + # 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' @@ -306,15 +305,25 @@ BEGIN { 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| @@ -327,22 +336,30 @@ BEGIN { 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", @@ -372,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? @@ -391,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) } From 448f1fb7d9f4360f4d8b8bc17381ee3fc5135fc2 Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 17 Jun 2022 15:38:08 +0200 Subject: [PATCH 7/8] Add test for systemu version query --- test/systemu_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From 51678a37df8b6ab3a2003203feb30f9cc71ed1fd Mon Sep 17 00:00:00 2001 From: markuspg Date: Fri, 17 Jun 2022 16:05:46 +0200 Subject: [PATCH 8/8] Remove deprecated "encoding: utf-8" comments This should be obsolete since Ruby 2.0 which got released in 2013 and has been obsoleted in 2016. --- lib/systemu.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/systemu.rb b/lib/systemu.rb index 7b63e26..c55fd8f 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - require 'tmpdir' require 'socket' require 'fileutils' @@ -182,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"))