diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
| commit | eefccf252527dc5b69af5959b0b0e2ddb5c91b74 (patch) | |
| tree | a37e13c9cd4aab7e8671004cf4f83000b52c96a8 /test | |
| parent | 184132e07fc1461555cb4da842df15f32842a843 (diff) | |
| download | puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.gz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.xz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.zip | |
Code smell: English names for special globals rather than line-noise
* Replaced 36 occurances of [$][?] with $CHILD_STATUS
3 Examples:
The code:
print "%s finished with exit code %s\n" % [host, $?.exitstatus]
becomes:
print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus]
The code:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
becomes:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus]
The code:
unless $? == 0
becomes:
unless $CHILD_STATUS == 0
* Replaced 3 occurances of [$][$] with $PID
3 Examples:
The code:
Process.kill(:HUP, $$) if restart_requested?
becomes:
Process.kill(:HUP, $PID) if restart_requested?
The code:
if pid == $$
becomes:
if pid == $PID
The code:
host[:name] = "!invalid.hostname.$$$"
becomes:
host[:name] = "!invalid.hostname.$PID$"
* Replaced 7 occurances of [$]& with $MATCH
3 Examples:
The code:
work.slice!(0, $&.length)
becomes:
work.slice!(0, $MATCH.length)
The code:
if $&
becomes:
if $MATCH
The code:
if $&
becomes:
if $MATCH
* Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH
3 Examples:
The code:
sitelibdir = $:.find { |x| x =~ /site_ruby/ }
becomes:
sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
The code:
$:.unshift "lib"
becomes:
$LOAD_PATH.unshift "lib"
The code:
$:.shift
becomes:
$LOAD_PATH.shift
* Replaced 3 occurances of [$]! with $ERROR_INFO
3 Examples:
The code:
$LOG.fatal("Problem reading #{filepath}: #{$!}")
becomes:
$LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}")
The code:
$stderr.puts "Couldn't build man pages: " + $!
becomes:
$stderr.puts "Couldn't build man pages: " + $ERROR_INFO
The code:
$stderr.puts $!.message
becomes:
$stderr.puts $ERROR_INFO.message
* Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES
3 Examples:
The code:
unless $".index 'racc/parser.rb'
becomes:
unless $LOADED_FEATURES.index 'racc/parser.rb'
The code:
$".push 'racc/parser.rb'
becomes:
$LOADED_FEATURES.push 'racc/parser.rb'
The code:
$".should be_include("tmp/myfile.rb")
becomes:
$LOADED_FEATURES.should be_include("tmp/myfile.rb")
Diffstat (limited to 'test')
| -rwxr-xr-x | test/certmgr/certmgr.rb | 2 | ||||
| -rwxr-xr-x | test/language/functions.rb | 2 | ||||
| -rwxr-xr-x | test/lib/puppettest.rb | 2 | ||||
| -rw-r--r-- | test/lib/puppettest/exetest.rb | 6 | ||||
| -rwxr-xr-x | test/other/puppet.rb | 14 | ||||
| -rwxr-xr-x | test/puppet/tc_suidmanager.rb | 4 | ||||
| -rwxr-xr-x | test/ral/type/cron.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/host.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/zone.rb | 2 | ||||
| -rwxr-xr-x | test/util/subclass_loader.rb | 4 |
10 files changed, 20 insertions, 20 deletions
diff --git a/test/certmgr/certmgr.rb b/test/certmgr/certmgr.rb index ab4372c5b..41a4a8782 100755 --- a/test/certmgr/certmgr.rb +++ b/test/certmgr/certmgr.rb @@ -170,7 +170,7 @@ class TestCertMgr < Test::Unit::TestCase #output = %x{openssl verify -CApath #{Puppet[:certdir]} -purpose sslserver #{cert.certfile}} } - assert_equal($?,0) + assert_equal($CHILD_STATUS,0) assert_equal(File.join(Puppet[:certdir], "signedcertest.pem: OK\n"), output) end diff --git a/test/language/functions.rb b/test/language/functions.rb index a9d7c1a7f..9cd4d24b5 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -402,7 +402,7 @@ class TestLangFunctions < Test::Unit::TestCase # "Got told autofunc already exists") dir = tempfile() - $: << dir + $LOAD_PATH << dir newpath = File.join(dir, "puppet", "parser", "functions") FileUtils.mkdir_p(newpath) diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index e11de04e2..522112db8 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -133,7 +133,7 @@ module PuppetTest # Rails clobbers RUBYLIB, thanks def libsetup curlibs = ENV["RUBYLIB"].split(":") - $:.reject do |dir| dir =~ /^\/usr/ end.each do |dir| + $LOAD_PATH.reject do |dir| dir =~ /^\/usr/ end.each do |dir| unless curlibs.include?(dir) curlibs << dir end diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb index 0d66c5a07..b0857d19f 100644 --- a/test/lib/puppettest/exetest.rb +++ b/test/lib/puppettest/exetest.rb @@ -27,7 +27,7 @@ module PuppetTest::ExeTest end def setlibdir - ENV["RUBYLIB"] = $:.find_all { |dir| + ENV["RUBYLIB"] = $LOAD_PATH.find_all { |dir| dir =~ /puppet/ or dir =~ /\.\./ }.join(":") end @@ -71,7 +71,7 @@ module PuppetTest::ExeTest output = %x{#{cmd}}.chomp } assert_equal("", output, "Puppetmasterd produced output %s" % output) - assert($? == 0, "Puppetmasterd exit status was %s" % $?) + assert($CHILD_STATUS == 0, "Puppetmasterd exit status was %s" % $CHILD_STATUS) sleep(1) cleanup do @@ -110,7 +110,7 @@ module PuppetTest::ExeTest # we default to mandating that it's running, but teardown # doesn't require that if pid - if pid == $$ + if pid == $PID raise Puppet::Error, "Tried to kill own pid" end begin diff --git a/test/other/puppet.rb b/test/other/puppet.rb index 0dea54da4..6fdf46850 100755 --- a/test/other/puppet.rb +++ b/test/other/puppet.rb @@ -55,11 +55,11 @@ class TestPuppetModule < Test::Unit::TestCase end def test_libdir - oldlibs = $:.dup + oldlibs = $LOAD_PATH.dup cleanup do - $:.each do |dir| + $LOAD_PATH.each do |dir| unless oldlibs.include?(dir) - $:.delete(dir) + $LOAD_PATH.delete(dir) end end end @@ -68,12 +68,12 @@ class TestPuppetModule < Test::Unit::TestCase Dir.mkdir(one) Dir.mkdir(two) - # Make sure setting the libdir gets the dir added to $: + # Make sure setting the libdir gets the dir added to $LOAD_PATH assert_nothing_raised do Puppet[:libdir] = one end - assert($:.include?(one), "libdir was not added") + assert($LOAD_PATH.include?(one), "libdir was not added") # Now change it, make sure it gets added and the old one gets # removed @@ -81,8 +81,8 @@ class TestPuppetModule < Test::Unit::TestCase Puppet[:libdir] = two end - assert($:.include?(two), "libdir was not added") - assert(! $:.include?(one), "old libdir was not removed") + assert($LOAD_PATH.include?(two), "libdir was not added") + assert(! $LOAD_PATH.include?(one), "old libdir was not removed") end end diff --git a/test/puppet/tc_suidmanager.rb b/test/puppet/tc_suidmanager.rb index 0d51ddacd..ddf6a0efc 100755 --- a/test/puppet/tc_suidmanager.rb +++ b/test/puppet/tc_suidmanager.rb @@ -122,8 +122,8 @@ class TestSUIDManager < Test::Unit::TestCase end def set_exit_status! - # We want to make sure $? is set, this is the only way I know how. - Kernel.system '' if $?.nil? + # We want to make sure $CHILD_STATUS is set, this is the only way I know how. + Kernel.system '' if $CHILD_STATUS.nil? end end diff --git a/test/ral/type/cron.rb b/test/ral/type/cron.rb index fc2d03e93..bd334f2ec 100755 --- a/test/ral/type/cron.rb +++ b/test/ral/type/cron.rb @@ -40,7 +40,7 @@ class TestCron < Test::Unit::TestCase tab = Puppet::Type.type(:cron).filetype.read(@me) } - if $? == 0 + if $CHILD_STATUS == 0 @currenttab = tab else @currenttab = nil diff --git a/test/ral/type/host.rb b/test/ral/type/host.rb index 81a4c0876..b6c4d9c66 100755 --- a/test/ral/type/host.rb +++ b/test/ral/type/host.rb @@ -130,7 +130,7 @@ class TestHost < Test::Unit::TestCase host = mkhost() assert_raise(Puppet::Error) { - host[:name] = "!invalid.hostname.$$$" + host[:name] = "!invalid.hostname.$PID$" } assert_raise(Puppet::Error) { diff --git a/test/ral/type/zone.rb b/test/ral/type/zone.rb index eaf850f59..d8a191b98 100755 --- a/test/ral/type/zone.rb +++ b/test/ral/type/zone.rb @@ -249,7 +249,7 @@ end } end - assert_equal(0, $?, "Did not successfully create zone") + assert_equal(0, $CHILD_STATUS, "Did not successfully create zone") hash = nil assert_nothing_raised { diff --git a/test/util/subclass_loader.rb b/test/util/subclass_loader.rb index ca2522dbf..622f9c356 100755 --- a/test/util/subclass_loader.rb +++ b/test/util/subclass_loader.rb @@ -17,8 +17,8 @@ class TestPuppetUtilSubclassLoader < Test::Unit::TestCase # Make a fake client unless defined?(@basedir) @basedir ||= tempfile() - $: << @basedir - cleanup { $:.delete(@basedir) if $:.include?(@basedir) } + $LOAD_PATH << @basedir + cleanup { $LOAD_PATH.delete(@basedir) if $LOAD_PATH.include?(@basedir) } end libdir = File.join([@basedir, path.split(File::SEPARATOR)].flatten) |
