summaryrefslogtreecommitdiffstats
path: root/test/language
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /test/language
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'test/language')
-rwxr-xr-xtest/language/ast.rb134
-rwxr-xr-xtest/language/ast/variable.rb28
-rwxr-xr-xtest/language/functions.rb788
-rwxr-xr-xtest/language/parser.rb1344
-rwxr-xr-xtest/language/scope.rb384
-rwxr-xr-xtest/language/snippets.rb868
-rwxr-xr-xtest/language/transportable.rb134
7 files changed, 1840 insertions, 1840 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb
index d11c87f6d..10b9fa361 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -8,83 +8,83 @@ require 'puppettest/resourcetesting'
require 'puppettest/parsertesting'
class TestAST < Test::Unit::TestCase
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
-
- def test_if
- scope = mkscope
- astif = nil
- astelse = nil
- fakeelse = FakeAST.new(:else)
- faketest = FakeAST.new(true)
- fakeif = FakeAST.new(:if)
-
- assert_nothing_raised {
- astelse = AST::Else.new(:statements => fakeelse)
- }
- assert_nothing_raised {
-
- astif = AST::IfStatement.new(
+ include PuppetTest::ParserTesting
+ include PuppetTest::ResourceTesting
+
+ def test_if
+ scope = mkscope
+ astif = nil
+ astelse = nil
+ fakeelse = FakeAST.new(:else)
+ faketest = FakeAST.new(true)
+ fakeif = FakeAST.new(:if)
+
+ assert_nothing_raised {
+ astelse = AST::Else.new(:statements => fakeelse)
+ }
+ assert_nothing_raised {
+
+ astif = AST::IfStatement.new(
- :test => faketest,
- :statements => fakeif,
+ :test => faketest,
+ :statements => fakeif,
- :else => astelse
- )
- }
-
- # We initialized it to true, so we should get that first
- ret = nil
- assert_nothing_raised {
- ret = astif.evaluate(scope)
- }
- assert_equal(:if, ret)
-
- # Now set it to false and check that
- faketest.evaluate = false
- assert_nothing_raised {
- ret = astif.evaluate(scope)
- }
- assert_equal(:else, ret)
+ :else => astelse
+ )
+ }
+
+ # We initialized it to true, so we should get that first
+ ret = nil
+ assert_nothing_raised {
+ ret = astif.evaluate(scope)
+ }
+ assert_equal(:if, ret)
+
+ # Now set it to false and check that
+ faketest.evaluate = false
+ assert_nothing_raised {
+ ret = astif.evaluate(scope)
+ }
+ assert_equal(:else, ret)
+ end
+
+ # Make sure our override object behaves "correctly"
+ def test_override
+ scope = mkscope
+
+ ref = nil
+ assert_nothing_raised do
+ ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo")
end
- # Make sure our override object behaves "correctly"
- def test_override
- scope = mkscope
+ scope.compiler.expects(:add_override).with { |res| res.is_a?(Puppet::Parser::Resource) }
+ ret = nil
+ assert_nothing_raised do
+ ret = ref.evaluate scope
+ end
- ref = nil
- assert_nothing_raised do
- ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo")
- end
+ assert_instance_of(Puppet::Parser::Resource, ret, "Did not return override")
+ end
- scope.compiler.expects(:add_override).with { |res| res.is_a?(Puppet::Parser::Resource) }
- ret = nil
- assert_nothing_raised do
- ret = ref.evaluate scope
- end
+ def test_collection
+ scope = mkscope
- assert_instance_of(Puppet::Parser::Resource, ret, "Did not return override")
+ coll = nil
+ assert_nothing_raised do
+ coll = AST::Collection.new(:type => "file", :form => :virtual)
end
- def test_collection
- scope = mkscope
-
- coll = nil
- assert_nothing_raised do
- coll = AST::Collection.new(:type => "file", :form => :virtual)
- end
-
- assert_instance_of(AST::Collection, coll)
+ assert_instance_of(AST::Collection, coll)
- ret = nil
- assert_nothing_raised do
- ret = coll.evaluate scope
- end
+ ret = nil
+ assert_nothing_raised do
+ ret = coll.evaluate scope
+ end
- assert_instance_of(Puppet::Parser::Collector, ret)
+ assert_instance_of(Puppet::Parser::Collector, ret)
- # Now make sure we get it back from the scope
- colls = scope.compiler.instance_variable_get("@collections")
- assert_equal([ret], colls, "Did not store collector in config's collection list")
- end
+ # Now make sure we get it back from the scope
+ colls = scope.compiler.instance_variable_get("@collections")
+ assert_equal([ret], colls, "Did not store collector in config's collection list")
+ end
end
diff --git a/test/language/ast/variable.rb b/test/language/ast/variable.rb
index 6a8b028bd..8a7738b23 100755
--- a/test/language/ast/variable.rb
+++ b/test/language/ast/variable.rb
@@ -9,21 +9,21 @@ require 'puppettest'
require 'puppettest/parsertesting'
class TestVariable < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- AST = Puppet::Parser::AST
+ include PuppetTest
+ include PuppetTest::ParserTesting
+ AST = Puppet::Parser::AST
- def setup
- super
- @scope = mkscope
- @name = "myvar"
- @var = AST::Variable.new(:value => @name)
- end
+ def setup
+ super
+ @scope = mkscope
+ @name = "myvar"
+ @var = AST::Variable.new(:value => @name)
+ end
- def test_evaluate
- assert_equal(:undef, @var.evaluate(@scope), "did not return :undef on unset var")
- @scope.setvar(@name, "something")
- assert_equal("something", @var.evaluate(@scope), "incorrect variable value")
- end
+ def test_evaluate
+ assert_equal(:undef, @var.evaluate(@scope), "did not return :undef on unset var")
+ @scope.setvar(@name, "something")
+ assert_equal("something", @var.evaluate(@scope), "incorrect variable value")
+ end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index eedcd35b0..1d4ed8241 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -9,535 +9,535 @@ require 'puppettest'
require 'puppettest/resourcetesting'
class TestLangFunctions < Test::Unit::TestCase
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
- def test_functions
- Puppet::Node::Environment.stubs(:current).returns nil
- assert_nothing_raised do
+ include PuppetTest::ParserTesting
+ include PuppetTest::ResourceTesting
+ def test_functions
+ Puppet::Node::Environment.stubs(:current).returns nil
+ assert_nothing_raised do
- Puppet::Parser::AST::Function.new(
+ Puppet::Parser::AST::Function.new(
- :name => "fakefunction",
+ :name => "fakefunction",
- :arguments => AST::ASTArray.new(
- :children => [nameobj("avalue")]
- )
- )
- end
-
- assert_raise(Puppet::ParseError) do
-
- func = Puppet::Parser::AST::Function.new(
-
- :name => "fakefunction",
-
- :arguments => AST::ASTArray.new(
- :children => [nameobj("avalue")]
- )
- )
- func.evaluate(mkscope)
- end
-
- assert_nothing_raised do
- Puppet::Parser::Functions.newfunction(:fakefunction, :type => :rvalue) do |input|
- return "output #{input[0]}"
- end
- end
-
- func = nil
- assert_nothing_raised do
+ :arguments => AST::ASTArray.new(
+ :children => [nameobj("avalue")]
+ )
+ )
+ end
- func = Puppet::Parser::AST::Function.new(
+ assert_raise(Puppet::ParseError) do
- :name => "fakefunction",
- :ftype => :rvalue,
+ func = Puppet::Parser::AST::Function.new(
- :arguments => AST::ASTArray.new(
- :children => [nameobj("avalue")]
- )
- )
- end
+ :name => "fakefunction",
- scope = mkscope
- val = nil
- assert_nothing_raised do
- val = func.evaluate(scope)
- end
+ :arguments => AST::ASTArray.new(
+ :children => [nameobj("avalue")]
+ )
+ )
+ func.evaluate(mkscope)
+ end
- assert_equal("output avalue", val)
+ assert_nothing_raised do
+ Puppet::Parser::Functions.newfunction(:fakefunction, :type => :rvalue) do |input|
+ return "output #{input[0]}"
+ end
end
- def test_taggedfunction
- scope = mkscope
- scope.resource.tag("yayness")
+ func = nil
+ assert_nothing_raised do
- # Make sure the ast stuff does what it's supposed to
- {"yayness" => true, "booness" => false}.each do |tag, retval|
- func = taggedobj(tag, :rvalue)
+ func = Puppet::Parser::AST::Function.new(
- val = nil
- assert_nothing_raised do
- val = func.evaluate(scope)
- end
+ :name => "fakefunction",
+ :ftype => :rvalue,
- assert_equal(retval, val, "'tagged' returned #{val} for #{tag}")
- end
+ :arguments => AST::ASTArray.new(
+ :children => [nameobj("avalue")]
+ )
+ )
+ end
- # Now make sure we correctly get tags.
- scope.resource.tag("resourcetag")
- assert(scope.function_tagged("resourcetag"), "tagged function did not catch resource tags")
- scope.compiler.catalog.tag("configtag")
- assert(scope.function_tagged("configtag"), "tagged function did not catch catalog tags")
+ scope = mkscope
+ val = nil
+ assert_nothing_raised do
+ val = func.evaluate(scope)
end
- def test_failfunction
- func = nil
- assert_nothing_raised do
+ assert_equal("output avalue", val)
+ end
- func = Puppet::Parser::AST::Function.new(
+ def test_taggedfunction
+ scope = mkscope
+ scope.resource.tag("yayness")
- :name => "fail",
- :ftype => :statement,
+ # Make sure the ast stuff does what it's supposed to
+ {"yayness" => true, "booness" => false}.each do |tag, retval|
+ func = taggedobj(tag, :rvalue)
- :arguments => AST::ASTArray.new(
- :children => [stringobj("this is a failure"), stringobj("and another")]
- )
- )
- end
+ val = nil
+ assert_nothing_raised do
+ val = func.evaluate(scope)
+ end
- scope = mkscope
- val = nil
- assert_raise(Puppet::ParseError) do
- val = func.evaluate(scope)
- end
+ assert_equal(retval, val, "'tagged' returned #{val} for #{tag}")
end
- def test_multipletemplates
- Dir.mkdir(Puppet[:templatedir])
- onep = File.join(Puppet[:templatedir], "one")
- twop = File.join(Puppet[:templatedir], "two")
+ # Now make sure we correctly get tags.
+ scope.resource.tag("resourcetag")
+ assert(scope.function_tagged("resourcetag"), "tagged function did not catch resource tags")
+ scope.compiler.catalog.tag("configtag")
+ assert(scope.function_tagged("configtag"), "tagged function did not catch catalog tags")
+ end
- File.open(onep, "w") do |f|
- f.puts "<%- if @one.nil? then raise '@one undefined' end -%>template <%= @one %>"
- end
+ def test_failfunction
+ func = nil
+ assert_nothing_raised do
- File.open(twop, "w") do |f|
- f.puts "template <%= @two %>"
- end
- func = nil
- assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
- func = Puppet::Parser::AST::Function.new(
+ :name => "fail",
+ :ftype => :statement,
- :name => "template",
- :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj("this is a failure"), stringobj("and another")]
+ )
+ )
+ end
- :arguments => AST::ASTArray.new(
- :children => [stringobj("one"), stringobj("two")]
- )
- )
- end
- ast = varobj("output", func)
+ scope = mkscope
+ val = nil
+ assert_raise(Puppet::ParseError) do
+ val = func.evaluate(scope)
+ end
+ end
- scope = mkscope
+ def test_multipletemplates
+ Dir.mkdir(Puppet[:templatedir])
+ onep = File.join(Puppet[:templatedir], "one")
+ twop = File.join(Puppet[:templatedir], "two")
- # Test that our manual exception throw fails the parse
- assert_raise(Puppet::ParseError) do
- ast.evaluate(scope)
- end
+ File.open(onep, "w") do |f|
+ f.puts "<%- if @one.nil? then raise '@one undefined' end -%>template <%= @one %>"
+ end
- # Test that our use of an undefined instance variable does not throw
- # an exception, but only safely continues.
- scope.setvar("one", "One")
- assert_nothing_raised do
- ast.evaluate(scope)
- end
+ File.open(twop, "w") do |f|
+ f.puts "template <%= @two %>"
+ end
+ func = nil
+ assert_nothing_raised do
- # Ensure that we got the output we expected from that evaluation.
- assert_equal("template One\ntemplate \n", scope.lookupvar("output"), "Undefined template variables do not raise exceptions")
+ func = Puppet::Parser::AST::Function.new(
- # Now, fill in the last variable and make sure the whole thing
- # evaluates correctly.
- scope.setvar("two", "Two")
- scope.unsetvar("output")
- assert_nothing_raised do
- ast.evaluate(scope)
- end
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj("one"), stringobj("two")]
+ )
+ )
+ end
+ ast = varobj("output", func)
- assert_equal(
- "template One\ntemplate Two\n", scope.lookupvar("output"),
+ scope = mkscope
- "Templates were not handled correctly")
+ # Test that our manual exception throw fails the parse
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(scope)
end
- # Now make sure we can fully qualify files, and specify just one
- def test_singletemplates
- template = tempfile
-
- File.open(template, "w") do |f|
- f.puts "template <%= @yay.nil?() ? raise('yay undefined') : @yay %>"
- end
+ # Test that our use of an undefined instance variable does not throw
+ # an exception, but only safely continues.
+ scope.setvar("one", "One")
+ assert_nothing_raised do
+ ast.evaluate(scope)
+ end
- func = nil
- assert_nothing_raised do
+ # Ensure that we got the output we expected from that evaluation.
+ assert_equal("template One\ntemplate \n", scope.lookupvar("output"), "Undefined template variables do not raise exceptions")
- func = Puppet::Parser::AST::Function.new(
+ # Now, fill in the last variable and make sure the whole thing
+ # evaluates correctly.
+ scope.setvar("two", "Two")
+ scope.unsetvar("output")
+ assert_nothing_raised do
+ ast.evaluate(scope)
+ end
- :name => "template",
- :ftype => :rvalue,
- :arguments => AST::ASTArray.new(
- :children => [stringobj(template)]
- )
- )
- end
- ast = varobj("output", func)
+ assert_equal(
+ "template One\ntemplate Two\n", scope.lookupvar("output"),
- scope = mkscope
- assert_raise(Puppet::ParseError) do
- ast.evaluate(scope)
- end
+ "Templates were not handled correctly")
+ end
- scope.setvar("yay", "this is yay")
+ # Now make sure we can fully qualify files, and specify just one
+ def test_singletemplates
+ template = tempfile
- assert_nothing_raised do
- ast.evaluate(scope)
- end
+ File.open(template, "w") do |f|
+ f.puts "template <%= @yay.nil?() ? raise('yay undefined') : @yay %>"
+ end
+ func = nil
+ assert_nothing_raised do
- assert_equal(
- "template this is yay\n", scope.lookupvar("output"),
+ func = Puppet::Parser::AST::Function.new(
- "Templates were not handled correctly")
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
end
+ ast = varobj("output", func)
- # Make sure that legacy template variable access works as expected.
- def test_legacyvariables
- template = tempfile
-
- File.open(template, "w") do |f|
- f.puts "template <%= deprecated %>"
- end
-
- func = nil
- assert_nothing_raised do
+ scope = mkscope
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(scope)
+ end
- func = Puppet::Parser::AST::Function.new(
+ scope.setvar("yay", "this is yay")
- :name => "template",
- :ftype => :rvalue,
+ assert_nothing_raised do
+ ast.evaluate(scope)
+ end
- :arguments => AST::ASTArray.new(
- :children => [stringobj(template)]
- )
- )
- end
- ast = varobj("output", func)
- # Verify that we get an exception using old-style accessors.
- scope = mkscope
- assert_raise(Puppet::ParseError) do
- ast.evaluate(scope)
- end
+ assert_equal(
+ "template this is yay\n", scope.lookupvar("output"),
- # Verify that we evaluate and return their value correctly.
- scope.setvar("deprecated", "deprecated value")
- assert_nothing_raised do
- ast.evaluate(scope)
- end
+ "Templates were not handled correctly")
+ end
- assert_equal(
- "template deprecated value\n", scope.lookupvar("output"),
+ # Make sure that legacy template variable access works as expected.
+ def test_legacyvariables
+ template = tempfile
- "Deprecated template variables were not handled correctly")
+ File.open(template, "w") do |f|
+ f.puts "template <%= deprecated %>"
end
- # Make sure that problems with kernel method visibility still exist.
- def test_kernel_module_shadows_deprecated_var_lookup
- template = tempfile
- File.open(template, "w").puts("<%= binding %>")
+ func = nil
+ assert_nothing_raised do
- func = nil
- assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
- func = Puppet::Parser::AST::Function.new(
+ :name => "template",
+ :ftype => :rvalue,
- :name => "template",
- :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
- :arguments => AST::ASTArray.new(
- :children => [stringobj(template)]
- )
- )
- end
- ast = varobj("output", func)
+ # Verify that we get an exception using old-style accessors.
+ scope = mkscope
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(scope)
+ end
- # Verify that Kernel methods still shadow deprecated variable lookups.
- scope = mkscope
- assert_nothing_raised("No exception for Kernel shadowed variable names") do
- ast.evaluate(scope)
- end
+ # Verify that we evaluate and return their value correctly.
+ scope.setvar("deprecated", "deprecated value")
+ assert_nothing_raised do
+ ast.evaluate(scope)
end
- def test_tempatefunction_cannot_see_scopes
- template = tempfile
- File.open(template, "w") do |f|
- f.puts "<%= lookupvar('myvar') %>"
- end
+ assert_equal(
+ "template deprecated value\n", scope.lookupvar("output"),
- func = nil
- assert_nothing_raised do
+ "Deprecated template variables were not handled correctly")
+ end
- func = Puppet::Parser::AST::Function.new(
+ # Make sure that problems with kernel method visibility still exist.
+ def test_kernel_module_shadows_deprecated_var_lookup
+ template = tempfile
+ File.open(template, "w").puts("<%= binding %>")
- :name => "template",
- :ftype => :rvalue,
+ func = nil
+ assert_nothing_raised do
- :arguments => AST::ASTArray.new(
- :children => [stringobj(template)]
- )
- )
- end
- ast = varobj("output", func)
+ func = Puppet::Parser::AST::Function.new(
- scope = mkscope
- scope.setvar("myvar", "this is yayness")
- assert_raise(Puppet::ParseError) do
- ast.evaluate(scope)
- end
- end
+ :name => "template",
+ :ftype => :rvalue,
- def test_template_reparses
- template = tempfile
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
- File.open(template, "w") do |f|
- f.puts "original text"
- end
+ # Verify that Kernel methods still shadow deprecated variable lookups.
+ scope = mkscope
+ assert_nothing_raised("No exception for Kernel shadowed variable names") do
+ ast.evaluate(scope)
+ end
+ end
- file = tempfile
+ def test_tempatefunction_cannot_see_scopes
+ template = tempfile
- Puppet[:code] = %{file { "#{file}": content => template("#{template}") }}
- Puppet[:environment] = "yay"
- node = mknode
- node.stubs(:environment).returns Puppet::Node::Environment.new
+ File.open(template, "w") do |f|
+ f.puts "<%= lookupvar('myvar') %>"
+ end
- Puppet[:environment] = "yay"
+ func = nil
+ assert_nothing_raised do
- catalog = Puppet::Parser::Compiler.new(node).compile
+ func = Puppet::Parser::AST::Function.new(
- version = catalog.version
+ :name => "template",
+ :ftype => :rvalue,
- fileobj = catalog.vertices.find { |r| r.title == file }
- assert(fileobj, "File was not in catalog")
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
+ scope = mkscope
+ scope.setvar("myvar", "this is yayness")
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(scope)
+ end
+ end
- assert_equal(
- "original text\n", fileobj["content"],
+ def test_template_reparses
+ template = tempfile
- "Template did not work")
+ File.open(template, "w") do |f|
+ f.puts "original text"
+ end
- Puppet[:filetimeout] = -5
- # Have to sleep because one second is the fs's time granularity.
- sleep(1)
+ file = tempfile
- # Now modify the template
- File.open(template, "w") do |f|
- f.puts "new text"
- end
+ Puppet[:code] = %{file { "#{file}": content => template("#{template}") }}
+ Puppet[:environment] = "yay"
+ node = mknode
+ node.stubs(:environment).returns Puppet::Node::Environment.new
- newversion = Puppet::Parser::Compiler.new(node).compile.version
+ Puppet[:environment] = "yay"
- assert(version != newversion, "Parse date did not change")
- end
+ catalog = Puppet::Parser::Compiler.new(node).compile
- def test_template_defined_vars
- template = tempfile
+ version = catalog.version
- File.open(template, "w") do |f|
- f.puts "template <%= @yayness %>"
- end
+ fileobj = catalog.vertices.find { |r| r.title == file }
+ assert(fileobj, "File was not in catalog")
- func = nil
- assert_nothing_raised do
- func = Puppet::Parser::AST::Function.new(
+ assert_equal(
+ "original text\n", fileobj["content"],
- :name => "template",
- :ftype => :rvalue,
+ "Template did not work")
- :arguments => AST::ASTArray.new(
- :children => [stringobj(template)]
- )
- )
- end
- ast = varobj("output", func)
+ Puppet[:filetimeout] = -5
+ # Have to sleep because one second is the fs's time granularity.
+ sleep(1)
- {
- "" => "",
- false => "false",
- }.each do |string, value|
- scope = mkscope
- scope.setvar("yayness", string)
- assert_equal(string, scope.lookupvar("yayness", false))
+ # Now modify the template
+ File.open(template, "w") do |f|
+ f.puts "new text"
+ end
- assert_nothing_raised("An empty string was not a valid variable value") do
- ast.evaluate(scope)
- end
+ newversion = Puppet::Parser::Compiler.new(node).compile.version
+ assert(version != newversion, "Parse date did not change")
+ end
- assert_equal(
- "template #{value}\n", scope.lookupvar("output"),
+ def test_template_defined_vars
+ template = tempfile
- "#{string.inspect} did not get evaluated correctly")
- end
+ File.open(template, "w") do |f|
+ f.puts "template <%= @yayness %>"
end
- def test_autoloading_functions
- #assert_equal(false, Puppet::Parser::Functions.function(:autofunc),
- # "Got told autofunc already exists")
+ func = nil
+ assert_nothing_raised do
- dir = tempfile
- $LOAD_PATH << dir
- newpath = File.join(dir, "puppet", "parser", "functions")
- FileUtils.mkdir_p(newpath)
+ func = Puppet::Parser::AST::Function.new(
- File.open(File.join(newpath, "autofunc.rb"), "w") { |f|
- f.puts %{
- Puppet::Parser::Functions.newfunction(:autofunc, :type => :rvalue) do |vals|
- Puppet.wanring vals.inspect
- end
- }
- }
- Puppet::Node::Environment.stubs(:current).returns nil
- obj = nil
- assert_nothing_raised {
- obj = Puppet::Parser::Functions.function(:autofunc)
- }
+ :name => "template",
+ :ftype => :rvalue,
- assert(obj, "Did not autoload function")
- assert(Puppet::Parser::Functions.environment_module.method_defined?(:function_autofunc), "Did not set function correctly")
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
end
+ ast = varobj("output", func)
- def test_search
- scope = mkscope
+ {
+ "" => "",
+ false => "false",
+ }.each do |string, value|
+ scope = mkscope
+ scope.setvar("yayness", string)
+ assert_equal(string, scope.lookupvar("yayness", false))
- fun = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yay::ness")
- foo = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "foo::bar")
+ assert_nothing_raised("An empty string was not a valid variable value") do
+ ast.evaluate(scope)
+ end
- search = Puppet::Parser::Functions.function(:search)
- scope.function_search(["foo", "yay"])
- ffun = ffoo = nil
- assert_nothing_raised("Search path change did not work") do
- ffun = scope.find_definition("ness")
- ffoo = scope.find_definition('bar')
- end
+ assert_equal(
+ "template #{value}\n", scope.lookupvar("output"),
- assert(ffun, "Could not find definition in 'fun' namespace")
- assert(ffoo, "Could not find definition in 'foo' namespace")
+ "#{string.inspect} did not get evaluated correctly")
+ end
+ end
+
+ def test_autoloading_functions
+ #assert_equal(false, Puppet::Parser::Functions.function(:autofunc),
+ # "Got told autofunc already exists")
+
+ dir = tempfile
+ $LOAD_PATH << dir
+ newpath = File.join(dir, "puppet", "parser", "functions")
+ FileUtils.mkdir_p(newpath)
+
+ File.open(File.join(newpath, "autofunc.rb"), "w") { |f|
+ f.puts %{
+ Puppet::Parser::Functions.newfunction(:autofunc, :type => :rvalue) do |vals|
+ Puppet.wanring vals.inspect
+ end
+ }
+ }
+ Puppet::Node::Environment.stubs(:current).returns nil
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet::Parser::Functions.function(:autofunc)
+ }
+
+ assert(obj, "Did not autoload function")
+ assert(Puppet::Parser::Functions.environment_module.method_defined?(:function_autofunc), "Did not set function correctly")
+ end
+
+ def test_search
+ scope = mkscope
+
+ fun = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yay::ness")
+ foo = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "foo::bar")
+
+ search = Puppet::Parser::Functions.function(:search)
+ scope.function_search(["foo", "yay"])
+
+ ffun = ffoo = nil
+ assert_nothing_raised("Search path change did not work") do
+ ffun = scope.find_definition("ness")
+ ffoo = scope.find_definition('bar')
end
- def test_include
- scope = mkscope
- parser = mkparser
+ assert(ffun, "Could not find definition in 'fun' namespace")
+ assert(ffoo, "Could not find definition in 'foo' namespace")
+ end
- include = Puppet::Parser::Functions.function(:include)
+ def test_include
+ scope = mkscope
+ parser = mkparser
- assert_raise(Puppet::ParseError, "did not throw error on missing class") do
- scope.function_include("nosuchclass")
- end
+ include = Puppet::Parser::Functions.function(:include)
+
+ assert_raise(Puppet::ParseError, "did not throw error on missing class") do
+ scope.function_include("nosuchclass")
+ end
- parser.newclass("myclass")
+ parser.newclass("myclass")
- scope.compiler.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass})
+ scope.compiler.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass})
- assert_nothing_raised do
- scope.function_include(["myclass", "otherclass"])
- end
+ assert_nothing_raised do
+ scope.function_include(["myclass", "otherclass"])
end
+ end
- def test_file
- parser = mkparser
- scope = mkscope(:parser => parser)
+ def test_file
+ parser = mkparser
+ scope = mkscope(:parser => parser)
- file = Puppet::Parser::Functions.function(:file)
+ file = Puppet::Parser::Functions.function(:file)
- file1 = tempfile
- file2 = tempfile
- file3 = tempfile
+ file1 = tempfile
+ file2 = tempfile
+ file3 = tempfile
- File.open(file2, "w") { |f| f.puts "yaytest" }
+ File.open(file2, "w") { |f| f.puts "yaytest" }
- val = nil
- assert_nothing_raised("Failed to call file with one arg") do
- val = scope.function_file([file2])
- end
+ val = nil
+ assert_nothing_raised("Failed to call file with one arg") do
+ val = scope.function_file([file2])
+ end
- assert_equal("yaytest\n", val, "file() failed")
+ assert_equal("yaytest\n", val, "file() failed")
- assert_nothing_raised("Failed to call file with two args") do
- val = scope.function_file([file1, file2])
- end
+ assert_nothing_raised("Failed to call file with two args") do
+ val = scope.function_file([file1, file2])
+ end
- assert_equal("yaytest\n", val, "file() failed")
+ assert_equal("yaytest\n", val, "file() failed")
- assert_raise(Puppet::ParseError, "did not fail when files are missing") do
- val = scope.function_file([file1, file3])
- end
+ assert_raise(Puppet::ParseError, "did not fail when files are missing") do
+ val = scope.function_file([file1, file3])
end
+ end
+
+ def test_generate
+ command = tempfile
+ sh = %x{which sh}
+ File.open(command, "w") do |f|
+ f.puts %{#!#{sh}
+ if [ -n "$1" ]; then
+ echo "yay-$1"
+ else
+ echo yay
+ fi
+ }
+ end
+ File.chmod(0755, command)
+ assert_equal("yay\n", %x{#{command}}, "command did not work")
+ assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work")
- def test_generate
- command = tempfile
- sh = %x{which sh}
- File.open(command, "w") do |f|
- f.puts %{#!#{sh}
- if [ -n "$1" ]; then
- echo "yay-$1"
- else
- echo yay
- fi
- }
- end
- File.chmod(0755, command)
- assert_equal("yay\n", %x{#{command}}, "command did not work")
- assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work")
-
- Puppet::Node::Environment.stubs(:current).returns nil
- generate = Puppet::Parser::Functions.function(:generate)
+ Puppet::Node::Environment.stubs(:current).returns nil
+ generate = Puppet::Parser::Functions.function(:generate)
- scope = mkscope
- parser = mkparser
+ scope = mkscope
+ parser = mkparser
- val = nil
- assert_nothing_raised("Could not call generator with no args") do
- val = scope.function_generate([command])
- end
- assert_equal("yay\n", val, "generator returned wrong results")
+ val = nil
+ assert_nothing_raised("Could not call generator with no args") do
+ val = scope.function_generate([command])
+ end
+ assert_equal("yay\n", val, "generator returned wrong results")
- assert_nothing_raised("Could not call generator with args") do
- val = scope.function_generate([command, "foo"])
- end
- assert_equal("yay-foo\n", val, "generator returned wrong results")
+ assert_nothing_raised("Could not call generator with args") do
+ val = scope.function_generate([command, "foo"])
+ end
+ assert_equal("yay-foo\n", val, "generator returned wrong results")
- assert_raise(Puppet::ParseError, "Did not fail with an unqualified path") do
- val = scope.function_generate([File.basename(command), "foo"])
- end
+ assert_raise(Puppet::ParseError, "Did not fail with an unqualified path") do
+ val = scope.function_generate([File.basename(command), "foo"])
+ end
- assert_raise(Puppet::ParseError, "Did not fail when command failed") do
- val = scope.function_generate([%x{which touch}.chomp, "/this/dir/does/not/exist"])
- end
+ assert_raise(Puppet::ParseError, "Did not fail when command failed") do
+ val = scope.function_generate([%x{which touch}.chomp, "/this/dir/does/not/exist"])
+ end
- fake = File.join(File.dirname(command), "..")
- dir = File.dirname(command)
- dirname = File.basename(dir)
- bad = File.join(dir, "..", dirname, File.basename(command))
- assert_raise(Puppet::ParseError, "Did not fail when command failed") do
- val = scope.function_generate([bad])
- end
+ fake = File.join(File.dirname(command), "..")
+ dir = File.dirname(command)
+ dirname = File.basename(dir)
+ bad = File.join(dir, "..", dirname, File.basename(command))
+ assert_raise(Puppet::ParseError, "Did not fail when command failed") do
+ val = scope.function_generate([bad])
end
+ end
end
diff --git a/test/language/parser.rb b/test/language/parser.rb
index 70827634f..5a433c724 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -9,738 +9,738 @@ require 'puppettest'
require 'puppettest/support/utils'
class TestParser < Test::Unit::TestCase
- include PuppetTest
- include PuppetTest::ParserTesting
- include PuppetTest::Support::Utils
- def setup
- super
- Puppet[:parseonly] = true
- #@lexer = Puppet::Parser::Lexer.new
- end
-
- def teardown
- super
- Puppet::Node::Environment.clear
- end
-
- def test_each_file
- textfiles { |file|
- Puppet::Node::Environment.clear
- parser = mkparser
- Puppet.debug("parsing #{file}") if __FILE__ == $0
- assert_nothing_raised {
- parser.file = file
- parser.parse
- }
- }
- end
-
- def test_failers
- failers { |file|
- parser = mkparser
- Puppet.debug("parsing failer #{file}") if __FILE__ == $0
- assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") {
- parser.file = file
- ast = parser.parse
- config = mkcompiler(parser)
- config.compile
- #ast.hostclass("").evaluate config.topscope
- }
- }
- end
-
- def test_arrayrvalues
- parser = mkparser
- ret = nil
- file = tempfile
- assert_nothing_raised {
- parser.string = "file { \"#{file}\": mode => [755, 640] }"
- }
-
- assert_nothing_raised {
- ret = parser.parse
- }
- end
-
- def test_arrayrvalueswithtrailingcomma
- parser = mkparser
- ret = nil
- file = tempfile
- assert_nothing_raised {
- parser.string = "file { \"#{file}\": mode => [755, 640,] }"
- }
-
- assert_nothing_raised {
- ret = parser.parse
- }
- end
-
- def mkmanifest(file)
- name = File.join(tmpdir, "file#{rand(100)}")
- @@tmpfiles << name
-
- File.open(file, "w") { |f|
- f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % name
- }
- end
-
- def test_importglobbing
- basedir = File.join(tmpdir, "importesting")
- @@tmpfiles << basedir
- Dir.mkdir(basedir)
-
- subdir = "subdir"
- Dir.mkdir(File.join(basedir, subdir))
- manifest = File.join(basedir, "manifest")
- File.open(manifest, "w") { |f|
- f.puts "import \"%s/*\"" % subdir
- }
-
- 4.times { |i|
- path = File.join(basedir, subdir, "subfile#{i}")
- mkmanifest(path)
- }
-
- assert_nothing_raised("Could not parse multiple files") {
- parser = mkparser
- parser.file = manifest
- parser.parse
- }
- end
-
- def test_nonexistent_import
- basedir = File.join(tmpdir, "importesting")
- @@tmpfiles << basedir
- Dir.mkdir(basedir)
- manifest = File.join(basedir, "manifest")
- File.open(manifest, "w") do |f|
- f.puts "import \" no such file \""
- end
- assert_raise(Puppet::ParseError) {
- parser = mkparser
- parser.file = manifest
- parser.parse
- }
- end
-
- def test_trailingcomma
- path = tempfile
- str = %{file { "#{path}": ensure => file, }
- }
-
- parser = mkparser
- parser.string = str
-
- assert_nothing_raised("Could not parse trailing comma") {
- parser.parse
- }
- end
-
- def test_importedclasses
- imported = tempfile
- importer = tempfile
-
- made = tempfile
+ include PuppetTest
+ include PuppetTest::ParserTesting
+ include PuppetTest::Support::Utils
+ def setup
+ super
+ Puppet[:parseonly] = true
+ #@lexer = Puppet::Parser::Lexer.new
+ end
+
+ def teardown
+ super
+ Puppet::Node::Environment.clear
+ end
+
+ def test_each_file
+ textfiles { |file|
+ Puppet::Node::Environment.clear
+ parser = mkparser
+ Puppet.debug("parsing #{file}") if __FILE__ == $0
+ assert_nothing_raised {
+ parser.file = file
+ parser.parse
+ }
+ }
+ end
+
+ def test_failers
+ failers { |file|
+ parser = mkparser
+ Puppet.debug("parsing failer #{file}") if __FILE__ == $0
+ assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") {
+ parser.file = file
+ ast = parser.parse
+ config = mkcompiler(parser)
+ config.compile
+ #ast.hostclass("").evaluate config.topscope
+ }
+ }
+ end
+
+ def test_arrayrvalues
+ parser = mkparser
+ ret = nil
+ file = tempfile
+ assert_nothing_raised {
+ parser.string = "file { \"#{file}\": mode => [755, 640] }"
+ }
+
+ assert_nothing_raised {
+ ret = parser.parse
+ }
+ end
+
+ def test_arrayrvalueswithtrailingcomma
+ parser = mkparser
+ ret = nil
+ file = tempfile
+ assert_nothing_raised {
+ parser.string = "file { \"#{file}\": mode => [755, 640,] }"
+ }
+
+ assert_nothing_raised {
+ ret = parser.parse
+ }
+ end
+
+ def mkmanifest(file)
+ name = File.join(tmpdir, "file#{rand(100)}")
+ @@tmpfiles << name
+
+ File.open(file, "w") { |f|
+ f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % name
+ }
+ end
+
+ def test_importglobbing
+ basedir = File.join(tmpdir, "importesting")
+ @@tmpfiles << basedir
+ Dir.mkdir(basedir)
+
+ subdir = "subdir"
+ Dir.mkdir(File.join(basedir, subdir))
+ manifest = File.join(basedir, "manifest")
+ File.open(manifest, "w") { |f|
+ f.puts "import \"%s/*\"" % subdir
+ }
+
+ 4.times { |i|
+ path = File.join(basedir, subdir, "subfile#{i}")
+ mkmanifest(path)
+ }
+
+ assert_nothing_raised("Could not parse multiple files") {
+ parser = mkparser
+ parser.file = manifest
+ parser.parse
+ }
+ end
+
+ def test_nonexistent_import
+ basedir = File.join(tmpdir, "importesting")
+ @@tmpfiles << basedir
+ Dir.mkdir(basedir)
+ manifest = File.join(basedir, "manifest")
+ File.open(manifest, "w") do |f|
+ f.puts "import \" no such file \""
+ end
+ assert_raise(Puppet::ParseError) {
+ parser = mkparser
+ parser.file = manifest
+ parser.parse
+ }
+ end
- File.open(imported, "w") do |f|
- f.puts %{class foo { file { "#{made}": ensure => file }}}
- end
+ def test_trailingcomma
+ path = tempfile
+ str = %{file { "#{path}": ensure => file, }
+ }
- File.open(importer, "w") do |f|
- f.puts %{import "#{imported}"\ninclude foo}
- end
+ parser = mkparser
+ parser.string = str
- parser = mkparser
- parser.file = importer
+ assert_nothing_raised("Could not parse trailing comma") {
+ parser.parse
+ }
+ end
+
+ def test_importedclasses
+ imported = tempfile
+ importer = tempfile
+
+ made = tempfile
+
+ File.open(imported, "w") do |f|
+ f.puts %{class foo { file { "#{made}": ensure => file }}}
+ end
- # Make sure it parses fine
- assert_nothing_raised {
- parser.parse
- }
-
- # Now make sure it actually does the work
- assert_creates(importer, made)
+ File.open(importer, "w") do |f|
+ f.puts %{import "#{imported}"\ninclude foo}
end
- # Make sure fully qualified and unqualified files can be imported
- def test_fqfilesandlocalfiles
- dir = tempfile
- Dir.mkdir(dir)
- importer = File.join(dir, "site.pp")
- fullfile = File.join(dir, "full.pp")
- localfile = File.join(dir, "local.pp")
-
- files = []
-
- File.open(importer, "w") do |f|
- f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local}
- end
-
- fullmaker = tempfile
- files << fullmaker
-
- File.open(fullfile, "w") do |f|
- f.puts %{class full { file { "#{fullmaker}": ensure => file }}}
- end
+ parser = mkparser
+ parser.file = importer
- localmaker = tempfile
- files << localmaker
+ # Make sure it parses fine
+ assert_nothing_raised {
+ parser.parse
+ }
- File.open(localfile, "w") do |f|
- f.puts %{class local { file { "#{localmaker}": ensure => file }}}
- end
+ # Now make sure it actually does the work
+ assert_creates(importer, made)
+ end
- parser = mkparser
- parser.file = importer
+ # Make sure fully qualified and unqualified files can be imported
+ def test_fqfilesandlocalfiles
+ dir = tempfile
+ Dir.mkdir(dir)
+ importer = File.join(dir, "site.pp")
+ fullfile = File.join(dir, "full.pp")
+ localfile = File.join(dir, "local.pp")
- # Make sure it parses
- assert_nothing_raised {
- parser.parse
- }
+ files = []
- # Now make sure it actually does the work
- assert_creates(importer, *files)
+ File.open(importer, "w") do |f|
+ f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local}
end
- # Make sure the parser adds '.pp' when necessary
- def test_addingpp
- dir = tempfile
- Dir.mkdir(dir)
- importer = File.join(dir, "site.pp")
- localfile = File.join(dir, "local.pp")
-
- files = []
-
- File.open(importer, "w") do |f|
- f.puts %{import "local"\ninclude local}
- end
+ fullmaker = tempfile
+ files << fullmaker
- file = tempfile
- files << file
-
- File.open(localfile, "w") do |f|
- f.puts %{class local { file { "#{file}": ensure => file }}}
- end
-
- parser = mkparser
- parser.file = importer
-
- assert_nothing_raised {
- parser.parse
- }
+ File.open(fullfile, "w") do |f|
+ f.puts %{class full { file { "#{fullmaker}": ensure => file }}}
end
- # Make sure that file importing changes file relative names.
- def test_changingrelativenames
- dir = tempfile
- Dir.mkdir(dir)
- Dir.mkdir(File.join(dir, "subdir"))
- top = File.join(dir, "site.pp")
- subone = File.join(dir, "subdir/subone")
- subtwo = File.join(dir, "subdir/subtwo")
-
- files = []
- file = tempfile
- files << file
-
- File.open(subone + ".pp", "w") do |f|
- f.puts %{class one { file { "#{file}": ensure => file }}}
- end
-
- otherfile = tempfile
- files << otherfile
- File.open(subtwo + ".pp", "w") do |f|
- f.puts %{import "subone"\n class two inherits one {
- file { "#{otherfile}": ensure => file }
- }}
- end
-
- File.open(top, "w") do |f|
- f.puts %{import "subdir/subtwo"}
- end
-
- parser = mkparser
- parser.file = top
+ localmaker = tempfile
+ files << localmaker
- assert_nothing_raised {
- parser.parse
- }
+ File.open(localfile, "w") do |f|
+ f.puts %{class local { file { "#{localmaker}": ensure => file }}}
end
- # Defaults are purely syntactical, so it doesn't make sense to be able to
- # collect them.
- def test_uncollectabledefaults
- string = "@Port { protocols => tcp }"
+ parser = mkparser
+ parser.file = importer
- assert_raise(Puppet::ParseError) {
- mkparser.parse(string)
- }
- end
+ # Make sure it parses
+ assert_nothing_raised {
+ parser.parse
+ }
- # Verify that we can parse collections
- def test_collecting
- text = "Port <| |>"
- parser = mkparser
- parser.string = text
+ # Now make sure it actually does the work
+ assert_creates(importer, *files)
+ end
- ret = nil
- assert_nothing_raised {
- ret = parser.parse
- }
+ # Make sure the parser adds '.pp' when necessary
+ def test_addingpp
+ dir = tempfile
+ Dir.mkdir(dir)
+ importer = File.join(dir, "site.pp")
+ localfile = File.join(dir, "local.pp")
- ret.hostclass("").code.each do |obj|
- assert_instance_of(AST::Collection, obj)
- end
- end
+ files = []
- def test_emptyfile
- file = tempfile
- File.open(file, "w") do |f|
- f.puts %{}
- end
- parser = mkparser
- parser.file = file
- assert_nothing_raised {
- parser.parse
- }
+ File.open(importer, "w") do |f|
+ f.puts %{import "local"\ninclude local}
end
- def test_multiple_nodes_named
- file = tempfile
- other = tempfile
-
- File.open(file, "w") do |f|
- f.puts %{
-node nodeA, nodeB {
- file { "#{other}": ensure => file }
-
-}
-}
- end
+ file = tempfile
+ files << file
- parser = mkparser
- parser.file = file
- ast = nil
- assert_nothing_raised {
- ast = parser.parse
- }
+ File.open(localfile, "w") do |f|
+ f.puts %{class local { file { "#{file}": ensure => file }}}
end
- def test_emptyarrays
- str = %{$var = []\n}
+ parser = mkparser
+ parser.file = importer
- parser = mkparser
- parser.string = str
-
- # Make sure it parses fine
- assert_nothing_raised {
- parser.parse
- }
- end
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
- # Make sure function names aren't reserved words.
- def test_functionnamecollision
- str = %{tag yayness
-tag(rahness)
+ # Make sure that file importing changes file relative names.
+ def test_changingrelativenames
+ dir = tempfile
+ Dir.mkdir(dir)
+ Dir.mkdir(File.join(dir, "subdir"))
+ top = File.join(dir, "site.pp")
+ subone = File.join(dir, "subdir/subone")
+ subtwo = File.join(dir, "subdir/subtwo")
-file { "/tmp/yayness":
- tag => "rahness",
- ensure => exists
-}
-}
- parser = mkparser
- parser.string = str
+ files = []
+ file = tempfile
+ files << file
- # Make sure it parses fine
- assert_nothing_raised {
- parser.parse
- }
+ File.open(subone + ".pp", "w") do |f|
+ f.puts %{class one { file { "#{file}": ensure => file }}}
end
- def test_metaparams_in_definition_prototypes
- parser = mkparser
-
-
- assert_raise(Puppet::ParseError) {
- parser.parse %{define mydef($schedule) {}}
- }
-
- assert_nothing_raised {
- parser.parse %{define adef($schedule = false) {}}
- parser.parse %{define mydef($schedule = daily) {}}
- }
+ otherfile = tempfile
+ files << otherfile
+ File.open(subtwo + ".pp", "w") do |f|
+ f.puts %{import "subone"\n class two inherits one {
+ file { "#{otherfile}": ensure => file }
+ }}
end
- def test_parsingif
- parser = mkparser
- exec = proc do |val|
- %{exec { "/bin/echo #{val}": logoutput => true }}
- end
- str1 = %{if true { #{exec.call("true")} }}
- ret = nil
- assert_nothing_raised {
- ret = parser.parse(str1).hostclass("").code[0]
- }
- assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
- parser = mkparser
- str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
- ret = parser.parse(str2).hostclass("").code[0]
- assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
- assert_instance_of(Puppet::Parser::AST::Else, ret.else)
- end
-
- def test_hostclass
- parser = mkparser
-
- assert_nothing_raised {
- parser.parse %{class myclass { class other {} }}
- }
- assert(parser.hostclass("myclass"), "Could not find myclass")
- assert(parser.hostclass("myclass::other"), "Could not find myclass::other")
-
- assert_nothing_raised {
- parser.parse "class base {}
- class container {
- class deep::sub inherits base {}
- }"
- }
- sub = parser.hostclass("container::deep::sub")
- assert(sub, "Could not find sub")
-
- # Now try it with a parent class being a fq class
- assert_nothing_raised {
- parser.parse "class container::one inherits container::deep::sub {}"
- }
- sub = parser.hostclass("container::one")
- assert(sub, "Could not find one")
- assert_equal("container::deep::sub", sub.parent)
-
- # Finally, try including a qualified class
- assert_nothing_raised("Could not include fully qualified class") {
- parser.parse "include container::deep::sub"
- }
- end
-
- def test_topnamespace
- parser = mkparser
-
- # Make sure we put the top-level code into a class called "" in
- # the "" namespace
- assert_nothing_raised do
- out = parser.parse ""
-
- assert_instance_of(Puppet::Resource::TypeCollection, out)
- assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code")
- end
-
- # Now try something a touch more complicated
- parser.initvars
- assert_nothing_raised do
- out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }"
- assert_instance_of(Puppet::Resource::TypeCollection, out)
- assert_equal("", parser.hostclass("").name)
- assert_equal("", parser.hostclass("").namespace)
- end
+ File.open(top, "w") do |f|
+ f.puts %{import "subdir/subtwo"}
end
- # Make sure virtual and exported resources work appropriately.
- def test_virtualresources
- tests = [:virtual]
- if Puppet.features.rails?
- catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
- facts_cache_class = Puppet::Node::Facts.indirection.cache_class
- node_cache_class = Puppet::Node.indirection.cache_class
- Puppet[:storeconfigs] = true
- tests << :exported
- end
-
- tests.each do |form|
- parser = mkparser
-
- if form == :virtual
- at = "@"
- else
- at = "@@"
- end
-
- check = proc do |res, msg|
- if res.is_a?(Puppet::Parser::Resource)
- txt = res.ref
- else
- txt = res.class
- end
- # Real resources get marked virtual when exported
- if form == :virtual or res.is_a?(Puppet::Parser::Resource)
- assert(res.virtual, "#{msg} #{at}#{txt} is not virtual")
- end
- if form == :virtual
- assert(! res.exported, "#{msg} #{at}#{txt} is exported")
- else
- assert(res.exported, "#{msg} #{at}#{txt} is not exported")
- end
- end
-
- ret = nil
- assert_nothing_raised do
- ret = parser.parse("#{at}file { '/tmp/testing': owner => root }")
- end
-
- assert_instance_of(AST::ASTArray, ret.hostclass("").code)
- resdef = ret.hostclass("").code[0]
- assert_instance_of(AST::Resource, resdef)
- assert_equal("/tmp/testing", resdef.title.value)
- # We always get an astarray back, so...
- check.call(resdef, "simple resource")
-
- # Now let's try it with multiple resources in the same spec
- assert_nothing_raised do
- ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }")
- end
-
- ret.hostclass("").code.each do |res|
- assert_instance_of(AST::Resource, res)
- check.call(res, "multiresource")
- end
- end
-
- ensure
- if Puppet.features.rails?
- Puppet[:storeconfigs] = false
- Puppet::Resource::Catalog.cache_class = catalog_cache_class
- Puppet::Node::Facts.cache_class = facts_cache_class
- Puppet::Node.cache_class = node_cache_class
- end
- end
-
- def test_collections
- tests = [:virtual]
- if Puppet.features.rails?
- catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
- facts_cache_class = Puppet::Node::Facts.indirection.cache_class
- node_cache_class = Puppet::Node.indirection.cache_class
- Puppet[:storeconfigs] = true
- tests << :exported
- end
-
- tests.each do |form|
- Puppet::Node::Environment.clear
- parser = mkparser
-
- if form == :virtual
- arrow = "<||>"
- else
- arrow = "<<||>>"
- end
-
- ret = nil
- assert_nothing_raised do
- ret = parser.parse("File #{arrow}")
- end
-
- coll = ret.hostclass("").code[0]
- assert_instance_of(AST::Collection, coll)
- assert_equal(form, coll.form)
- end
-
- ensure
- if Puppet.features.rails?
- Puppet[:storeconfigs] = false
- Puppet::Resource::Catalog.cache_class = catalog_cache_class
- Puppet::Node::Facts.cache_class = facts_cache_class
- Puppet::Node.cache_class = node_cache_class
- end
- end
+ parser = mkparser
+ parser.file = top
- def test_collectionexpressions
- %w{== !=}.each do |oper|
- Puppet::Node::Environment.clear
- str = "File <| title #{oper} '/tmp/testing' |>"
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
- parser = mkparser
+ # Defaults are purely syntactical, so it doesn't make sense to be able to
+ # collect them.
+ def test_uncollectabledefaults
+ string = "@Port { protocols => tcp }"
- res = nil
- assert_nothing_raised do
- res = parser.parse(str).hostclass("").code[0]
- end
+ assert_raise(Puppet::ParseError) {
+ mkparser.parse(string)
+ }
+ end
- assert_instance_of(AST::Collection, res)
+ # Verify that we can parse collections
+ def test_collecting
+ text = "Port <| |>"
+ parser = mkparser
+ parser.string = text
- query = res.query
- assert_instance_of(AST::CollExpr, query)
+ ret = nil
+ assert_nothing_raised {
+ ret = parser.parse
+ }
- assert_equal(:virtual, query.form)
- assert_equal("title", query.test1.value)
- assert_equal("/tmp/testing", query.test2.value)
- assert_equal(oper, query.oper)
- end
+ ret.hostclass("").code.each do |obj|
+ assert_instance_of(AST::Collection, obj)
end
+ end
- def test_collectionstatements
- %w{and or}.each do |joiner|
- str = "File <| title == '/tmp/testing' #{joiner} owner == root |>"
-
- parser = mkparser
-
- res = nil
- assert_nothing_raised do
- res = parser.parse(str).hostclass("").code[0]
- end
-
- assert_instance_of(AST::Collection, res)
-
- query = res.query
- assert_instance_of(AST::CollExpr, query)
-
- assert_equal(joiner, query.oper)
- assert_instance_of(AST::CollExpr, query.test1)
- assert_instance_of(AST::CollExpr, query.test2)
- end
- end
-
- def test_collectionstatements_with_parens
- [
- "(title == '/tmp/testing' and owner == root) or owner == wheel",
- "(title == '/tmp/testing')"
- ].each do |test|
- str = "File <| #{test} |>"
- parser = mkparser
-
- res = nil
- assert_nothing_raised("Could not parse '#{test}'") do
- res = parser.parse(str).hostclass("").code[0]
- end
-
- assert_instance_of(AST::Collection, res)
-
- query = res.query
- assert_instance_of(AST::CollExpr, query)
-
- #assert_equal(joiner, query.oper)
- #assert_instance_of(AST::CollExpr, query.test1)
- #assert_instance_of(AST::CollExpr, query.test2)
- end
+ def test_emptyfile
+ file = tempfile
+ File.open(file, "w") do |f|
+ f.puts %{}
end
+ parser = mkparser
+ parser.file = file
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
- def test_fully_qualified_definitions
- parser = mkparser
+ def test_multiple_nodes_named
+ file = tempfile
+ other = tempfile
- assert_nothing_raised("Could not parse fully-qualified definition") {
- parser.parse %{define one::two { }}
- }
- assert(parser.definition("one::two"), "Could not find one::two with no namespace")
-
- # Now try using the definition
- assert_nothing_raised("Could not parse fully-qualified definition usage") {
- parser.parse %{one::two { yayness: }}
- }
- end
-
- # #524
- def test_functions_with_no_arguments
- parser = mkparser
- assert_nothing_raised("Could not parse statement function with no args") {
- parser.parse %{tag()}
- }
- assert_nothing_raised("Could not parse rvalue function with no args") {
- parser.parse %{$testing = template()}
- }
- end
-
- # #774
- def test_fully_qualified_collection_statement
- parser = mkparser
- assert_nothing_raised("Could not parse fully qualified collection statement") {
- parser.parse %{Foo::Bar <||>}
- }
- end
-
- def test_multiple_imports_on_one_line
- one = tempfile
- two = tempfile
- base = tempfile
- File.open(one, "w") { |f| f.puts "$var = value" }
- File.open(two, "w") { |f| f.puts "$var = value" }
- File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" }
-
- parser = mkparser
- parser.file = base
-
- # Importing is logged at debug time.
- Puppet::Util::Log.level = :debug
- assert_nothing_raised("Parser could not import multiple files at once") do
- parser.parse
- end
-
- [one, two].each do |file|
- assert(@logs.detect { |l| l.message =~ /importing '#{file}'/}, "did not import #{file}")
- end
- end
+ File.open(file, "w") do |f|
+ f.puts %{
+node nodeA, nodeB {
+ file { "#{other}": ensure => file }
- def test_cannot_assign_qualified_variables
- parser = mkparser
- assert_raise(Puppet::ParseError, "successfully assigned a qualified variable") do
- parser.parse("$one::two = yay")
- end
+}
+}
end
- # #629 - undef keyword
- def test_undef
- parser = mkparser
- result = nil
- assert_nothing_raised("Could not parse assignment to undef") {
- result = parser.parse %{$variable = undef}
- }
+ parser = mkparser
+ parser.file = file
+ ast = nil
+ assert_nothing_raised {
+ ast = parser.parse
+ }
+ end
- main = result.hostclass("").code
- children = main.children
- assert_instance_of(AST::VarDef, main.children[0])
- assert_instance_of(AST::Undef, main.children[0].value)
- end
+ def test_emptyarrays
+ str = %{$var = []\n}
- # Prompted by #729 -- parsing should not modify the interpreter.
- def test_parse
- parser = mkparser
+ parser = mkparser
+ parser.string = str
- str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n"
- result = nil
- assert_nothing_raised("Could not parse") do
- result = parser.parse(str)
- end
- assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
+ # Make sure it parses fine
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
- assert_instance_of(Puppet::Resource::Type, result.hostclass("yay"), "Did not create 'yay' class")
- assert_instance_of(Puppet::Resource::Type, result.hostclass(""), "Did not create main class")
- assert_instance_of(Puppet::Resource::Type, result.definition("bar"), "Did not create 'bar' definition")
- assert_instance_of(Puppet::Resource::Type, result.node("foo"), "Did not create 'foo' node")
- end
-
- def test_namesplit
- parser = mkparser
+ # Make sure function names aren't reserved words.
+ def test_functionnamecollision
+ str = %{tag yayness
+tag(rahness)
- assert_nothing_raised do
- {"base::sub" => %w{base sub},
- "main" => ["", "main"],
- "one::two::three::four" => ["one::two::three", "four"],
- }.each do |name, ary|
- result = parser.namesplit(name)
- assert_equal(ary, result, "#{name} split to #{result}")
- end
- end
+file { "/tmp/yayness":
+ tag => "rahness",
+ ensure => exists
+}
+}
+ parser = mkparser
+ parser.string = str
+
+ # Make sure it parses fine
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
+
+ def test_metaparams_in_definition_prototypes
+ parser = mkparser
+
+
+ assert_raise(Puppet::ParseError) {
+ parser.parse %{define mydef($schedule) {}}
+ }
+
+ assert_nothing_raised {
+ parser.parse %{define adef($schedule = false) {}}
+ parser.parse %{define mydef($schedule = daily) {}}
+ }
+ end
+
+ def test_parsingif
+ parser = mkparser
+ exec = proc do |val|
+ %{exec { "/bin/echo #{val}": logoutput => true }}
+ end
+ str1 = %{if true { #{exec.call("true")} }}
+ ret = nil
+ assert_nothing_raised {
+ ret = parser.parse(str1).hostclass("").code[0]
+ }
+ assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
+ parser = mkparser
+ str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
+ ret = parser.parse(str2).hostclass("").code[0]
+ assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
+ assert_instance_of(Puppet::Parser::AST::Else, ret.else)
+ end
+
+ def test_hostclass
+ parser = mkparser
+
+ assert_nothing_raised {
+ parser.parse %{class myclass { class other {} }}
+ }
+ assert(parser.hostclass("myclass"), "Could not find myclass")
+ assert(parser.hostclass("myclass::other"), "Could not find myclass::other")
+
+ assert_nothing_raised {
+ parser.parse "class base {}
+ class container {
+ class deep::sub inherits base {}
+ }"
+ }
+ sub = parser.hostclass("container::deep::sub")
+ assert(sub, "Could not find sub")
+
+ # Now try it with a parent class being a fq class
+ assert_nothing_raised {
+ parser.parse "class container::one inherits container::deep::sub {}"
+ }
+ sub = parser.hostclass("container::one")
+ assert(sub, "Could not find one")
+ assert_equal("container::deep::sub", sub.parent)
+
+ # Finally, try including a qualified class
+ assert_nothing_raised("Could not include fully qualified class") {
+ parser.parse "include container::deep::sub"
+ }
+ end
+
+ def test_topnamespace
+ parser = mkparser
+
+ # Make sure we put the top-level code into a class called "" in
+ # the "" namespace
+ assert_nothing_raised do
+ out = parser.parse ""
+
+ assert_instance_of(Puppet::Resource::TypeCollection, out)
+ assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code")
+ end
+
+ # Now try something a touch more complicated
+ parser.initvars
+ assert_nothing_raised do
+ out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }"
+ assert_instance_of(Puppet::Resource::TypeCollection, out)
+ assert_equal("", parser.hostclass("").name)
+ assert_equal("", parser.hostclass("").namespace)
+ end
+ end
+
+ # Make sure virtual and exported resources work appropriately.
+ def test_virtualresources
+ tests = [:virtual]
+ if Puppet.features.rails?
+ catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
+ facts_cache_class = Puppet::Node::Facts.indirection.cache_class
+ node_cache_class = Puppet::Node.indirection.cache_class
+ Puppet[:storeconfigs] = true
+ tests << :exported
+ end
+
+ tests.each do |form|
+ parser = mkparser
+
+ if form == :virtual
+ at = "@"
+ else
+ at = "@@"
+ end
+
+ check = proc do |res, msg|
+ if res.is_a?(Puppet::Parser::Resource)
+ txt = res.ref
+ else
+ txt = res.class
+ end
+ # Real resources get marked virtual when exported
+ if form == :virtual or res.is_a?(Puppet::Parser::Resource)
+ assert(res.virtual, "#{msg} #{at}#{txt} is not virtual")
+ end
+ if form == :virtual
+ assert(! res.exported, "#{msg} #{at}#{txt} is exported")
+ else
+ assert(res.exported, "#{msg} #{at}#{txt} is not exported")
+ end
+ end
+
+ ret = nil
+ assert_nothing_raised do
+ ret = parser.parse("#{at}file { '/tmp/testing': owner => root }")
+ end
+
+ assert_instance_of(AST::ASTArray, ret.hostclass("").code)
+ resdef = ret.hostclass("").code[0]
+ assert_instance_of(AST::Resource, resdef)
+ assert_equal("/tmp/testing", resdef.title.value)
+ # We always get an astarray back, so...
+ check.call(resdef, "simple resource")
+
+ # Now let's try it with multiple resources in the same spec
+ assert_nothing_raised do
+ ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }")
+ end
+
+ ret.hostclass("").code.each do |res|
+ assert_instance_of(AST::Resource, res)
+ check.call(res, "multiresource")
+ end
+ end
+
+ ensure
+ if Puppet.features.rails?
+ Puppet[:storeconfigs] = false
+ Puppet::Resource::Catalog.cache_class = catalog_cache_class
+ Puppet::Node::Facts.cache_class = facts_cache_class
+ Puppet::Node.cache_class = node_cache_class
+ end
+ end
+
+ def test_collections
+ tests = [:virtual]
+ if Puppet.features.rails?
+ catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
+ facts_cache_class = Puppet::Node::Facts.indirection.cache_class
+ node_cache_class = Puppet::Node.indirection.cache_class
+ Puppet[:storeconfigs] = true
+ tests << :exported
end
- # Make sure class, node, and define methods are case-insensitive
- def test_structure_case_insensitivity
- parser = mkparser
+ tests.each do |form|
+ Puppet::Node::Environment.clear
+ parser = mkparser
- result = nil
- assert_nothing_raised do
- result = parser.newclass "Yayness"
- end
- assert_equal(result, parser.find_hostclass("", "yayNess"))
+ if form == :virtual
+ arrow = "<||>"
+ else
+ arrow = "<<||>>"
+ end
- assert_nothing_raised do
- result = parser.newdefine "FunTest"
- end
- assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched")
- end
+ ret = nil
+ assert_nothing_raised do
+ ret = parser.parse("File #{arrow}")
+ end
+
+ coll = ret.hostclass("").code[0]
+ assert_instance_of(AST::Collection, coll)
+ assert_equal(form, coll.form)
+ end
+
+ ensure
+ if Puppet.features.rails?
+ Puppet[:storeconfigs] = false
+ Puppet::Resource::Catalog.cache_class = catalog_cache_class
+ Puppet::Node::Facts.cache_class = facts_cache_class
+ Puppet::Node.cache_class = node_cache_class
+ end
+ end
+
+ def test_collectionexpressions
+ %w{== !=}.each do |oper|
+ Puppet::Node::Environment.clear
+ str = "File <| title #{oper} '/tmp/testing' |>"
+
+ parser = mkparser
+
+ res = nil
+ assert_nothing_raised do
+ res = parser.parse(str).hostclass("").code[0]
+ end
+
+ assert_instance_of(AST::Collection, res)
+
+ query = res.query
+ assert_instance_of(AST::CollExpr, query)
+
+ assert_equal(:virtual, query.form)
+ assert_equal("title", query.test1.value)
+ assert_equal("/tmp/testing", query.test2.value)
+ assert_equal(oper, query.oper)
+ end
+ end
+
+ def test_collectionstatements
+ %w{and or}.each do |joiner|
+ str = "File <| title == '/tmp/testing' #{joiner} owner == root |>"
+
+ parser = mkparser
+
+ res = nil
+ assert_nothing_raised do
+ res = parser.parse(str).hostclass("").code[0]
+ end
+
+ assert_instance_of(AST::Collection, res)
+
+ query = res.query
+ assert_instance_of(AST::CollExpr, query)
+
+ assert_equal(joiner, query.oper)
+ assert_instance_of(AST::CollExpr, query.test1)
+ assert_instance_of(AST::CollExpr, query.test2)
+ end
+ end
+
+ def test_collectionstatements_with_parens
+ [
+ "(title == '/tmp/testing' and owner == root) or owner == wheel",
+ "(title == '/tmp/testing')"
+ ].each do |test|
+ str = "File <| #{test} |>"
+ parser = mkparser
+
+ res = nil
+ assert_nothing_raised("Could not parse '#{test}'") do
+ res = parser.parse(str).hostclass("").code[0]
+ end
+
+ assert_instance_of(AST::Collection, res)
+
+ query = res.query
+ assert_instance_of(AST::CollExpr, query)
+
+ #assert_equal(joiner, query.oper)
+ #assert_instance_of(AST::CollExpr, query.test1)
+ #assert_instance_of(AST::CollExpr, query.test2)
+ end
+ end
+
+ def test_fully_qualified_definitions
+ parser = mkparser
+
+ assert_nothing_raised("Could not parse fully-qualified definition") {
+ parser.parse %{define one::two { }}
+ }
+ assert(parser.definition("one::two"), "Could not find one::two with no namespace")
+
+ # Now try using the definition
+ assert_nothing_raised("Could not parse fully-qualified definition usage") {
+ parser.parse %{one::two { yayness: }}
+ }
+ end
+
+ # #524
+ def test_functions_with_no_arguments
+ parser = mkparser
+ assert_nothing_raised("Could not parse statement function with no args") {
+ parser.parse %{tag()}
+ }
+ assert_nothing_raised("Could not parse rvalue function with no args") {
+ parser.parse %{$testing = template()}
+ }
+ end
+
+ # #774
+ def test_fully_qualified_collection_statement
+ parser = mkparser
+ assert_nothing_raised("Could not parse fully qualified collection statement") {
+ parser.parse %{Foo::Bar <||>}
+ }
+ end
+
+ def test_multiple_imports_on_one_line
+ one = tempfile
+ two = tempfile
+ base = tempfile
+ File.open(one, "w") { |f| f.puts "$var = value" }
+ File.open(two, "w") { |f| f.puts "$var = value" }
+ File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" }
+
+ parser = mkparser
+ parser.file = base
+
+ # Importing is logged at debug time.
+ Puppet::Util::Log.level = :debug
+ assert_nothing_raised("Parser could not import multiple files at once") do
+ parser.parse
+ end
+
+ [one, two].each do |file|
+ assert(@logs.detect { |l| l.message =~ /importing '#{file}'/}, "did not import #{file}")
+ end
+ end
+
+ def test_cannot_assign_qualified_variables
+ parser = mkparser
+ assert_raise(Puppet::ParseError, "successfully assigned a qualified variable") do
+ parser.parse("$one::two = yay")
+ end
+ end
+
+ # #629 - undef keyword
+ def test_undef
+ parser = mkparser
+ result = nil
+ assert_nothing_raised("Could not parse assignment to undef") {
+ result = parser.parse %{$variable = undef}
+ }
+
+ main = result.hostclass("").code
+ children = main.children
+ assert_instance_of(AST::VarDef, main.children[0])
+ assert_instance_of(AST::Undef, main.children[0].value)
+ end
+
+ # Prompted by #729 -- parsing should not modify the interpreter.
+ def test_parse
+ parser = mkparser
+
+ str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n"
+ result = nil
+ assert_nothing_raised("Could not parse") do
+ result = parser.parse(str)
+ end
+ assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
+
+ assert_instance_of(Puppet::Resource::Type, result.hostclass("yay"), "Did not create 'yay' class")
+ assert_instance_of(Puppet::Resource::Type, result.hostclass(""), "Did not create main class")
+ assert_instance_of(Puppet::Resource::Type, result.definition("bar"), "Did not create 'bar' definition")
+ assert_instance_of(Puppet::Resource::Type, result.node("foo"), "Did not create 'foo' node")
+ end
+
+ def test_namesplit
+ parser = mkparser
+
+ assert_nothing_raised do
+ {"base::sub" => %w{base sub},
+ "main" => ["", "main"],
+ "one::two::three::four" => ["one::two::three", "four"],
+ }.each do |name, ary|
+ result = parser.namesplit(name)
+ assert_equal(ary, result, "#{name} split to #{result}")
+ end
+ end
+ end
+
+ # Make sure class, node, and define methods are case-insensitive
+ def test_structure_case_insensitivity
+ parser = mkparser
+
+ result = nil
+ assert_nothing_raised do
+ result = parser.newclass "Yayness"
+ end
+ assert_equal(result, parser.find_hostclass("", "yayNess"))
+
+ assert_nothing_raised do
+ result = parser.newdefine "FunTest"
+ end
+ assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched")
+ end
end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 0e99aa5ae..cb5558aec 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -17,261 +17,261 @@ require 'puppettest/resourcetesting'
# and test whether we've got things in the right scopes
class TestScope < Test::Unit::TestCase
- include PuppetTest::ParserTesting
- include PuppetTest::ResourceTesting
+ include PuppetTest::ParserTesting
+ include PuppetTest::ResourceTesting
+
+ def setup
+ Puppet::Node::Environment.clear
+ super
+ end
+
+ def to_ary(hash)
+ hash.collect { |key,value|
+ [key,value]
+ }
+ end
+
+ def test_variables
+ config = mkcompiler
+ topscope = config.topscope
+ midscope = config.newscope(topscope)
+ botscope = config.newscope(midscope)
+
+ scopes = {:top => topscope, :mid => midscope, :bot => botscope}
+
+ # Set a variable in the top and make sure all three can get it
+ topscope.setvar("first", "topval")
+ scopes.each do |name, scope|
+ assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}")
+ end
- def setup
- Puppet::Node::Environment.clear
- super
+ # Now set a var in the midscope and make sure the mid and bottom can see it but not the top
+ midscope.setvar("second", "midval")
+ assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope")
+ [:mid, :bot].each do |name|
+ assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}")
end
- def to_ary(hash)
- hash.collect { |key,value|
- [key,value]
- }
+ # And set something in the bottom, and make sure we only find it there.
+ botscope.setvar("third", "botval")
+ [:top, :mid].each do |name|
+ assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope")
end
+ assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope")
- def test_variables
- config = mkcompiler
- topscope = config.topscope
- midscope = config.newscope(topscope)
- botscope = config.newscope(midscope)
- scopes = {:top => topscope, :mid => midscope, :bot => botscope}
+ # Test that the scopes convert to hash structures correctly.
+ # For topscope recursive vs non-recursive should be identical
+ assert_equal(topscope.to_hash(false), topscope.to_hash(true),
+ "Recursive and non-recursive hash is identical for topscope")
- # Set a variable in the top and make sure all three can get it
- topscope.setvar("first", "topval")
- scopes.each do |name, scope|
- assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}")
- end
+ # Check the variable we expect is present.
+ assert_equal({"first" => "topval"}, topscope.to_hash, "topscope returns the expected hash of variables")
- # Now set a var in the midscope and make sure the mid and bottom can see it but not the top
- midscope.setvar("second", "midval")
- assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope")
- [:mid, :bot].each do |name|
- assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}")
- end
+ # Now, check that midscope does the right thing in all cases.
- # And set something in the bottom, and make sure we only find it there.
- botscope.setvar("third", "botval")
- [:top, :mid].each do |name|
- assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope")
- end
- assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope")
+ assert_equal(
+ {"second" => "midval"},
+ midscope.to_hash(false),
+ "midscope non-recursive hash contains only midscope variable")
- # Test that the scopes convert to hash structures correctly.
- # For topscope recursive vs non-recursive should be identical
- assert_equal(topscope.to_hash(false), topscope.to_hash(true),
- "Recursive and non-recursive hash is identical for topscope")
+ assert_equal(
+ {"first" => "topval", "second" => "midval"},
+ midscope.to_hash(true),
- # Check the variable we expect is present.
- assert_equal({"first" => "topval"}, topscope.to_hash, "topscope returns the expected hash of variables")
+ "midscope recursive hash contains topscope variable also")
- # Now, check that midscope does the right thing in all cases.
+ # Finally, check the ability to shadow symbols by adding a shadow to
+ # bottomscope, then checking that we see the right stuff.
+ botscope.setvar("first", "shadowval")
- assert_equal(
- {"second" => "midval"},
- midscope.to_hash(false),
+ assert_equal(
+ {"third" => "botval", "first" => "shadowval"},
+ botscope.to_hash(false),
- "midscope non-recursive hash contains only midscope variable")
+ "botscope has the right non-recursive hash")
- assert_equal(
- {"first" => "topval", "second" => "midval"},
- midscope.to_hash(true),
+ assert_equal(
+ {"third" => "botval", "first" => "shadowval", "second" => "midval"},
+ botscope.to_hash(true),
- "midscope recursive hash contains topscope variable also")
+ "botscope values shadow parent scope values")
+ end
- # Finally, check the ability to shadow symbols by adding a shadow to
- # bottomscope, then checking that we see the right stuff.
- botscope.setvar("first", "shadowval")
+ def test_declarative
+ # set to declarative
+ top = mkscope
+ sub = mkscope(:parent => top)
- assert_equal(
- {"third" => "botval", "first" => "shadowval"},
- botscope.to_hash(false),
+ assert_nothing_raised {
+ top.setvar("test","value")
+ }
+ assert_raise(Puppet::ParseError) {
+ top.setvar("test","other")
+ }
+ assert_nothing_raised {
+ sub.setvar("test","later")
+ }
+ assert_raise(Puppet::ParseError) {
+ top.setvar("test","yeehaw")
+ }
+ end
- "botscope has the right non-recursive hash")
+ def test_parent
+ config = mkcompiler
+ top = config.topscope
- assert_equal(
- {"third" => "botval", "first" => "shadowval", "second" => "midval"},
- botscope.to_hash(true),
+ # Make a subscope
+ sub = config.newscope(top)
- "botscope values shadow parent scope values")
- end
+ assert_equal(top, sub.parent, "Did not find parent scope correctly")
+ assert_equal(top, sub.parent, "Did not find parent scope on second call")
+ end
- def test_declarative
- # set to declarative
- top = mkscope
- sub = mkscope(:parent => top)
-
- assert_nothing_raised {
- top.setvar("test","value")
- }
- assert_raise(Puppet::ParseError) {
- top.setvar("test","other")
- }
- assert_nothing_raised {
- sub.setvar("test","later")
- }
- assert_raise(Puppet::ParseError) {
- top.setvar("test","yeehaw")
- }
- end
+ # Make sure we know what we consider to be truth.
+ def test_truth
- def test_parent
- config = mkcompiler
- top = config.topscope
+ assert_equal(
+ true, Puppet::Parser::Scope.true?("a string"),
- # Make a subscope
- sub = config.newscope(top)
-
- assert_equal(top, sub.parent, "Did not find parent scope correctly")
- assert_equal(top, sub.parent, "Did not find parent scope on second call")
- end
-
- # Make sure we know what we consider to be truth.
- def test_truth
+ "Strings not considered true")
assert_equal(
- true, Puppet::Parser::Scope.true?("a string"),
-
- "Strings not considered true")
+ true, Puppet::Parser::Scope.true?(true),
- assert_equal(
- true, Puppet::Parser::Scope.true?(true),
+ "True considered true")
- "True considered true")
-
- assert_equal(
- false, Puppet::Parser::Scope.true?(""),
+ assert_equal(
+ false, Puppet::Parser::Scope.true?(""),
- "Empty strings considered true")
+ "Empty strings considered true")
- assert_equal(
- false, Puppet::Parser::Scope.true?(false),
+ assert_equal(
+ false, Puppet::Parser::Scope.true?(false),
- "false considered true")
+ "false considered true")
- assert_equal(
- false, Puppet::Parser::Scope.true?(:undef),
+ assert_equal(
+ false, Puppet::Parser::Scope.true?(:undef),
- "undef considered true")
- end
+ "undef considered true")
+ end
- def test_virtual_definitions_do_not_get_evaluated
- parser = mkparser
- config = mkcompiler
+ def test_virtual_definitions_do_not_get_evaluated
+ parser = mkparser
+ config = mkcompiler
- # Create a default source
- parser.newclass("")
- config.topscope.source = parser.known_resource_types.hostclass("")
+ # Create a default source
+ parser.newclass("")
+ config.topscope.source = parser.known_resource_types.hostclass("")
- # And a scope resource
- scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope)
- config.topscope.resource = scope_res
+ # And a scope resource
+ scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope)
+ config.topscope.resource = scope_res
- args = AST::ASTArray.new(
- :children => [nameobj("arg")]
- )
+ args = AST::ASTArray.new(
+ :children => [nameobj("arg")]
+ )
- # Create a top-level define
- parser.newdefine "one", :arguments => [%w{arg}],
- :code => AST::ASTArray.new(
- :children => [
- resourcedef("file", "/tmp", {"owner" => varref("arg")})
- ]
- )
+ # Create a top-level define
+ parser.newdefine "one", :arguments => [%w{arg}],
+ :code => AST::ASTArray.new(
+ :children => [
+ resourcedef("file", "/tmp", {"owner" => varref("arg")})
+ ]
+ )
- # create a resource that calls our third define
- obj = resourcedef("one", "boo", {"arg" => "parentfoo"})
+ # create a resource that calls our third define
+ obj = resourcedef("one", "boo", {"arg" => "parentfoo"})
- # And mark it as virtual
- obj.virtual = true
+ # And mark it as virtual
+ obj.virtual = true
- # And then evaluate it
- obj.evaluate config.topscope
+ # And then evaluate it
+ obj.evaluate config.topscope
- # And run the loop.
- config.send(:evaluate_generators)
+ # And run the loop.
+ config.send(:evaluate_generators)
- %w{File}.each do |type|
- objects = config.resources.find_all { |r| r.type == type and r.virtual }
+ %w{File}.each do |type|
+ objects = config.resources.find_all { |r| r.type == type and r.virtual }
- assert(objects.empty?, "Virtual define got evaluated")
- end
+ assert(objects.empty?, "Virtual define got evaluated")
end
-
- if defined? ::ActiveRecord
- # Verify that we can both store and collect an object in the same
- # run, whether it's in the same scope as a collection or a different
- # scope.
- def test_storeandcollect
- catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
- facts_cache_class = Puppet::Node::Facts.indirection.cache_class
- node_cache_class = Puppet::Node.indirection.cache_class
- Puppet[:storeconfigs] = true
- Puppet::Rails.init
- sleep 1
- children = []
- Puppet[:code] = "
+ end
+
+ if defined? ::ActiveRecord
+ # Verify that we can both store and collect an object in the same
+ # run, whether it's in the same scope as a collection or a different
+ # scope.
+ def test_storeandcollect
+ catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class
+ facts_cache_class = Puppet::Node::Facts.indirection.cache_class
+ node_cache_class = Puppet::Node.indirection.cache_class
+ Puppet[:storeconfigs] = true
+ Puppet::Rails.init
+ sleep 1
+ children = []
+ Puppet[:code] = "
class yay {
- @@host { myhost: ip => \"192.168.0.2\" }
+ @@host { myhost: ip => \"192.168.0.2\" }
}
include yay
@@host { puppet: ip => \"192.168.0.3\" }
Host <<||>>"
- config = nil
- # We run it twice because we want to make sure there's no conflict
- # if we pull it up from the database.
- node = mknode
- node.merge "hostname" => node.name
- 2.times { |i|
- catalog = Puppet::Parser::Compiler.new(node).compile
- assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "puppet"))
- assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "myhost"))
- }
- ensure
- Puppet[:storeconfigs] = false
- Puppet::Resource::Catalog.cache_class = catalog_cache_class
- Puppet::Node::Facts.cache_class = facts_cache_class
- Puppet::Node.cache_class = node_cache_class
- end
- else
- $stderr.puts "No ActiveRecord -- skipping collection tests"
- end
+ config = nil
+ # We run it twice because we want to make sure there's no conflict
+ # if we pull it up from the database.
+ node = mknode
+ node.merge "hostname" => node.name
+ 2.times { |i|
+ catalog = Puppet::Parser::Compiler.new(node).compile
+ assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "puppet"))
+ assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "myhost"))
+ }
+ ensure
+ Puppet[:storeconfigs] = false
+ Puppet::Resource::Catalog.cache_class = catalog_cache_class
+ Puppet::Node::Facts.cache_class = facts_cache_class
+ Puppet::Node.cache_class = node_cache_class
+ end
+ else
+ $stderr.puts "No ActiveRecord -- skipping collection tests"
+ end
- def test_namespaces
- scope = mkscope
+ def test_namespaces
+ scope = mkscope
- assert_equal(
- [""], scope.namespaces,
+ assert_equal(
+ [""], scope.namespaces,
- "Started out with incorrect namespaces")
- assert_nothing_raised { scope.add_namespace("fun::test") }
- assert_equal(["fun::test"], scope.namespaces, "Did not add namespace correctly")
- assert_nothing_raised { scope.add_namespace("yay::test") }
- assert_equal(["fun::test", "yay::test"], scope.namespaces, "Did not add extra namespace correctly")
- end
+ "Started out with incorrect namespaces")
+ assert_nothing_raised { scope.add_namespace("fun::test") }
+ assert_equal(["fun::test"], scope.namespaces, "Did not add namespace correctly")
+ assert_nothing_raised { scope.add_namespace("yay::test") }
+ assert_equal(["fun::test", "yay::test"], scope.namespaces, "Did not add extra namespace correctly")
+ end
- # #629 - undef should be "" or :undef
- def test_lookupvar_with_undef
- scope = mkscope
+ # #629 - undef should be "" or :undef
+ def test_lookupvar_with_undef
+ scope = mkscope
- scope.setvar("testing", :undef)
+ scope.setvar("testing", :undef)
- assert_equal(
- :undef, scope.lookupvar("testing", false),
+ assert_equal(
+ :undef, scope.lookupvar("testing", false),
- "undef was not returned as :undef when not string")
+ "undef was not returned as :undef when not string")
- assert_equal(
- "", scope.lookupvar("testing", true),
+ assert_equal(
+ "", scope.lookupvar("testing", true),
- "undef was not returned as '' when string")
- end
+ "undef was not returned as '' when string")
+ end
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index d55b75e50..51c5e23fe 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -9,511 +9,511 @@ require 'puppet/network/handler'
require 'puppettest'
class TestSnippets < Test::Unit::TestCase
- include PuppetTest
+ include PuppetTest
- def setup
- super
- @file = Puppet::Type.type(:file)
- Facter.stubs(:to_hash).returns({})
- Facter.stubs(:value).returns("whatever")
- end
+ def setup
+ super
+ @file = Puppet::Type.type(:file)
+ Facter.stubs(:to_hash).returns({})
+ Facter.stubs(:value).returns("whatever")
+ end
- def self.snippetdir
- PuppetTest.datadir "snippets"
- end
+ def self.snippetdir
+ PuppetTest.datadir "snippets"
+ end
- def assert_file(path, msg = nil)
- unless file = @catalog.resource(:file, path)
- msg ||= "Could not find file #{path}"
- raise msg
- end
+ def assert_file(path, msg = nil)
+ unless file = @catalog.resource(:file, path)
+ msg ||= "Could not find file #{path}"
+ raise msg
end
+ end
- def assert_not_file(path, msg = nil)
- if file = @catalog.resource(:file, path)
- msg ||= "File #{path} exists!"
- raise msg
- end
+ def assert_not_file(path, msg = nil)
+ if file = @catalog.resource(:file, path)
+ msg ||= "File #{path} exists!"
+ raise msg
end
+ end
- def assert_mode_equal(mode, path)
- unless file = @catalog.resource(:file, path)
- raise "Could not find file #{path}"
- end
-
- unless mode == file.should(:mode)
- raise "Mode for %s is incorrect: %o vs %o" % [path, mode, file.should(:mode)]
- end
+ def assert_mode_equal(mode, path)
+ unless file = @catalog.resource(:file, path)
+ raise "Could not find file #{path}"
end
- def snippet(name)
- File.join(self.class.snippetdir, name)
+ unless mode == file.should(:mode)
+ raise "Mode for %s is incorrect: %o vs %o" % [path, mode, file.should(:mode)]
end
+ end
- def file2ast(file)
- parser = Puppet::Parser::Parser.new
- parser.file = file
- ast = parser.parse
+ def snippet(name)
+ File.join(self.class.snippetdir, name)
+ end
- ast
- end
+ def file2ast(file)
+ parser = Puppet::Parser::Parser.new
+ parser.file = file
+ ast = parser.parse
- def snippet2ast(text)
- parser = Puppet::Parser::Parser.new
- parser.string = text
- ast = parser.parse
+ ast
+ end
- ast
- end
+ def snippet2ast(text)
+ parser = Puppet::Parser::Parser.new
+ parser.string = text
+ ast = parser.parse
- def client
- args = {
- :Listen => false
- }
- Puppet::Network::Client.new(args)
- end
+ ast
+ end
- def ast2scope(ast)
- scope = Puppet::Parser::Scope.new
- ast.evaluate(scope)
-
- scope
- end
-
- def scope2objs(scope)
- objs = scope.to_trans
- end
-
- def snippet2scope(snippet)
- ast = snippet2ast(snippet)
- scope = ast2scope(ast)
- end
-
- def snippet2objs(snippet)
- ast = snippet2ast(snippet)
- scope = ast2scope(ast)
- objs = scope2objs(scope)
- end
-
- def properties(type)
- properties = type.validproperties
- end
-
- def metaparams(type)
- mparams = []
- Puppet::Type.eachmetaparam { |param|
- mparams.push param
- }
-
- mparams
- end
-
- def params(type)
- params = []
- type.parameters.each { |name,property|
- params.push name
- }
-
- params
- end
-
- def randthing(thing,type)
- list = self.send(thing,type)
- list[rand(list.length)]
- end
+ def client
+ args = {
+ :Listen => false
+ }
+ Puppet::Network::Client.new(args)
+ end
+
+ def ast2scope(ast)
+ scope = Puppet::Parser::Scope.new
+ ast.evaluate(scope)
+
+ scope
+ end
+
+ def scope2objs(scope)
+ objs = scope.to_trans
+ end
+
+ def snippet2scope(snippet)
+ ast = snippet2ast(snippet)
+ scope = ast2scope(ast)
+ end
+
+ def snippet2objs(snippet)
+ ast = snippet2ast(snippet)
+ scope = ast2scope(ast)
+ objs = scope2objs(scope)
+ end
+
+ def properties(type)
+ properties = type.validproperties
+ end
+
+ def metaparams(type)
+ mparams = []
+ Puppet::Type.eachmetaparam { |param|
+ mparams.push param
+ }
- def randeach(type)
- [:properties, :metaparams, :parameters].collect { |thing|
- randthing(thing,type)
- }
- end
+ mparams
+ end
- @@snippets = {
- true => [
- %{File { mode => 755 }}
- ],
+ def params(type)
+ params = []
+ type.parameters.each { |name,property|
+ params.push name
}
- def disabled_test_defaults
- Puppet::Type.eachtype { |type|
- next if type.name == :puppet or type.name == :component
+ params
+ end
- rands = randeach(type)
+ def randthing(thing,type)
+ list = self.send(thing,type)
+ list[rand(list.length)]
+ end
- name = type.name.to_s.capitalize
-
- [0..1, 0..2].each { |range|
- params = rands[range]
- paramstr = params.collect { |param|
- "#{param} => fake"
- }.join(", ")
+ def randeach(type)
+ [:properties, :metaparams, :parameters].collect { |thing|
+ randthing(thing,type)
+ }
+ end
- str = "#{name} { #{paramstr} }"
+ @@snippets = {
+ true => [
+ %{File { mode => 755 }}
+ ],
+ }
- scope = nil
- assert_nothing_raised {
- scope = snippet2scope(str)
- }
+ def disabled_test_defaults
+ Puppet::Type.eachtype { |type|
+ next if type.name == :puppet or type.name == :component
- defaults = nil
- assert_nothing_raised {
- defaults = scope.lookupdefaults(name)
- }
+ rands = randeach(type)
- p defaults
+ name = type.name.to_s.capitalize
- params.each { |param|
- puts "#{name} => '#{param}'"
- assert(defaults.include?(param))
- }
- }
- }
- end
+ [0..1, 0..2].each { |range|
+ params = rands[range]
+ paramstr = params.collect { |param|
+ "#{param} => fake"
+ }.join(", ")
- # this is here in case no tests get defined; otherwise we get a warning
- def test_nothing
- end
+ str = "#{name} { #{paramstr} }"
- def snippet_filecreate
- %w{a b c d}.each { |letter|
- path = "/tmp/create#{letter}test"
- assert_file(path)
- assert_mode_equal(0755, path) if %w{a b}.include?(letter)
+ scope = nil
+ assert_nothing_raised {
+ scope = snippet2scope(str)
}
- end
- def snippet_simpledefaults
- path = "/tmp/defaulttest"
- assert_file(path)
- assert_mode_equal(0755, path)
- end
-
- def snippet_simpleselector
- files = %w{a b c d}.collect { |letter|
- path = "/tmp/snippetselect#{letter}test"
- assert_file(path)
- assert_mode_equal(0755, path)
+ defaults = nil
+ assert_nothing_raised {
+ defaults = scope.lookupdefaults(name)
}
- end
-
- def snippet_classpathtest
- path = "/tmp/classtest"
-
- file = @catalog.resource(:file, path)
- assert(file, "did not create file #{path}")
- assert_equal( "/Stage[main]/Testing/Mytype[componentname]/File[/tmp/classtest]", file.path)
- end
-
- def snippet_argumentdefaults
- path1 = "/tmp/argumenttest1"
- path2 = "/tmp/argumenttest2"
-
- file1 = @catalog.resource(:file, path1)
- file2 = @catalog.resource(:file, path2)
-
- assert_file(path1)
- assert_mode_equal(0755, path1)
-
- assert_file(path2)
- assert_mode_equal(0644, path2)
- end
-
- def snippet_casestatement
- paths = %w{
- /tmp/existsfile
- /tmp/existsfile2
- /tmp/existsfile3
- /tmp/existsfile4
- /tmp/existsfile5
- /tmp/existsfile6
- }
+ p defaults
- paths.each { |path|
- file = @catalog.resource(:file, path)
- assert(file, "File #{path} is missing")
- assert_mode_equal(0755, path)
+ params.each { |param|
+ puts "#{name} => '#{param}'"
+ assert(defaults.include?(param))
}
- end
+ }
+ }
+ end
- def snippet_implicititeration
- paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" }
+ # this is here in case no tests get defined; otherwise we get a warning
+ def test_nothing
+ end
- paths.each { |path|
- file = @catalog.resource(:file, path)
- assert_file(path)
- assert_mode_equal(0755, path)
- }
- end
+ def snippet_filecreate
+ %w{a b c d}.each { |letter|
+ path = "/tmp/create#{letter}test"
+ assert_file(path)
+ assert_mode_equal(0755, path) if %w{a b}.include?(letter)
+ }
+ end
+
+ def snippet_simpledefaults
+ path = "/tmp/defaulttest"
+ assert_file(path)
+ assert_mode_equal(0755, path)
+ end
+
+ def snippet_simpleselector
+ files = %w{a b c d}.collect { |letter|
+ path = "/tmp/snippetselect#{letter}test"
+ assert_file(path)
+ assert_mode_equal(0755, path)
+ }
+ end
- def snippet_multipleinstances
- paths = %w{a b c}.collect { |l| "/tmp/multipleinstances#{l}" }
+ def snippet_classpathtest
+ path = "/tmp/classtest"
- paths.each { |path|
- assert_file(path)
- assert_mode_equal(0755, path)
+ file = @catalog.resource(:file, path)
+ assert(file, "did not create file #{path}")
- }
- end
+ assert_equal( "/Stage[main]/Testing/Mytype[componentname]/File[/tmp/classtest]", file.path)
+ end
- def snippet_namevartest
- file = "/tmp/testfiletest"
- dir = "/tmp/testdirtest"
- assert_file(file)
- assert_file(dir)
- assert_equal(:directory, @catalog.resource(:file, dir).should(:ensure), "Directory is not set to be a directory")
- end
+ def snippet_argumentdefaults
+ path1 = "/tmp/argumenttest1"
+ path2 = "/tmp/argumenttest2"
- def snippet_scopetest
- file = "/tmp/scopetest"
- assert_file(file)
- assert_mode_equal(0755, file)
- end
+ file1 = @catalog.resource(:file, path1)
+ file2 = @catalog.resource(:file, path2)
- def snippet_selectorvalues
- nums = %w{1 2 3 4 5 6 7}
- files = nums.collect { |n|
- "/tmp/selectorvalues#{n}"
- }
+ assert_file(path1)
+ assert_mode_equal(0755, path1)
- files.each { |f|
- assert_file(f)
- assert_mode_equal(0755, f)
- }
- end
+ assert_file(path2)
+ assert_mode_equal(0644, path2)
+ end
- def snippet_singleselector
- nums = %w{1 2 3}
- files = nums.collect { |n|
- "/tmp/singleselector#{n}"
- }
+ def snippet_casestatement
+ paths = %w{
+ /tmp/existsfile
+ /tmp/existsfile2
+ /tmp/existsfile3
+ /tmp/existsfile4
+ /tmp/existsfile5
+ /tmp/existsfile6
+ }
- files.each { |f|
- assert_file(f)
- assert_mode_equal(0755, f)
- }
- end
+ paths.each { |path|
+ file = @catalog.resource(:file, path)
+ assert(file, "File #{path} is missing")
+ assert_mode_equal(0755, path)
+ }
+ end
- def snippet_falsevalues
- file = "/tmp/falsevaluesfalse"
- assert_file(file)
- end
+ def snippet_implicititeration
+ paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" }
- def disabled_snippet_classargtest
- [1,2].each { |num|
- file = "/tmp/classargtest#{num}"
- assert_file(file)
- assert_mode_equal(0755, file)
- }
- end
+ paths.each { |path|
+ file = @catalog.resource(:file, path)
+ assert_file(path)
+ assert_mode_equal(0755, path)
+ }
+ end
- def snippet_classheirarchy
- [1,2,3].each { |num|
- file = "/tmp/classheir#{num}"
- assert_file(file)
- assert_mode_equal(0755, file)
- }
- end
+ def snippet_multipleinstances
+ paths = %w{a b c}.collect { |l| "/tmp/multipleinstances#{l}" }
- def snippet_singleary
- [1,2,3,4].each { |num|
- file = "/tmp/singleary#{num}"
- assert_file(file)
- }
- end
+ paths.each { |path|
+ assert_file(path)
+ assert_mode_equal(0755, path)
- def snippet_classincludes
- [1,2,3].each { |num|
- file = "/tmp/classincludes#{num}"
- assert_file(file)
- assert_mode_equal(0755, file)
- }
- end
+ }
+ end
+
+ def snippet_namevartest
+ file = "/tmp/testfiletest"
+ dir = "/tmp/testdirtest"
+ assert_file(file)
+ assert_file(dir)
+ assert_equal(:directory, @catalog.resource(:file, dir).should(:ensure), "Directory is not set to be a directory")
+ end
+
+ def snippet_scopetest
+ file = "/tmp/scopetest"
+ assert_file(file)
+ assert_mode_equal(0755, file)
+ end
+
+ def snippet_selectorvalues
+ nums = %w{1 2 3 4 5 6 7}
+ files = nums.collect { |n|
+ "/tmp/selectorvalues#{n}"
+ }
- def snippet_componentmetaparams
- ["/tmp/component1", "/tmp/component2"].each { |file|
- assert_file(file)
- }
- end
+ files.each { |f|
+ assert_file(f)
+ assert_mode_equal(0755, f)
+ }
+ end
- def snippet_aliastest
- %w{/tmp/aliastest /tmp/aliastest2 /tmp/aliastest3}.each { |file|
- assert_file(file)
- }
- end
+ def snippet_singleselector
+ nums = %w{1 2 3}
+ files = nums.collect { |n|
+ "/tmp/singleselector#{n}"
+ }
- def snippet_singlequote
- { 1 => 'a $quote',
- 2 => 'some "\yayness\"'
- }.each { |count, str|
- path = "/tmp/singlequote#{count}"
- assert_file(path)
- assert_equal(str, @catalog.resource(:file, path).parameter(:content).actual_content)
- }
- end
+ files.each { |f|
+ assert_file(f)
+ assert_mode_equal(0755, f)
+ }
+ end
+
+ def snippet_falsevalues
+ file = "/tmp/falsevaluesfalse"
+ assert_file(file)
+ end
+
+ def disabled_snippet_classargtest
+ [1,2].each { |num|
+ file = "/tmp/classargtest#{num}"
+ assert_file(file)
+ assert_mode_equal(0755, file)
+ }
+ end
- # There's no way to actually retrieve the list of classes from the
- # transaction.
- def snippet_tag
- end
+ def snippet_classheirarchy
+ [1,2,3].each { |num|
+ file = "/tmp/classheir#{num}"
+ assert_file(file)
+ assert_mode_equal(0755, file)
+ }
+ end
- # Make sure that set tags are correctly in place, yo.
- def snippet_tagged
- tags = {"testing" => true, "yayness" => false,
- "both" => false, "bothtrue" => true, "define" => true}
+ def snippet_singleary
+ [1,2,3,4].each { |num|
+ file = "/tmp/singleary#{num}"
+ assert_file(file)
+ }
+ end
- tags.each do |tag, retval|
- assert_file("/tmp/tagged#{tag}#{retval.to_s}")
- end
- end
+ def snippet_classincludes
+ [1,2,3].each { |num|
+ file = "/tmp/classincludes#{num}"
+ assert_file(file)
+ assert_mode_equal(0755, file)
+ }
+ end
- def snippet_defineoverrides
- file = "/tmp/defineoverrides1"
- assert_file(file)
- assert_mode_equal(0755, file)
- end
+ def snippet_componentmetaparams
+ ["/tmp/component1", "/tmp/component2"].each { |file|
+ assert_file(file)
+ }
+ end
- def snippet_deepclassheirarchy
- 5.times { |i|
- i += 1
- file = "/tmp/deepclassheir#{i}"
- assert_file(file)
- }
- end
+ def snippet_aliastest
+ %w{/tmp/aliastest /tmp/aliastest2 /tmp/aliastest3}.each { |file|
+ assert_file(file)
+ }
+ end
+
+ def snippet_singlequote
+ { 1 => 'a $quote',
+ 2 => 'some "\yayness\"'
+ }.each { |count, str|
+ path = "/tmp/singlequote#{count}"
+ assert_file(path)
+ assert_equal(str, @catalog.resource(:file, path).parameter(:content).actual_content)
+ }
+ end
+
+ # There's no way to actually retrieve the list of classes from the
+ # transaction.
+ def snippet_tag
+ end
+
+ # Make sure that set tags are correctly in place, yo.
+ def snippet_tagged
+ tags = {"testing" => true, "yayness" => false,
+ "both" => false, "bothtrue" => true, "define" => true}
+
+ tags.each do |tag, retval|
+ assert_file("/tmp/tagged#{tag}#{retval.to_s}")
+ end
+ end
+
+ def snippet_defineoverrides
+ file = "/tmp/defineoverrides1"
+ assert_file(file)
+ assert_mode_equal(0755, file)
+ end
+
+ def snippet_deepclassheirarchy
+ 5.times { |i|
+ i += 1
+ file = "/tmp/deepclassheir#{i}"
+ assert_file(file)
+ }
+ end
- def snippet_emptyclass
- # There's nothing to check other than that it works
- end
+ def snippet_emptyclass
+ # There's nothing to check other than that it works
+ end
- def snippet_emptyexec
- assert(@catalog.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec")
- end
+ def snippet_emptyexec
+ assert(@catalog.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec")
+ end
- def snippet_multisubs
- path = "/tmp/multisubtest"
- assert_file(path)
- file = @catalog.resource(:file, path)
- assert_equal("{md5}5fbef65269a99bddc2106251dd89b1dc", file.should(:content), "sub2 did not override content")
- assert_mode_equal(0755, path)
- end
+ def snippet_multisubs
+ path = "/tmp/multisubtest"
+ assert_file(path)
+ file = @catalog.resource(:file, path)
+ assert_equal("{md5}5fbef65269a99bddc2106251dd89b1dc", file.should(:content), "sub2 did not override content")
+ assert_mode_equal(0755, path)
+ end
- def snippet_collection
- assert_file("/tmp/colltest1")
- assert_nil(@catalog.resource(:file, "/tmp/colltest2"), "Incorrectly collected file")
- end
+ def snippet_collection
+ assert_file("/tmp/colltest1")
+ assert_nil(@catalog.resource(:file, "/tmp/colltest2"), "Incorrectly collected file")
+ end
- def snippet_virtualresources
- %w{1 2 3 4}.each do |num|
- assert_file("/tmp/virtualtest#{num}")
- end
+ def snippet_virtualresources
+ %w{1 2 3 4}.each do |num|
+ assert_file("/tmp/virtualtest#{num}")
end
+ end
- def snippet_componentrequire
- %w{1 2}.each do |num|
+ def snippet_componentrequire
+ %w{1 2}.each do |num|
- assert_file(
- "/tmp/testing_component_requires#{num}",
+ assert_file(
+ "/tmp/testing_component_requires#{num}",
- "#{num} does not exist")
- end
- end
-
- def snippet_realize_defined_types
- assert_file("/tmp/realize_defined_test1")
- assert_file("/tmp/realize_defined_test2")
- end
-
- def snippet_collection_within_virtual_definitions
- assert_file("/tmp/collection_within_virtual_definitions1_foo.txt")
- assert_file("/tmp/collection_within_virtual_definitions2_foo2.txt")
- end
-
- def snippet_fqparents
- assert_file("/tmp/fqparent1", "Did not make file from parent class")
- assert_file("/tmp/fqparent2", "Did not make file from subclass")
- end
-
- def snippet_fqdefinition
- assert_file("/tmp/fqdefinition", "Did not make file from fully-qualified definition")
- end
-
- def snippet_subclass_name_duplication
- assert_file("/tmp/subclass_name_duplication1", "Did not make first file from duplicate subclass names")
- assert_file("/tmp/subclass_name_duplication2", "Did not make second file from duplicate subclass names")
- end
-
- def snippet_funccomma
- assert_file("/tmp/funccomma1", "Did not make first file from trailing function comma")
- assert_file("/tmp/funccomma2", "Did not make second file from trailing function comma")
- end
-
- def snippet_arraytrailingcomma
- assert_file("/tmp/arraytrailingcomma1", "Did not make first file from array")
- assert_file("/tmp/arraytrailingcomma2", "Did not make second file from array")
- end
-
- def snippet_multipleclass
- assert_file("/tmp/multipleclassone", "one")
- assert_file("/tmp/multipleclasstwo", "two")
- end
+ "#{num} does not exist")
+ end
+ end
+
+ def snippet_realize_defined_types
+ assert_file("/tmp/realize_defined_test1")
+ assert_file("/tmp/realize_defined_test2")
+ end
+
+ def snippet_collection_within_virtual_definitions
+ assert_file("/tmp/collection_within_virtual_definitions1_foo.txt")
+ assert_file("/tmp/collection_within_virtual_definitions2_foo2.txt")
+ end
+
+ def snippet_fqparents
+ assert_file("/tmp/fqparent1", "Did not make file from parent class")
+ assert_file("/tmp/fqparent2", "Did not make file from subclass")
+ end
+
+ def snippet_fqdefinition
+ assert_file("/tmp/fqdefinition", "Did not make file from fully-qualified definition")
+ end
+
+ def snippet_subclass_name_duplication
+ assert_file("/tmp/subclass_name_duplication1", "Did not make first file from duplicate subclass names")
+ assert_file("/tmp/subclass_name_duplication2", "Did not make second file from duplicate subclass names")
+ end
+
+ def snippet_funccomma
+ assert_file("/tmp/funccomma1", "Did not make first file from trailing function comma")
+ assert_file("/tmp/funccomma2", "Did not make second file from trailing function comma")
+ end
+
+ def snippet_arraytrailingcomma
+ assert_file("/tmp/arraytrailingcomma1", "Did not make first file from array")
+ assert_file("/tmp/arraytrailingcomma2", "Did not make second file from array")
+ end
+
+ def snippet_multipleclass
+ assert_file("/tmp/multipleclassone", "one")
+ assert_file("/tmp/multipleclasstwo", "two")
+ end
+
+ def snippet_multilinecomments
+ assert_not_file("/tmp/multilinecomments","Did create a commented resource");
+ end
+
+ def snippet_collection_override
+ path = "/tmp/collection"
+ assert_file(path)
+ assert_mode_equal(0600, path)
+ end
+
+ def snippet_ifexpression
+ assert_file("/tmp/testiftest","if test");
+ end
+
+ def snippet_hash
+ assert_file("/tmp/myhashfile1","hash test 1");
+ assert_file("/tmp/myhashfile2","hash test 2");
+ assert_file("/tmp/myhashfile3","hash test 3");
+ assert_file("/tmp/myhashfile4","hash test 4");
+ end
+
+ # Iterate across each of the snippets and create a test.
+ Dir.entries(snippetdir).sort.each { |file|
+ next if file =~ /^\./
+
+
+ mname = "snippet_" + file.sub(/\.pp$/, '')
+ if self.method_defined?(mname)
+ #eval("alias #{testname} #{mname}")
+ testname = ("test_#{mname}").intern
+ self.send(:define_method, testname) {
+ Puppet[:manifest] = snippet(file)
+ facts = {
+ "hostname" => "testhost",
+ "domain" => "domain.com",
+ "ipaddress" => "127.0.0.1",
+ "fqdn" => "testhost.domain.com"
+ }
- def snippet_multilinecomments
- assert_not_file("/tmp/multilinecomments","Did create a commented resource");
- end
+ node = Puppet::Node.new("testhost")
+ node.merge(facts)
- def snippet_collection_override
- path = "/tmp/collection"
- assert_file(path)
- assert_mode_equal(0600, path)
- end
+ catalog = nil
+ assert_nothing_raised("Could not compile catalog") {
+ catalog = Puppet::Resource::Catalog.find(node)
+ }
- def snippet_ifexpression
- assert_file("/tmp/testiftest","if test");
- end
+ assert_nothing_raised("Could not convert catalog") {
+ catalog = catalog.to_ral
+ }
- def snippet_hash
- assert_file("/tmp/myhashfile1","hash test 1");
- assert_file("/tmp/myhashfile2","hash test 2");
- assert_file("/tmp/myhashfile3","hash test 3");
- assert_file("/tmp/myhashfile4","hash test 4");
+ @catalog = catalog
+ assert_nothing_raised {
+ self.send(mname)
+ }
+ }
+ mname = mname.intern
end
-
- # Iterate across each of the snippets and create a test.
- Dir.entries(snippetdir).sort.each { |file|
- next if file =~ /^\./
-
-
- mname = "snippet_" + file.sub(/\.pp$/, '')
- if self.method_defined?(mname)
- #eval("alias #{testname} #{mname}")
- testname = ("test_#{mname}").intern
- self.send(:define_method, testname) {
- Puppet[:manifest] = snippet(file)
- facts = {
- "hostname" => "testhost",
- "domain" => "domain.com",
- "ipaddress" => "127.0.0.1",
- "fqdn" => "testhost.domain.com"
- }
-
- node = Puppet::Node.new("testhost")
- node.merge(facts)
-
- catalog = nil
- assert_nothing_raised("Could not compile catalog") {
- catalog = Puppet::Resource::Catalog.find(node)
- }
-
- assert_nothing_raised("Could not convert catalog") {
- catalog = catalog.to_ral
- }
-
- @catalog = catalog
- assert_nothing_raised {
- self.send(mname)
- }
- }
- mname = mname.intern
- end
- }
+ }
end
diff --git a/test/language/transportable.rb b/test/language/transportable.rb
index 37c67d6f8..1e9ae930e 100755
--- a/test/language/transportable.rb
+++ b/test/language/transportable.rb
@@ -9,79 +9,79 @@ require 'puppettest/parsertesting'
require 'yaml'
class TestTransportable < Test::Unit::TestCase
- include PuppetTest::ParserTesting
-
- def test_yamldumpobject
- obj = mk_transobject
- obj.to_yaml_properties
- str = nil
- assert_nothing_raised {
- str = YAML.dump(obj)
- }
-
- newobj = nil
- assert_nothing_raised {
- newobj = YAML.load(str)
- }
-
- assert(newobj.name, "Object has no name")
- assert(newobj.type, "Object has no type")
+ include PuppetTest::ParserTesting
+
+ def test_yamldumpobject
+ obj = mk_transobject
+ obj.to_yaml_properties
+ str = nil
+ assert_nothing_raised {
+ str = YAML.dump(obj)
+ }
+
+ newobj = nil
+ assert_nothing_raised {
+ newobj = YAML.load(str)
+ }
+
+ assert(newobj.name, "Object has no name")
+ assert(newobj.type, "Object has no type")
+ end
+
+ def test_yamldumpbucket
+ objects = %w{/etc/passwd /etc /tmp /var /dev}.collect { |d|
+ mk_transobject(d)
+ }
+ bucket = mk_transbucket(*objects)
+ str = nil
+ assert_nothing_raised {
+ str = YAML.dump(bucket)
+ }
+
+ newobj = nil
+ assert_nothing_raised {
+ newobj = YAML.load(str)
+ }
+
+ assert(newobj.name, "Bucket has no name")
+ assert(newobj.type, "Bucket has no type")
+ end
+
+ # Make sure our 'delve' command is working
+ def test_delve
+ top = mk_transtree do |object, depth, width|
+ object.file = :funtest if width % 2 == 1
end
- def test_yamldumpbucket
- objects = %w{/etc/passwd /etc /tmp /var /dev}.collect { |d|
- mk_transobject(d)
- }
- bucket = mk_transbucket(*objects)
- str = nil
- assert_nothing_raised {
- str = YAML.dump(bucket)
- }
-
- newobj = nil
- assert_nothing_raised {
- newobj = YAML.load(str)
- }
-
- assert(newobj.name, "Bucket has no name")
- assert(newobj.type, "Bucket has no type")
- end
-
- # Make sure our 'delve' command is working
- def test_delve
- top = mk_transtree do |object, depth, width|
- object.file = :funtest if width % 2 == 1
+ objects = []
+ buckets = []
+ found = []
+
+ count = 0
+ assert_nothing_raised {
+ top.delve do |object|
+ count += 1
+ if object.is_a? Puppet::TransBucket
+ buckets << object
+ else
+ objects << object
+ if object.file == :funtest
+ found << object
+ end
end
+ end
+ }
- objects = []
- buckets = []
- found = []
-
- count = 0
- assert_nothing_raised {
- top.delve do |object|
- count += 1
- if object.is_a? Puppet::TransBucket
- buckets << object
- else
- objects << object
- if object.file == :funtest
- found << object
- end
- end
- end
- }
-
- top.flatten.each do |obj|
- assert(objects.include?(obj), "Missing obj #{obj.type}[#{obj.name}]")
- end
+ top.flatten.each do |obj|
+ assert(objects.include?(obj), "Missing obj #{obj.type}[#{obj.name}]")
+ end
- assert_equal(
- found.length,
- top.flatten.find_all { |o| o.file == :funtest }.length,
+ assert_equal(
+ found.length,
+ top.flatten.find_all { |o| o.file == :funtest }.length,
- "Found incorrect number of objects")
- end
+ "Found incorrect number of objects")
+ end
end