summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:05:04 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:05:04 -0700
commit9ee56f2e67be973da49b1d3f21de1bf87de35e6f (patch)
treeddab8c01509f47664c52c8a6b165bb5a974f138f /spec/unit/parser
parent051bd98751d9d4bc97f93f66723d9b7a00c0cfb4 (diff)
downloadpuppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.gz
puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.xz
puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.zip
Code smell: Inconsistent indentation and related formatting issues
* Replaced 163 occurances of defined\? +([@a-zA-Z_.0-9?=]+) with defined?(\1) This makes detecting subsequent patterns easier. 3 Examples: The code: if ! defined? @parse_config becomes: if ! defined?(@parse_config) The code: return @option_parser if defined? @option_parser becomes: return @option_parser if defined?(@option_parser) The code: if defined? @local and @local becomes: if defined?(@local) and @local * Eliminate trailing spaces. Replaced 428 occurances of ^(.*?) +$ with \1 1 file was skipped. test/ral/providers/host/parsed.rb because 0 * Replace leading tabs with an appropriate number of spaces. Replaced 306 occurances of ^(\t+)(.*) with Tabs are not consistently expanded in all environments. * Don't arbitrarily wrap on sprintf (%) operator. Replaced 143 occurances of (.*['"] *%) +(.*) with Splitting the line does nothing to aid clarity and hinders further refactorings. 3 Examples: The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] 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, $?.exitstatus] * Don't break short arrays/parameter list in two. Replaced 228 occurances of (.*) +(.*) with 3 Examples: The code: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) becomes: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) The code: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) becomes: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) The code: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") becomes: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") * If arguments must wrap, treat them all equally Replaced 510 occurances of lines ending in things like ...(foo, or ...(bar(1,3), with \1 \2 3 Examples: The code: midscope.to_hash(false), becomes: assert_equal( The code: botscope.to_hash(true), becomes: # bottomscope, then checking that we see the right stuff. The code: :path => link, becomes: * Replaced 4516 occurances of ^( *)(.*) with The present code base is supposed to use four-space indentation. In some places we failed to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question. 15 Examples: The code: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc becomes: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc The code: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( becomes: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( The code: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } becomes: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } The code: #passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } becomes: # passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } The code: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") becomes: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") The code: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", becomes: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", The code: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do becomes: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do The code: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') becomes: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') The code: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) becomes: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) The code: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") becomes: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") The code: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } becomes: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } The code: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid becomes: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid The code: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' becomes: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' The code: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs becomes: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs The code: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element| becomes: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element|
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/casestatement_spec.rb8
-rwxr-xr-xspec/unit/parser/ast/comparison_operator_spec.rb18
-rwxr-xr-xspec/unit/parser/ast/vardef_spec.rb6
-rw-r--r--spec/unit/parser/ast_spec.rb6
-rwxr-xr-xspec/unit/parser/functions/defined_spec.rb2
-rwxr-xr-xspec/unit/parser/functions/regsubst_spec.rb134
-rwxr-xr-xspec/unit/parser/functions/shellquote_spec.rb51
-rwxr-xr-xspec/unit/parser/functions/split_spec.rb24
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb5
-rwxr-xr-xspec/unit/parser/lexer_spec.rb8
-rwxr-xr-xspec/unit/parser/parser_spec.rb48
-rwxr-xr-xspec/unit/parser/resource_spec.rb2
-rwxr-xr-xspec/unit/parser/scope_spec.rb15
-rwxr-xr-xspec/unit/parser/templatewrapper_spec.rb14
14 files changed, 179 insertions, 162 deletions
diff --git a/spec/unit/parser/ast/casestatement_spec.rb b/spec/unit/parser/ast/casestatement_spec.rb
index 240d3bfea..187dd5822 100755
--- a/spec/unit/parser/ast/casestatement_spec.rb
+++ b/spec/unit/parser/ast/casestatement_spec.rb
@@ -136,11 +136,13 @@ describe Puppet::Parser::AST::CaseStatement do
}
options = tests.collect do |result, values|
values = values.collect { |v| AST::Leaf.new :value => v }
- AST::CaseOpt.new(:value => AST::ASTArray.new(:children => values),
+
+ AST::CaseOpt.new(
+ :value => AST::ASTArray.new(:children => values),
+
:statements => AST::Leaf.new(:value => result))
end
- options << AST::CaseOpt.new(:value => AST::Default.new(:value => "default"),
- :statements => AST::Leaf.new(:value => "default"))
+ options << AST::CaseOpt.new(:value => AST::Default.new(:value => "default"), :statements => AST::Leaf.new(:value => "default"))
ast = nil
param = AST::Variable.new(:value => "testparam")
diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb
index 97402433f..51f4cc516 100755
--- a/spec/unit/parser/ast/comparison_operator_spec.rb
+++ b/spec/unit/parser/ast/comparison_operator_spec.rb
@@ -54,11 +54,11 @@ describe Puppet::Parser::AST::ComparisonOperator do
end
%w{< > <= >= ==}.each do |oper|
- it "should return the result of using '#{oper}' to compare the left and right sides" do
- operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @one, :operator => oper, :rval => @two
+ it "should return the result of using '#{oper}' to compare the left and right sides" do
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @one, :operator => oper, :rval => @two
- operator.evaluate(@scope).should == 1.send(oper,2)
- end
+ operator.evaluate(@scope).should == 1.send(oper,2)
+ end
end
it "should return the result of using '!=' to compare the left and right sides" do
@@ -81,12 +81,12 @@ describe Puppet::Parser::AST::ComparisonOperator do
# see ticket #1759
%w{< > <= >=}.each do |oper|
it "should return the correct result of using '#{oper}' to compare 10 and 9" do
- ten = stub 'one', :safeevaluate => "10"
- nine = stub 'two', :safeevaluate => "9"
- operator = Puppet::Parser::AST::ComparisonOperator.new :lval => ten, :operator => oper, :rval => nine
+ ten = stub 'one', :safeevaluate => "10"
+ nine = stub 'two', :safeevaluate => "9"
+ operator = Puppet::Parser::AST::ComparisonOperator.new :lval => ten, :operator => oper, :rval => nine
- operator.evaluate(@scope).should == 10.send(oper,9)
- end
+ operator.evaluate(@scope).should == 10.send(oper,9)
+ end
end
end
diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb
index a6863e75f..369a9f847 100755
--- a/spec/unit/parser/ast/vardef_spec.rb
+++ b/spec/unit/parser/ast/vardef_spec.rb
@@ -17,7 +17,7 @@ describe Puppet::Parser::AST::VarDef do
value.expects(:safeevaluate).with(@scope)
vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil
+ :line => nil
vardef.evaluate(@scope)
end
@@ -28,7 +28,7 @@ describe Puppet::Parser::AST::VarDef do
@scope.expects(:setvar).with { |name,value,options| options[:append] == nil }
vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil
+ :line => nil
vardef.evaluate(@scope)
end
@@ -39,7 +39,7 @@ describe Puppet::Parser::AST::VarDef do
@scope.expects(:setvar).with { |name,value,options| options[:append] == true }
vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil, :append => true
+ :line => nil, :append => true
vardef.evaluate(@scope)
end
diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb
index ca6f8080a..cd271af98 100644
--- a/spec/unit/parser/ast_spec.rb
+++ b/spec/unit/parser/ast_spec.rb
@@ -21,9 +21,9 @@ describe Puppet::Parser::AST do
end
[ Puppet::Parser::AST::Collection, Puppet::Parser::AST::Else,
- Puppet::Parser::AST::Function, Puppet::Parser::AST::IfStatement,
- Puppet::Parser::AST::Resource, Puppet::Parser::AST::ResourceDefaults,
- Puppet::Parser::AST::ResourceOverride, Puppet::Parser::AST::VarDef
+ Puppet::Parser::AST::Function, Puppet::Parser::AST::IfStatement,
+ Puppet::Parser::AST::Resource, Puppet::Parser::AST::ResourceDefaults,
+ Puppet::Parser::AST::ResourceOverride, Puppet::Parser::AST::VarDef
].each do |k|
it "#{k}.use_docs should return true" do
ast = k.new({})
diff --git a/spec/unit/parser/functions/defined_spec.rb b/spec/unit/parser/functions/defined_spec.rb
index 03b0ef9dd..90f2f5239 100755
--- a/spec/unit/parser/functions/defined_spec.rb
+++ b/spec/unit/parser/functions/defined_spec.rb
@@ -18,7 +18,7 @@ describe "the 'defined' function" do
@scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness")
@scope.function_defined("yayness").should be_true
end
-
+
it "should be true when the name is defined as a definition" do
@scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
@scope.function_defined("yayness").should be_true
diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb
index 5a533efb1..6ff619f8d 100755
--- a/spec/unit/parser/functions/regsubst_spec.rb
+++ b/spec/unit/parser/functions/regsubst_spec.rb
@@ -13,29 +13,24 @@ describe "the regsubst function" do
end
it "should raise a ParseError if there is less than 3 arguments" do
- lambda { @scope.function_regsubst(["foo", "bar"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst(["foo", "bar"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there is more than 5 arguments" do
- lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError when given a bad flag" do
- lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "X"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "X"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError for non-string and non-array target" do
- lambda { @scope.function_regsubst([4711, "bar", "gazonk"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst([4711, "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError for array target with non-string element" do
- lambda { @scope.function_regsubst([["x", ["y"], "z"], "bar", "gazonk"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst([["x", ["y"], "z"], "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError for a bad regular expression" do
@@ -44,63 +39,80 @@ describe "the regsubst function" do
end
it "should raise a ParseError for a non-string regular expression" do
- lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.should( raise_error(Puppet::ParseError))
end
it "should handle groups" do
+
result = @scope.function_regsubst(
+
[ '130.236.254.10',
- '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
- '\4-\3-\2-\1'
+
+ '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
+ '\4-\3-\2-\1'
])
result.should(eql("10-254-236-130"))
end
it "should handle simple regexps" do
+
result = @scope.function_regsubst(
+
[ "the monkey breaks banana trees",
- "b[an]*a",
- "coconut"
+ "b[an]*a",
+
+ "coconut"
])
result.should(eql("the monkey breaks coconut trees"))
end
it "should handle case-sensitive regexps" do
+
result = @scope.function_regsubst(
+
[ "the monkey breaks baNAna trees",
- "b[an]+a",
- "coconut"
+ "b[an]+a",
+
+ "coconut"
])
result.should(eql("the monkey breaks baNAna trees"))
end
it "should handle case-insensitive regexps" do
+
result = @scope.function_regsubst(
+
[ "the monkey breaks baNAna trees",
- "b[an]+a",
- "coconut",
- "I"
+ "b[an]+a",
+ "coconut",
+
+ "I"
])
result.should(eql("the monkey breaks coconut trees"))
end
it "should handle global substitutions" do
+
result = @scope.function_regsubst(
+
[ "the monkey breaks\tbanana trees",
- "[ \t]",
- "--",
- "G"
+ "[ \t]",
+ "--",
+
+ "G"
])
result.should(eql("the--monkey--breaks--banana--trees"))
end
it "should handle global substitutions with groups" do
+
result = @scope.function_regsubst(
+
[ '130.236.254.10',
- '([0-9]+)',
- '<\1>',
- 'G'
+
+ '([0-9]+)',
+ '<\1>',
+ 'G'
])
result.should(eql('<130>.<236>.<254>.<10>'))
end
@@ -108,59 +120,71 @@ describe "the regsubst function" do
it "should apply on all elements of an array" do
data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
result = @scope.function_regsubst([ data, '[.]', '-'])
- result.should(eql(
- ['130-236.254.10', 'foo-example.com', 'coconut', '10-20.30.40']))
+ result.should(eql( ['130-236.254.10', 'foo-example.com', 'coconut', '10-20.30.40']))
end
it "should apply global substitutions on all elements of an array" do
data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
result = @scope.function_regsubst([ data, '[.]', '-', 'G'])
- result.should(eql(
- ['130-236-254-10', 'foo-example-com', 'coconut', '10-20-30-40']))
+ result.should(eql( ['130-236-254-10', 'foo-example-com', 'coconut', '10-20-30-40']))
end
it "should handle groups on all elements of an array" do
data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst(
- [ data,
- '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
- '\4-\3-\2-\1'
+
+ result = @scope.function_regsubst(
+
+ [ data,
+
+ '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
+ '\4-\3-\2-\1'
])
- result.should(eql(
- ['10-254-236-130', 'foo.example.com', 'coconut', '40-30-20-10']))
+ result.should(eql( ['10-254-236-130', 'foo.example.com', 'coconut', '40-30-20-10']))
end
it "should handle global substitutions with groups on all elements of an array" do
data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst(
- [ data,
- '([^.]+)',
- '<\1>',
- 'G'
+
+ result = @scope.function_regsubst(
+
+ [ data,
+
+ '([^.]+)',
+ '<\1>',
+ 'G'
])
- result.should(eql(
- ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>',
- '<coconut>', '<10>.<20>.<30>.<40>']))
+
+ result.should(eql(
+
+ ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>',
+
+ '<coconut>', '<10>.<20>.<30>.<40>']))
end
it "should return an array (not a string) for a single element array parameter" do
data = ['130.236.254.10']
- result = @scope.function_regsubst(
- [ data,
- '([^.]+)',
- '<\1>',
- 'G'
+
+ result = @scope.function_regsubst(
+
+ [ data,
+
+ '([^.]+)',
+ '<\1>',
+ 'G'
])
result.should(eql(['<130>.<236>.<254>.<10>']))
end
it "should return a string (not a one element array) for a simple string parameter" do
data = '130.236.254.10'
- result = @scope.function_regsubst(
- [ data,
- '([^.]+)',
- '<\1>',
- 'G'
+
+ result = @scope.function_regsubst(
+
+ [ data,
+
+ '([^.]+)',
+ '<\1>',
+ 'G'
])
result.should(eql('<130>.<236>.<254>.<10>'))
end
diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb
index 283a4de1e..8286be32e 100755
--- a/spec/unit/parser/functions/shellquote_spec.rb
+++ b/spec/unit/parser/functions/shellquote_spec.rb
@@ -19,74 +19,63 @@ describe "the shellquote function" do
end
it "should handle several simple arguments" do
- result = @scope.function_shellquote(
- ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
- result.should(eql(
- 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
+ result = @scope.function_shellquote( ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
+ result.should(eql( 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
end
it "should handle array arguments" do
+
result = @scope.function_shellquote(
+
['foo', ['bar@example.com', 'localhost:/dev/null'],
- 'xyzzy+-4711,23'])
+
+ 'xyzzy+-4711,23'])
result.should(eql(
'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
end
it "should quote unsafe characters" do
- result = @scope.function_shellquote(
- ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
- result.should(eql(
- '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
+ result = @scope.function_shellquote( ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
+ result.should(eql( '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
end
it "should deal with double quotes" do
result = @scope.function_shellquote(
- ['"foo"bar"'])
+ ['"foo"bar"'])
result.should(eql(
'\'"foo"bar"\''))
end
it "should cope with dollar signs" do
- result = @scope.function_shellquote(
- ['$PATH', 'foo$bar', '"x$"'])
- result.should(eql(
- "'$PATH' 'foo$bar' '\"x$\"'"))
+ result = @scope.function_shellquote( ['$PATH', 'foo$bar', '"x$"'])
+ result.should(eql( "'$PATH' 'foo$bar' '\"x$\"'"))
end
it "should deal with apostrophes (single quotes)" do
result = @scope.function_shellquote(
- ["'foo'bar'", "`$'EDITOR'`"])
+ ["'foo'bar'", "`$'EDITOR'`"])
result.should(eql(
'"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"'))
end
it "should cope with grave accents (backquotes)" do
- result = @scope.function_shellquote(
- ['`echo *`', '`ls "$MAILPATH"`'])
- result.should(eql(
- "'`echo *`' '`ls \"$MAILPATH\"`'"))
+ result = @scope.function_shellquote( ['`echo *`', '`ls "$MAILPATH"`'])
+ result.should(eql( "'`echo *`' '`ls \"$MAILPATH\"`'"))
end
it "should deal with both single and double quotes" do
- result = @scope.function_shellquote(
- ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
- result.should(eql(
- '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
+ result = @scope.function_shellquote( ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
+ result.should(eql( '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
end
it "should handle multiple quotes *and* dollars and backquotes" do
- result = @scope.function_shellquote(
- ['\'foo"$x`bar`"xyzzy\''])
- result.should(eql(
- '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
+ result = @scope.function_shellquote( ['\'foo"$x`bar`"xyzzy\''])
+ result.should(eql( '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
end
it "should handle linefeeds" do
- result = @scope.function_shellquote(
- ["foo \n bar"])
- result.should(eql(
- "\"foo \n bar\""))
+ result = @scope.function_shellquote( ["foo \n bar"])
+ result.should(eql( "\"foo \n bar\""))
end
end
diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb
index 8aa031d19..3d0240af4 100755
--- a/spec/unit/parser/functions/split_spec.rb
+++ b/spec/unit/parser/functions/split_spec.rb
@@ -13,39 +13,37 @@ describe "the split function" do
end
it "should raise a ParseError if there is less than 2 arguments" do
- lambda { @scope.function_split(["foo"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_split(["foo"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a ParseError if there is more than 2 arguments" do
- lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
end
it "should raise a RegexpError if the regexp is malformed" do
lambda { @scope.function_split(["foo", "("]) }.should(
- raise_error(RegexpError))
+ raise_error(RegexpError))
end
it "should handle simple string without metacharacters" do
- result = @scope.function_split([ "130;236;254;10", ";"])
- result.should(eql(["130", "236", "254", "10"]))
+ result = @scope.function_split([ "130;236;254;10", ";"])
+ result.should(eql(["130", "236", "254", "10"]))
end
it "should handle simple regexps" do
- result = @scope.function_split([ "130.236;254.;10", "[.;]+"])
- result.should(eql(["130", "236", "254", "10"]))
+ result = @scope.function_split([ "130.236;254.;10", "[.;]+"])
+ result.should(eql(["130", "236", "254", "10"]))
end
it "should handle groups" do
- result = @scope.function_split([ "130.236;254.;10", "([.;]+)"])
- result.should(eql(["130", ".", "236", ";", "254", ".;", "10"]))
+ result = @scope.function_split([ "130.236;254.;10", "([.;]+)"])
+ result.should(eql(["130", ".", "236", ";", "254", ".;", "10"]))
end
it "should handle simple string without metacharacters" do
- result = @scope.function_split([ "130.236.254.10", ";"])
- result.should(eql(["130.236.254.10"]))
+ result = @scope.function_split([ "130.236.254.10", ";"])
+ result.should(eql(["130.236.254.10"]))
end
end
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index 949dc3fcc..71921e0e0 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -13,8 +13,7 @@ describe "the sprintf function" do
end
it "should raise a ParseError if there is less than 1 argument" do
- lambda { @scope.function_sprintf([]) }.should(
- raise_error(Puppet::ParseError))
+ lambda { @scope.function_sprintf([]) }.should( raise_error(Puppet::ParseError))
end
it "should format integers" do
@@ -35,7 +34,7 @@ describe "the sprintf function" do
it "should perform more complex formatting" do
result = @scope.function_sprintf(
[ "<%.8s:%#5o %#8X (%-8s)>",
- "overlongstring", "23", "48879", "foo" ])
+ "overlongstring", "23", "48879", "foo" ])
result.should(eql("<overlong: 027 0XBEEF (foo )>"))
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index c437034a4..47a768469 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -357,8 +357,8 @@ describe Puppet::Parser::Lexer::TOKENS[:MLCOMMENT] do
it "should match multiple lines enclosed with '/*' and '*/'" do
@token.regex.should =~ """/*
- this is a comment
- */"""
+ this is a comment
+ */"""
end
it "should increase the lexer current line number by the amount of lines spanned by the comment" do
@@ -480,8 +480,8 @@ describe Puppet::Parser::Lexer::TOKENS[:REGEX] do
:CASE,:VARIABLE,:LBRACE,:STRING,:COLON,:LBRACE,:VARIABLE,:EQUALS,:NAME,:DIV,:NAME,:RBRACE,[:REGEX,/regex/],:COLON,:LBRACE,:NAME,:LPAREN,:STRING,:RPAREN,:RBRACE,:RBRACE
)
end
-
- end
+
+ end
it "should return the REGEX token and a Regexp" do
diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb
index 2cbb80f9b..53a16e62a 100755
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@ -32,7 +32,7 @@ describe Puppet::Parser do
parser = Puppet::Parser::Parser.new "development"
parser.known_resource_types.should equal(rtc)
end
-
+
it "should delegate importing to the known resource type loader" do
parser = Puppet::Parser::Parser.new "development"
parser.known_resource_types.loader.expects(:import).with("newfile", "current_file")
@@ -100,32 +100,32 @@ describe Puppet::Parser do
end
it "comparison operation, it should create the correct ast objects" do
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<"
- }
- @parser.parse("if 1 < 2 { $var = 1 }")
+ ast::ComparisonOperator.expects(:new).with {
+ |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<"
+ }
+ @parser.parse("if 1 < 2 { $var = 1 }")
end
end
describe "when parsing if complex expressions" do
- it "should create a correct ast tree" do
- aststub = stub_everything 'ast'
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">"
- }.returns(aststub)
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="=="
- }.returns(aststub)
- ast::BooleanOperator.expects(:new).with {
- |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and"
- }
- @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }")
- end
-
- it "should raise an error on incorrect expression" do
- lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error
+ it "should create a correct ast tree" do
+ aststub = stub_everything 'ast'
+ ast::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">"
+ }.returns(aststub)
+ ast::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="=="
+ }.returns(aststub)
+ ast::BooleanOperator.expects(:new).with {
+ |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and"
+ }
+ @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }")
+ end
+
+ it "should raise an error on incorrect expression" do
+ lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error
end
end
@@ -194,7 +194,7 @@ describe Puppet::Parser do
it "should build a chain of 'ifs' if there's an 'elsif'" do
ast = @parser.parse(<<-PP)
- if true { notice('test') } elsif true {} else { }
+ if true { notice('test') } elsif true {} else { }
PP
end
@@ -398,12 +398,12 @@ describe Puppet::Parser do
@krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil}))
lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error
end
-
+
it "should correctly mark exported resources as exported" do
@parser.parse("@@file { '/file': }")
@krt.hostclass("").code[0].exported.should be_true
end
-
+
it "should correctly mark virtual resources as virtual" do
@parser.parse("@file { '/file': }")
@krt.hostclass("").code[0].virtual.should be_true
diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb
index 9d407c0e7..31bde27dd 100755
--- a/spec/unit/parser/resource_spec.rb
+++ b/spec/unit/parser/resource_spec.rb
@@ -496,7 +496,7 @@ describe Puppet::Parser::Resource do
end
it "should fail if the same param is declared twice" do
- lambda do
+ lambda do
@parser_resource = mkresource :source => @source, :parameters => [
Puppet::Parser::Resource::Param.new(
:name => :foo, :value => "bar", :source => @source
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 29dca38f4..94192a693 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -11,7 +11,7 @@ describe Puppet::Parser::Scope do
@scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
@scope.parent = @topscope
end
-
+
it "should be able to store references to class scopes" do
lambda { @scope.class_set "myname", "myscope" }.should_not raise_error
end
@@ -500,8 +500,7 @@ describe Puppet::Parser::Scope do
assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly")
tests.each do |input, output|
assert_nothing_raised("Failed to scan %s" % input.inspect) do
- assert_equal(output, scope.strinterp(input),
- 'did not parserret %s correctly' % input.inspect)
+ assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect)
end
end
@@ -513,11 +512,17 @@ describe Puppet::Parser::Scope do
%w{d f h l w z}.each do |l|
string = "\\" + l
assert_nothing_raised do
- assert_equal(string, scope.strinterp(string),
+
+ assert_equal(
+ string, scope.strinterp(string),
+
'did not parserret %s correctly' % string)
end
- assert(logs.detect { |m| m.message =~ /Unrecognised escape/ },
+
+ assert(
+ logs.detect { |m| m.message =~ /Unrecognised escape/ },
+
"Did not get warning about escape sequence with %s" % string)
logs.clear
end
diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb
index 1b4121643..9a16666fd 100755
--- a/spec/unit/parser/templatewrapper_spec.rb
+++ b/spec/unit/parser/templatewrapper_spec.rb
@@ -120,18 +120,18 @@ describe Puppet::Parser::TemplateWrapper do
@tw.result("template contents")
@tw.instance_variable_get("@one").should == "foo"
- end
+ end
- it "should not error out if one of the variables is a symbol" do
+ it "should not error out if one of the variables is a symbol" do
template_mock = mock("template", :result => "woot!")
ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
@scope.expects(:to_hash).returns(:_timestamp => "1234")
@tw.result("template contents")
- end
+ end
- %w{! . ; :}.each do |badchar|
- it "should translate #{badchar} to _ when setting the instance variables" do
+ %w{! . ; :}.each do |badchar|
+ it "should translate #{badchar} to _ when setting the instance variables" do
template_mock = mock("template", :result => "woot!")
ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
@@ -139,6 +139,6 @@ describe Puppet::Parser::TemplateWrapper do
@tw.result("template contents")
@tw.instance_variable_get("@one_").should == "foo"
- end
- end
+ end
+ end
end