summaryrefslogtreecommitdiff
path: root/test/other
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:55 -0700
commite8cf06336b64491a2dd7538a06651e0caaf6a48d (patch)
tree9f5d4c83d03fefa54c385462f60875056a58a82c /test/other
parenteefccf252527dc5b69af5959b0b0e2ddb5c91b74 (diff)
downloadpuppet-e8cf06336b64491a2dd7538a06651e0caaf6a48d.tar.gz
Code smell: Use string interpolation
* Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
Diffstat (limited to 'test/other')
-rwxr-xr-xtest/other/puppet.rb2
-rwxr-xr-xtest/other/relationships.rb2
-rwxr-xr-xtest/other/report.rb8
-rwxr-xr-xtest/other/transactions.rb18
4 files changed, 15 insertions, 15 deletions
diff --git a/test/other/puppet.rb b/test/other/puppet.rb
index 6fdf46850..4acee3ee5 100755
--- a/test/other/puppet.rb
+++ b/test/other/puppet.rb
@@ -46,7 +46,7 @@ class TestPuppetModule < Test::Unit::TestCase
cleanup do
ENV["PATH"] = oldpath
end
- newpath = oldpath + ":" + "/something/else"
+ newpath = oldpath + ":/something/else"
assert_nothing_raised do
Puppet[:path] = newpath
end
diff --git a/test/other/relationships.rb b/test/other/relationships.rb
index abdb537a3..3ca944670 100755
--- a/test/other/relationships.rb
+++ b/test/other/relationships.rb
@@ -42,7 +42,7 @@ class TestRelationships < Test::Unit::TestCase
sources.each do |source|
targets.each do |target|
edge = deps.find { |e| e.source == source and e.target == target }
- assert(edge, "Could not find edge for %s => %s" % [source.ref, target.ref])
+ assert(edge, "Could not find edge for #{source.ref} => #{target.ref}")
if refresher
assert_equal(:ALL_EVENTS, edge.event)
diff --git a/test/other/report.rb b/test/other/report.rb
index af9ecea81..b5cbec0c3 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -78,7 +78,7 @@ class TestReports < Test::Unit::TestCase
Puppet.settings.use(:main, :master)
3.times { |i|
- log = Puppet.warning("Report test message %s" % i)
+ log = Puppet.warning("Report test message #{i}")
report << log
}
@@ -123,11 +123,11 @@ class TestReports < Test::Unit::TestCase
# Now make sure it creaets each of the rrd files
%w{changes resources time}.each do |type|
- file = File.join(hostdir, "%s.rrd" % type)
- assert(FileTest.exists?(file), "Did not create rrd file for %s" % type)
+ file = File.join(hostdir, "#{type}.rrd")
+ assert(FileTest.exists?(file), "Did not create rrd file for #{type}")
daily = file.sub ".rrd", "-daily.png"
- assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type)
+ assert(FileTest.exists?(daily), "Did not make daily graph for #{type}")
end
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 5c73f1b9d..e49e96a7f 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -146,8 +146,8 @@ class TestTransactions < Test::Unit::TestCase
end
%w{ya ra y r}.each do |name|
- assert(trans.catalog.vertex?(Puppet::Type.type(:generator)[name]), "Generated %s was not a vertex" % name)
- assert($finished.include?(name), "%s was not finished" % name)
+ assert(trans.catalog.vertex?(Puppet::Type.type(:generator)[name]), "Generated #{name} was not a vertex")
+ assert($finished.include?(name), "#{name} was not finished")
end
end
@@ -304,15 +304,15 @@ class TestTransactions < Test::Unit::TestCase
rels.each do |after, before|
config = mk_catalog(before, after)
trans = Puppet::Transaction.new(config)
- str = "from %s to %s" % [before, after]
+ str = "from #{before} to #{after}"
- assert_nothing_raised("Failed to create graph %s" % str) do
+ assert_nothing_raised("Failed to create graph #{str}") do
trans.prepare
end
graph = trans.relationship_graph
- assert(graph.edge?(before, after), "did not create manual relationship %s" % str)
- assert(! graph.edge?(after, before), "created automatic relationship %s" % str)
+ assert(graph.edge?(before, after), "did not create manual relationship #{str}")
+ assert(! graph.edge?(after, before), "created automatic relationship #{str}")
end
end
@@ -329,13 +329,13 @@ class TestTransactions < Test::Unit::TestCase
:title => "file")
exec = Puppet::Type.type(:exec).new(
- :command => "touch %s" % epath,
+ :command => "touch #{epath}",
:path => ENV["PATH"], :subscribe => file, :refreshonly => true,
:title => 'exec1')
exec2 = Puppet::Type.type(:exec).new(
- :command => "touch %s" % spath,
+ :command => "touch #{spath}",
:path => ENV["PATH"], :subscribe => exec, :refreshonly => true,
:title => 'exec2')
@@ -379,7 +379,7 @@ class TestTransactions < Test::Unit::TestCase
file = Puppet::Type.type(:file).new(
:path => path, :ensure => :absent,
- :backup => false, :title => "file%s" % i)
+ :backup => false, :title => "file#{i}")
File.open(path, "w") { |f| f.puts "" }
files << file
end