diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/snippets/collection_within_virtual_definitions.pp | 20 | ||||
-rw-r--r-- | test/data/snippets/realize_defined_types.pp | 13 | ||||
-rwxr-xr-x | test/language/ast.rb | 66 | ||||
-rwxr-xr-x | test/language/ast/casestatement.rb | 6 | ||||
-rwxr-xr-x | test/language/ast/definition.rb | 166 | ||||
-rwxr-xr-x | test/language/ast/hostclass.rb | 184 | ||||
-rwxr-xr-x | test/language/ast/resource.rb | 13 | ||||
-rwxr-xr-x | test/language/ast/resource_reference.rb | 24 | ||||
-rwxr-xr-x | test/language/ast/selector.rb | 4 | ||||
-rwxr-xr-x | test/language/ast/variable.rb | 4 | ||||
-rwxr-xr-x | test/language/compile.rb | 569 | ||||
-rwxr-xr-x | test/language/functions.rb | 48 | ||||
-rwxr-xr-x | test/language/parser.rb | 16 | ||||
-rwxr-xr-x | test/language/resource.rb | 43 | ||||
-rwxr-xr-x | test/language/scope.rb | 58 | ||||
-rwxr-xr-x | test/language/snippets.rb | 7 | ||||
-rw-r--r-- | test/lib/puppettest/parsertesting.rb | 16 | ||||
-rwxr-xr-x | test/lib/puppettest/support/resources.rb | 2 | ||||
-rwxr-xr-x | test/other/transactions.rb | 8 | ||||
-rwxr-xr-x | test/ral/manager/type.rb | 4 | ||||
-rwxr-xr-x | test/ral/types/basic.rb | 4 |
21 files changed, 133 insertions, 1142 deletions
diff --git a/test/data/snippets/collection_within_virtual_definitions.pp b/test/data/snippets/collection_within_virtual_definitions.pp new file mode 100644 index 000000000..3c21468b0 --- /dev/null +++ b/test/data/snippets/collection_within_virtual_definitions.pp @@ -0,0 +1,20 @@ +define test($name) { + file {"/tmp/collection_within_virtual_definitions1_$name.txt": + content => "File name $name\n" + } + Test2 <||> +} + +define test2() { + file {"/tmp/collection_within_virtual_definitions2_$name.txt": + content => "This is a test\n" + } +} + +node default { + @test {"foo": + name => "foo" + } + @test2 {"foo2": } + Test <||> +} diff --git a/test/data/snippets/realize_defined_types.pp b/test/data/snippets/realize_defined_types.pp deleted file mode 100644 index a4b562258..000000000 --- a/test/data/snippets/realize_defined_types.pp +++ /dev/null @@ -1,13 +0,0 @@ -define testing { - file { "/tmp/realize_defined_test1": ensure => file } -} -@testing { yay: } - -define deeper { - file { "/tmp/realize_defined_test2": ensure => file } -} - -@deeper { boo: } - -realize Testing[yay] -realize File["/tmp/realize_defined_test2"] diff --git a/test/language/ast.rb b/test/language/ast.rb index b31012d38..8c0f31aba 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -35,14 +35,14 @@ class TestAST < Test::Unit::TestCase # We initialized it to true, so we should get that first ret = nil assert_nothing_raised { - ret = astif.evaluate(:scope => "yay") + ret = astif.evaluate("yay") } assert_equal(:if, ret) # Now set it to false and check that faketest.evaluate = false assert_nothing_raised { - ret = astif.evaluate(:scope => "yay") + ret = astif.evaluate("yay") } assert_equal(:else, ret) end @@ -57,10 +57,10 @@ class TestAST < Test::Unit::TestCase end Puppet::Parser::Resource.expects(:new).with { |o| o.is_a?(Hash) }.returns(:override) - scope.compile.expects(:store_override).with(:override) + scope.compiler.expects(:add_override).with(:override) ret = nil assert_nothing_raised do - ret = ref.evaluate :scope => scope + ret = ref.evaluate scope end assert_equal(:override, ret, "Did not return override") @@ -74,7 +74,7 @@ class TestAST < Test::Unit::TestCase args = {:source => "/yay/ness", :group => "yayness"} assert_nothing_raised do obj = defaultobj "file", args - obj.evaluate :scope => scope + obj.evaluate scope end hash = nil @@ -93,56 +93,6 @@ class TestAST < Test::Unit::TestCase end end - def test_node - scope = mkscope - parser = scope.compile.parser - - # Define a base node - basenode = parser.newnode "basenode", :code => AST::ASTArray.new(:children => [ - resourcedef("file", "/tmp/base", "owner" => "root") - ]) - - # Now define a subnode - nodes = parser.newnode ["mynode", "othernode"], - :code => AST::ASTArray.new(:children => [ - resourcedef("file", "/tmp/mynode", "owner" => "root"), - resourcedef("file", "/tmp/basenode", "owner" => "daemon") - ]) - - assert_instance_of(Array, nodes) - - # Make sure we can find them all. - %w{mynode othernode}.each do |node| - assert(parser.nodes[node], "Could not find %s" % node) - end - mynode = parser.nodes["mynode"] - - # Now try evaluating the node - assert_nothing_raised do - mynode.evaluate :scope => scope, :resource => scope.resource - end - - # Make sure that we can find each of the files - myfile = scope.findresource "File[/tmp/mynode]" - assert(myfile, "Could not find file from node") - assert_equal("root", myfile[:owner]) - - basefile = scope.findresource "File[/tmp/basenode]" - assert(basefile, "Could not find file from base node") - assert_equal("daemon", basefile[:owner]) - - # Now make sure we can evaluate nodes with parents - child = parser.newnode(%w{child}, :parent => "basenode").shift - - newscope = mkscope :parser => parser - assert_nothing_raised do - child.evaluate :scope => newscope, :resource => scope.resource - end - - assert(newscope.findresource("File[/tmp/base]"), - "Could not find base resource") - end - def test_collection scope = mkscope @@ -155,13 +105,13 @@ class TestAST < Test::Unit::TestCase ret = nil assert_nothing_raised do - ret = coll.evaluate :scope => scope + ret = coll.evaluate scope end assert_instance_of(Puppet::Parser::Collector, ret) # Now make sure we get it back from the scope - colls = scope.compile.instance_variable_get("@collections") + colls = scope.compiler.instance_variable_get("@collections") assert_equal([ret], colls, "Did not store collector in config's collection list") end @@ -175,7 +125,7 @@ class TestAST < Test::Unit::TestCase run_collection_queries(:virtual) do |string, result, query| code = nil assert_nothing_raised do - str, code = query.evaluate :scope => scope + str, code = query.evaluate scope end assert_instance_of(Proc, code) diff --git a/test/language/ast/casestatement.rb b/test/language/ast/casestatement.rb index 0a744b686..d95d788d9 100755 --- a/test/language/ast/casestatement.rb +++ b/test/language/ast/casestatement.rb @@ -45,7 +45,7 @@ class TestCaseStatement < Test::Unit::TestCase result = nil assert_nothing_raised do - result = ast.evaluate :scope => scope + result = ast.evaluate scope end assert(result, "did not get valid result") assert_equal(["upper"], $evaluated, "Did not match case-sensitively") @@ -56,7 +56,7 @@ class TestCaseStatement < Test::Unit::TestCase $evaluated.clear hash["MyParam"].reset assert_nothing_raised do - result = ast.evaluate :scope => scope + result = ast.evaluate scope end assert(result, "did not get valid result") assert_equal(["lower"], result, "Did not match case-insensitively") @@ -92,7 +92,7 @@ class TestCaseStatement < Test::Unit::TestCase scope = mkscope scope.setvar("testparam", value) assert_nothing_raised do - result = ast.evaluate(:scope => scope) + result = ast.evaluate(scope) end assert_equal(should, result, "Got incorrect result for %s" % value) diff --git a/test/language/ast/definition.rb b/test/language/ast/definition.rb deleted file mode 100755 index 2a71aaa45..000000000 --- a/test/language/ast/definition.rb +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke A. Kanies on 2006-02-20. -# Copyright (c) 2006. All rights reserved. - -require File.dirname(__FILE__) + '/../../lib/puppettest' - -require 'puppettest' -require 'mocha' -require 'puppettest/parsertesting' -require 'puppettest/resourcetesting' - -class TestASTDefinition < Test::Unit::TestCase - include PuppetTest - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - AST = Puppet::Parser::AST - - def test_initialize - parser = mkparser - - # Create a new definition - klass = parser.newdefine "yayness", - :arguments => [["owner", stringobj("nobody")], %w{mode}], - :code => AST::ASTArray.new( - :children => [resourcedef("file", "/tmp/$name", - "owner" => varref("owner"), "mode" => varref("mode"))] - ) - - # Test validattr? a couple different ways - [:owner, "owner", :schedule, "schedule"].each do |var| - assert(klass.validattr?(var), "%s was not considered valid" % var.inspect) - end - - [:random, "random"].each do |var| - assert(! klass.validattr?(var), "%s was considered valid" % var.inspect) - end - - end - - def test_evaluate - parser = mkparser - config = mkcompile - config.send(:evaluate_main) - scope = config.topscope - klass = parser.newdefine "yayness", - :arguments => [["owner", stringobj("nobody")], %w{mode}], - :code => AST::ASTArray.new( - :children => [resourcedef("file", "/tmp/$name", - "owner" => varref("owner"), "mode" => varref("mode"))] - ) - - resource = Puppet::Parser::Resource.new( - :title => "first", - :type => "yayness", - :exported => false, - :virtual => false, - :scope => scope, - :source => scope.source - ) - resource.send(:set_parameter, "name", "first") - resource.send(:set_parameter, "mode", "755") - - resource.stubs(:title) - assert_nothing_raised do - klass.evaluate(:scope => scope, :resource => resource) - end - - firstobj = config.findresource("File[/tmp/first]") - assert(firstobj, "Did not create /tmp/first obj") - - assert_equal("File", firstobj.type) - assert_equal("/tmp/first", firstobj.title) - assert_equal("nobody", firstobj[:owner]) - assert_equal("755", firstobj[:mode]) - - # Make sure we can't evaluate it with the same args - assert_raise(Puppet::ParseError) do - klass.evaluate(:scope => scope, :resource => resource) - end - - # Now create another with different args - resource2 = Puppet::Parser::Resource.new( - :title => "second", - :type => "yayness", - :exported => false, - :virtual => false, - :scope => scope, - :source => scope.source - ) - resource2.send(:set_parameter, "name", "second") - resource2.send(:set_parameter, "mode", "755") - resource2.send(:set_parameter, "owner", "daemon") - - assert_nothing_raised do - klass.evaluate(:scope => scope, :resource => resource2) - end - - secondobj = config.findresource("File[/tmp/second]") - assert(secondobj, "Did not create /tmp/second obj") - - assert_equal("File", secondobj.type) - assert_equal("/tmp/second", secondobj.title) - assert_equal("daemon", secondobj[:owner]) - assert_equal("755", secondobj[:mode]) - end - - # #539 - definitions should support both names and titles - def test_names_and_titles - parser = mkparser - scope = mkscope :parser => parser - - [ - {:name => "one", :title => "two"}, - {:title => "mytitle"} - ].each_with_index do |hash, i| - # Create a definition that uses both name and title. Put this - # inside the loop so the subscope expectations work. - klass = parser.newdefine "yayness%s" % i - - resource = Puppet::Parser::Resource.new( - :title => hash[:title], - :type => "yayness%s" % i, - :exported => false, - :virtual => false, - :scope => scope, - :source => scope.source - ) - - subscope = klass.subscope(scope, resource) - - klass.expects(:subscope).returns(subscope) - - if hash[:name] - resource.stubs(:to_hash).returns({:name => hash[:name]}) - end - - assert_nothing_raised("Could not evaluate definition with %s" % hash.inspect) do - klass.evaluate(:scope => scope, :resource => resource) - end - - name = hash[:name] || hash[:title] - title = hash[:title] - - assert_equal(name, subscope.lookupvar("name"), - "Name did not get set correctly") - assert_equal(title, subscope.lookupvar("title"), - "title did not get set correctly") - - [:name, :title].each do |param| - val = resource.send(param) - assert(subscope.tags.include?(val), - "Scope was not tagged with %s '%s'" % [param, val]) - end - end - end - - # Testing the root cause of #615. We should be using the fqname for the type, instead - # of just the short name. - def test_fully_qualified_types - parser = mkparser - klass = parser.newclass("one::two") - - assert_equal("one::two", klass.classname, "Class did not get fully qualified class name") - end -end diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb deleted file mode 100755 index 80032f30c..000000000 --- a/test/language/ast/hostclass.rb +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env ruby -# -# Created by Luke A. Kanies on 2006-02-20. -# Copyright (c) 2006. All rights reserved. - -require File.dirname(__FILE__) + '/../../lib/puppettest' - -require 'puppettest' -require 'puppettest/parsertesting' -require 'puppettest/resourcetesting' -require 'mocha' - -class TestASTHostClass < Test::Unit::TestCase - include PuppetTest - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - AST = Puppet::Parser::AST - - def test_hostclass - scope = mkscope - parser = scope.compile.parser - - # Create the class we're testing, first with no parent - klass = parser.newclass "first", - :code => AST::ASTArray.new( - :children => [resourcedef("file", "/tmp", - "owner" => "nobody", "mode" => "755")] - ) - - resource = Puppet::Parser::Resource.new(:type => "class", :title => "first", :scope => scope) - assert_nothing_raised do - klass.evaluate(:scope => scope, :resource => resource) - end - - # Then try it again - assert_nothing_raised do - klass.evaluate(:scope => scope, :resource => resource) - end - - assert(scope.compile.class_scope(klass), "Class was not considered evaluated") - - tmp = scope.findresource("File[/tmp]") - assert(tmp, "Could not find file /tmp") - assert_equal("nobody", tmp[:owner]) - assert_equal("755", tmp[:mode]) - - # Now create a couple more classes. - newbase = parser.newclass "newbase", - :code => AST::ASTArray.new( - :children => [resourcedef("file", "/tmp/other", - "owner" => "nobody", "mode" => "644")] - ) - - newsub = parser.newclass "newsub", - :parent => "newbase", - :code => AST::ASTArray.new( - :children => [resourcedef("file", "/tmp/yay", - "owner" => "nobody", "mode" => "755"), - resourceoverride("file", "/tmp/other", - "owner" => "daemon") - ] - ) - - # Override a different variable in the top scope. - moresub = parser.newclass "moresub", - :parent => "newbase", - :code => AST::ASTArray.new( - :children => [resourceoverride("file", "/tmp/other", - "mode" => "755")] - ) - - assert_nothing_raised do - newsub.evaluate(:scope => scope, :resource => resource) - end - - assert_nothing_raised do - moresub.evaluate(:scope => scope, :resource => resource) - end - - assert(scope.compile.class_scope(newbase), "Did not eval newbase") - assert(scope.compile.class_scope(newsub), "Did not eval newsub") - - yay = scope.findresource("File[/tmp/yay]") - assert(yay, "Did not find file /tmp/yay") - assert_equal("nobody", yay[:owner]) - assert_equal("755", yay[:mode]) - - other = scope.findresource("File[/tmp/other]") - assert(other, "Did not find file /tmp/other") - assert_equal("daemon", other[:owner]) - assert_equal("755", other[:mode]) - end - - # Make sure that classes set their namespaces to themselves. This - # way they start looking for definitions in their own namespace. - def test_hostclass_namespace - scope = mkscope - parser = scope.compile.parser - - # Create a new class - klass = nil - assert_nothing_raised do - klass = parser.newclass "funtest" - end - - # Now define a definition in that namespace - - define = nil - assert_nothing_raised do - define = parser.newdefine "funtest::mydefine" - end - - assert_equal("funtest", klass.namespace, - "component namespace was not set in the class") - - assert_equal("funtest", define.namespace, - "component namespace was not set in the definition") - - newscope = klass.subscope(scope, mock("resource")) - - assert_equal(["funtest"], newscope.namespaces, - "Scope did not inherit namespace") - - # Now make sure we can find the define - assert(newscope.finddefine("mydefine"), - "Could not find definition in my enclosing class") - end - - # Make sure that our scope is a subscope of the parentclass's scope. - # At the same time, make sure definitions in the parent class can be - # found within the subclass (#517). - def test_parent_scope_from_parentclass - scope = mkscope - parser = scope.compile.parser - - source = parser.newclass "" - parser.newclass("base") - fun = parser.newdefine("base::fun") - parser.newclass("middle", :parent => "base") - parser.newclass("sub", :parent => "middle") - scope = mkscope :parser => parser - - ret = nil - assert_nothing_raised do - ret = scope.compile.evaluate_classes(["sub"], scope) - end - scope.compile.send(:evaluate_generators) - - subscope = scope.compile.class_scope(scope.findclass("sub")) - assert(subscope, "could not find sub scope") - mscope = scope.compile.class_scope(scope.findclass("middle")) - assert(mscope, "could not find middle scope") - pscope = scope.compile.class_scope(scope.findclass("base")) - assert(pscope, "could not find parent scope") - - assert(pscope == mscope.parent, "parent scope of middle was not set correctly") - assert(mscope == subscope.parent, "parent scope of sub was not set correctly") - - result = mscope.finddefine("fun") - assert(result, "could not find parent-defined definition from middle") - assert(fun == result, "found incorrect parent-defined definition from middle") - - result = subscope.finddefine("fun") - assert(result, "could not find parent-defined definition from sub") - assert(fun == result, "found incorrect parent-defined definition from sub") - end - - # #795 - make sure the subclass's tags get set before we - # evaluate the parent class, so we can be sure that the parent - # class can switch based on the sub classes. - def test_tags_set_before_parent_is_evaluated - scope = mkscope - parser = scope.compile.parser - base = parser.newclass "base" - sub = parser.newclass "sub", :parent => "base" - - base.expects(:safeevaluate).with do |args| - assert(scope.compile.catalog.tags.include?("sub"), "Did not tag with sub class name before evaluating base class") - base.evaluate(args) - true - end - sub.evaluate :scope => scope, :resource => scope.resource - end -end diff --git a/test/language/ast/resource.rb b/test/language/ast/resource.rb index c99d98eeb..97541d92f 100755 --- a/test/language/ast/resource.rb +++ b/test/language/ast/resource.rb @@ -16,8 +16,7 @@ class TestASTResource< Test::Unit::TestCase def setup super @scope = mkscope - @parser = @scope.compile.parser - @scope.compile.send(:evaluate_main) + @parser = @scope.compiler.parser end def newdef(type, title, params = nil) @@ -36,24 +35,24 @@ class TestASTResource< Test::Unit::TestCase title = "title" # First try a qualified type - assert_equal("One::Two", newdef("two", title).evaluate(:scope => twoscope)[0].type, + assert_equal("One::Two", newdef("two", title).evaluate(twoscope)[0].type, "Defined type was not made fully qualified") # Then try a type that does not need to be qualified - assert_equal("One", newdef("one", title).evaluate(:scope => twoscope)[0].type, + assert_equal("One", newdef("one", title).evaluate(twoscope)[0].type, "Unqualified defined type was not handled correctly") # Then an unqualified type from within the one namespace - assert_equal("Three", newdef("three", title).evaluate(:scope => twoscope)[0].type, + assert_equal("Three", newdef("three", title).evaluate(twoscope)[0].type, "Defined type was not made fully qualified") # Then a builtin type - assert_equal("File", newdef("file", title).evaluate(:scope => twoscope)[0].type, + assert_equal("File", newdef("file", title).evaluate(twoscope)[0].type, "Builtin type was not handled correctly") # Now try a type that does not exist, which should throw an error. assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do - newdef("nosuchtype", title).evaluate(:scope => twoscope) + newdef("nosuchtype", title).evaluate(twoscope) end end end diff --git a/test/language/ast/resource_reference.rb b/test/language/ast/resource_reference.rb index c9fde078f..1f554d90f 100755 --- a/test/language/ast/resource_reference.rb +++ b/test/language/ast/resource_reference.rb @@ -20,7 +20,7 @@ class TestASTResourceReference < Test::Unit::TestCase def setup super @scope = mkscope - @parser = @scope.compile.parser + @parser = @scope.compiler.parser end def test_evaluate @@ -31,7 +31,7 @@ class TestASTResourceReference < Test::Unit::TestCase evaled = nil assert_nothing_raised("Could not evaluate resource ref") do - evaled = ref.evaluate(:scope => @scope) + evaled = ref.evaluate(@scope) end assert_equal(type, evaled.type, "Type did not translate correctly") @@ -44,7 +44,7 @@ class TestASTResourceReference < Test::Unit::TestCase ref = newref("Class", "one") evaled = nil assert_nothing_raised("Could not evaluate resource ref") do - evaled = ref.evaluate(:scope => @scope) + evaled = ref.evaluate(@scope) end assert_equal("Class", evaled.type, "Did not set type to 'class'") @@ -61,24 +61,24 @@ class TestASTResourceReference < Test::Unit::TestCase title = "title" # First try a qualified type - assert_equal("One::Two", newref("two", title).evaluate(:scope => twoscope).type, + assert_equal("One::Two", newref("two", title).evaluate(twoscope).type, "Defined type was not made fully qualified") # Then try a type that does not need to be qualified - assert_equal("One", newref("one", title).evaluate(:scope => twoscope).type, + assert_equal("One", newref("one", title).evaluate(twoscope).type, "Unqualified defined type was not handled correctly") # Then an unqualified type from within the one namespace - assert_equal("Three", newref("three", title).evaluate(:scope => twoscope).type, + assert_equal("Three", newref("three", title).evaluate(twoscope).type, "Defined type was not made fully qualified") # Then a builtin type - assert_equal("File", newref("file", title).evaluate(:scope => twoscope).type, + assert_equal("File", newref("file", title).evaluate(twoscope).type, "Builtin type was not handled correctly") # Now try a type that does not exist, which should throw an error. assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do - newref("nosuchtype", title).evaluate(:scope => twoscope) + newref("nosuchtype", title).evaluate(twoscope) end # Now run the same tests, but with the classes @@ -86,20 +86,20 @@ class TestASTResourceReference < Test::Unit::TestCase @parser.newclass "one::five" # First try an unqualified type - assert_equal("four", newref("class", "four").evaluate(:scope => twoscope).title, + assert_equal("four", newref("class", "four").evaluate(twoscope).title, "Unqualified class was not found") # Then a qualified class - assert_equal("one::five", newref("class", "five").evaluate(:scope => twoscope).title, + assert_equal("one::five", newref("class", "five").evaluate(twoscope).title, "Class was not made fully qualified") # Then try a type that does not need to be qualified - assert_equal("four", newref("class", "four").evaluate(:scope => twoscope).title, + assert_equal("four", newref("class", "four").evaluate(twoscope).title, "Unqualified class was not handled correctly") # Now try a type that does not exist, which should throw an error. assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do - newref("class", "nosuchclass").evaluate(:scope => twoscope) + newref("class", "nosuchclass").evaluate(twoscope) end end end diff --git a/test/language/ast/selector.rb b/test/language/ast/selector.rb index 535fcbf70..6e923bdcb 100755 --- a/test/language/ast/selector.rb +++ b/test/language/ast/selector.rb @@ -37,7 +37,7 @@ class TestSelector < Test::Unit::TestCase params = maker.call() sel = AST::Selector.new(:param => param, :values => params.values) result = nil - assert_nothing_raised { result = sel.evaluate(:scope => scope) } + assert_nothing_raised { result = sel.evaluate(scope) } assert_equal(should[str], result, "did not case-sensitively match %s" % str) end @@ -53,7 +53,7 @@ class TestSelector < Test::Unit::TestCase params.delete(:upper) sel = AST::Selector.new(:param => param, :values => params.values) result = nil - assert_nothing_raised { result = sel.evaluate(:scope => scope) } + assert_nothing_raised { result = sel.evaluate(scope) } assert_equal("lower", result, "did not case-insensitively match %s" % str) end end diff --git a/test/language/ast/variable.rb b/test/language/ast/variable.rb index 09122ce16..bde397bb4 100755 --- a/test/language/ast/variable.rb +++ b/test/language/ast/variable.rb @@ -22,9 +22,9 @@ class TestVariable < Test::Unit::TestCase end def test_evaluate - assert_equal("", @var.evaluate(:scope => @scope), "did not return empty string on unset var") + assert_equal("", @var.evaluate(@scope), "did not return empty string on unset var") @scope.setvar(@name, "something") - assert_equal("something", @var.evaluate(:scope => @scope), "incorrect variable value") + assert_equal("something", @var.evaluate(@scope), "incorrect variable value") end end diff --git a/test/language/compile.rb b/test/language/compile.rb deleted file mode 100755 index 082b37a1c..000000000 --- a/test/language/compile.rb +++ /dev/null @@ -1,569 +0,0 @@ -#!/usr/bin/env ruby - -require File.dirname(__FILE__) + '/../lib/puppettest' - -require 'mocha' -require 'puppettest' -require 'puppettest/parsertesting' -require 'puppet/parser/compile' - -# Test our compile object. -class TestCompile < Test::Unit::TestCase - include PuppetTest - include PuppetTest::ParserTesting - - Compile = Puppet::Parser::Compile - Scope = Puppet::Parser::Scope - Node = Puppet::Network::Handler.handler(:node) - SimpleNode = Puppet::Node - - def mknode(name = "foo") - @node = SimpleNode.new(name) - end - - def mkparser - # This should mock an interpreter - @parser = stub 'parser', :version => "1.0", :nodes => {} - end - - def mkcompile(options = {}) - if node = options[:node] - options.delete(:node) - else - node = mknode - end - @compile = Compile.new(node, mkparser, options) - end - - def test_initialize - compile = nil - node = stub 'node', :name => "foo" - parser = stub 'parser', :version => "1.0", :nodes => {} - assert_nothing_raised("Could not init compile with all required options") do - compile = Compile.new(node, parser) - end - - assert_equal(node, compile.node, "Did not set node correctly") - assert_equal(parser, compile.parser, "Did not set parser correctly") - - # We're not testing here whether we call initvars, because it's too difficult to - # mock. - - # Now try it with some options - assert_nothing_raised("Could not init compile with extra options") do - compile = Compile.new(node, parser) - end - - assert_equal(false, compile.ast_nodes?, "Did not set ast_nodes? correctly") - end - - def test_initvars - compile = mkcompile - [:class_scopes, :resource_table, :exported_resources, :resource_overrides].each do |table| - assert_instance_of(Hash, compile.send(:instance_variable_get, "@#{table}"), "Did not set %s table correctly" % table) - end - assert_instance_of(Scope, compile.topscope, "Did not create a topscope") - graph = compile.instance_variable_get("@scope_graph") - assert_instance_of(Puppet::SimpleGraph, graph, "Did not create scope graph") - assert(graph.vertex?(compile.topscope), "Did not add top scope as a vertex in the graph") - end - - # Make sure we store and can retrieve references to classes and their scopes. - def test_class_set_and_class_scope - klass = mock 'ast_class' - klass.expects(:classname).returns("myname") - - compile = mkcompile - compile.catalog.expects(:tag).with("myname") - - assert_nothing_raised("Could not set class") do - compile.class_set "myname", "myscope" - end - # First try to retrieve it by name. - assert_equal("myscope", compile.class_scope("myname"), "Could not retrieve class scope by name") - - # Then by object - assert_equal("myscope", compile.class_scope(klass), "Could not retrieve class scope by object") - end - - def test_classlist - compile = mkcompile - - compile.class_set "", "empty" - compile.class_set "one", "yep" - compile.class_set "two", "nope" - - # Make sure our class list is correct - assert_equal(%w{one two}.sort, compile.classlist.sort, "Did not get correct class list") - end - - # Make sure collections get added to our internal array - def test_add_collection - compile = mkcompile - assert_nothing_raised("Could not add collection") do - compile.add_collection "nope" - end - assert_equal(%w{nope}, compile.instance_variable_get("@collections"), "Did not add collection") - end - - # Make sure we create a graph of scopes. - def test_newscope - compile = mkcompile - graph = compile.instance_variable_get("@scope_graph") - assert_instance_of(Scope, compile.topscope, "Did not create top scope") - assert_instance_of(Puppet::SimpleGraph, graph, "Did not create graph") - - assert(graph.vertex?(compile.topscope), "The top scope is not a vertex in the graph") - - # Now that we've got the top scope, create a new, subscope - subscope = nil - assert_nothing_raised("Could not create subscope") do - subscope = compile.newscope(compile.topscope) - end - assert_instance_of(Scope, subscope, "Did not create subscope") - assert(graph.edge?(compile.topscope, subscope), "An edge between top scope and subscope was not added") - - # Make sure a scope can find its parent. - assert(compile.parent(subscope), "Could not look up parent scope on compile") - assert_equal(compile.topscope.object_id, compile.parent(subscope).object_id, "Did not get correct parent scope from compile") - assert_equal(compile.topscope.object_id, subscope.parent.object_id, "Scope did not correctly retrieve its parent scope") - - # Now create another, this time specifying options - another = nil - assert_nothing_raised("Could not create subscope") do - another = compile.newscope(subscope, :level => 5) - end - assert_equal(5, another.level, "did not set scope option correctly") - assert_instance_of(Scope, another, "Did not create second subscope") - assert(graph.edge?(subscope, another), "An edge between parent scope and second subscope was not added") - - # Make sure it can find its parent. - assert(compile.parent(another), "Could not look up parent scope of second subscope on compile") - assert_equal(subscope.object_id, compile.parent(another).object_id, "Did not get correct parent scope of second subscope from compile") - assert_equal(subscope.object_id, another.parent.object_id, "Second subscope did not correctly retrieve its parent scope") - - # And make sure both scopes show up in the right order in the search path - assert_equal([another.object_id, subscope.object_id, compile.topscope.object_id], another.scope_path.collect { |p| p.object_id }, - "Did not get correct scope path") - end - - # The heart of the action. - def test_compile - compile = mkcompile - [:set_node_parameters, :evaluate_main, :evaluate_ast_node, :evaluate_node_classes, :evaluate_generators, :fail_on_unevaluated, :finish].each do |method| - compile.expects(method) - end - assert_instance_of(Puppet::Node::Catalog, compile.compile, "Did not return the catalog") - end - - # Test setting the node's parameters into the top scope. - def test_set_node_parameters - compile = mkcompile - @node.parameters = {"a" => "b", "c" => "d"} - scope = compile.topscope - @node.parameters.each do |param, value| - scope.expects(:setvar).with(param, value) - end - - assert_nothing_raised("Could not call 'set_node_parameters'") do - compile.send(:set_node_parameters) - end - end - - # Test that we can evaluate the main class, which is the one named "" in namespace - # "". - def test_evaluate_main - compile = mkcompile - main_class = mock 'main_class' - compile.topscope.expects(:source=).with(main_class) - @parser.expects(:findclass).with("", "").returns(main_class) - - main_resource = mock 'main resource' - Puppet::Parser::Resource.expects(:new).with { |args| args[:title] == :main }.returns(main_resource) - - main_resource.expects(:evaluate) - - assert_nothing_raised("Could not call evaluate_main") do - compile.send(:evaluate_main) - end - end - - def test_evaluate_node_classes - compile = mkcompile - @node.classes = %w{one two three four} - compile.expects(:evaluate_classes).with(%w{one two three four}, compile.topscope) - assert_nothing_raised("could not call evaluate_node_classes") do - compile.send(:evaluate_node_classes) - end - end - - def test_evaluate_collections - compile = mkcompile - - colls = [] - - # Make sure we return false when there's nothing there. - assert(! compile.send(:evaluate_collections), "Returned true when there were no collections") - - # And when the collections fail to evaluate. - colls << mock("coll1-false") - colls << mock("coll2-false") - colls.each { |c| c.expects(:evaluate).returns(false) } - - compile.instance_variable_set("@collections", colls) - assert(! compile.send(:evaluate_collections), "Returned true when collections both evaluated nothing") - - # Now have one of the colls evaluate - colls.clear - colls << mock("coll1-one-true") - colls << mock("coll2-one-true") - colls[0].expects(:evaluate).returns(true) - colls[1].expects(:evaluate).returns(false) - assert(compile.send(:evaluate_collections), "Did not return true when one collection evaluated true") - - # And have them both eval true - colls.clear - colls << mock("coll1-both-true") - colls << mock("coll2-both-true") - colls[0].expects(:evaluate).returns(true) - colls[1].expects(:evaluate).returns(true) - assert(compile.send(:evaluate_collections), "Did not return true when both collections evaluated true") - end - - def test_unevaluated_resources - compile = mkcompile - resources = {} - compile.instance_variable_set("@resource_table", resources) - - # First test it when the table is empty - assert_nil(compile.send(:unevaluated_resources), "Somehow found unevaluated resources in an empty table") - - # Then add a builtin resources - resources["one"] = mock("builtin only") - resources["one"].expects(:builtin?).returns(true) - assert_nil(compile.send(:unevaluated_resources), "Considered a builtin resource unevaluated") - - # And do both builtin and non-builtin but already evaluated - resources.clear - resources["one"] = mock("builtin (with eval)") - resources["one"].expects(:builtin?).returns(true) - resources["two"] = mock("evaled (with builtin)") - resources["two"].expects(:builtin?).returns(false) - resources["two"].expects(:evaluated?).returns(true) - assert_nil(compile.send(:unevaluated_resources), "Considered either a builtin or evaluated resource unevaluated") - - # Now a single unevaluated resource. - resources.clear - resources["one"] = mock("unevaluated") - resources["one"].expects(:builtin?).returns(false) - resources["one"].expects(:evaluated?).returns(false) - assert_equal([resources["one"]], compile.send(:unevaluated_resources), "Did not find unevaluated resource") - - # With two uneval'ed resources, and an eval'ed one thrown in - resources.clear - resources["one"] = mock("unevaluated one") - resources["one"].expects(:builtin?).returns(false) - resources["one"].expects(:evaluated?).returns(false) - resources["two"] = mock("unevaluated two") - resources["two"].expects(:builtin?).returns(false) - resources["two"].expects(:evaluated?).returns(false) - resources["three"] = mock("evaluated") - resources["three"].expects(:builtin?).returns(false) - resources["three"].expects(:evaluated?).returns(true) - - result = compile.send(:unevaluated_resources) - %w{one two}.each do |name| - assert(result.include?(resources[name]), "Did not find %s in the unevaluated list" % name) - end - end - - def test_evaluate_definitions - # First try the case where there's nothing to return - compile = mkcompile - compile.expects(:unevaluated_resources).returns(nil) - - assert_nothing_raised("Could not test for unevaluated resources") do - assert(! compile.send(:evaluate_definitions), "evaluate_definitions returned true when no resources were evaluated") - end - - # Now try it with resources left to evaluate - resources = [] - res1 = mock("resource1") - res1.expects(:evaluate) - res2 = mock("resource2") - res2.expects(:evaluate) - resources << res1 << res2 - compile = mkcompile - compile.expects(:unevaluated_resources).returns(resources) - - assert_nothing_raised("Could not test for unevaluated resources") do - assert(compile.send(:evaluate_definitions), "evaluate_definitions returned false when resources were evaluated") - end - end - - def test_evaluate_generators - # First try the case where we have nothing to do - compile = mkcompile - compile.expects(:evaluate_definitions).returns(false) - compile.expects(:evaluate_collections).returns(false) - - assert_nothing_raised("Could not call :eval_iterate") do - compile.send(:evaluate_generators) - end - - # FIXME I could not get this test to work, but the code is short - # enough that I'm ok with it. - # It's important that collections are evaluated before definitions, - # so make sure that's the case by verifying that collections get tested - # twice but definitions only once. - #compile = mkcompile - #compile.expects(:evaluate_collections).returns(true).returns(false) - #compile.expects(:evaluate_definitions).returns(false) - #compile.send(:eval_iterate) - end - - def test_store - compile = mkcompile - Puppet.features.expects(:rails?).returns(true) - Puppet::Rails.expects(:connect) - - node = mock 'node' - resource_table = mock 'resources' - resource_table.expects(:values).returns(:resources) - compile.instance_variable_set("@node", node) - compile.instance_variable_set("@resource_table", resource_table) - compile.expects(:store_to_active_record).with(node, :resources) - compile.send(:store) - end - - def test_store_to_active_record - compile = mkcompile - node = mock 'node' - node.expects(:name).returns("myname") - Puppet::Rails::Host.stubs(:transaction).yields - Puppet::Rails::Host.expects(:store).with(node, :resources) - compile.send(:store_to_active_record, node, :resources) - end - - # Make sure that 'finish' gets called on all of our resources. - def test_finish - compile = mkcompile - table = compile.instance_variable_get("@resource_table") - - # Add a resource that does respond to :finish - yep = mock("finisher") - yep.expects(:respond_to?).with(:finish).returns(true) - yep.expects(:finish) - table["yep"] = yep - - # And one that does not - dnf = mock("dnf") - dnf.expects(:respond_to?).with(:finish).returns(false) - table["dnf"] = dnf - - compile.send(:finish) - end - - def test_verify_uniqueness - compile = mkcompile - - resources = compile.instance_variable_get("@resource_table") - resource = mock("noconflict") - resource.expects(:ref).returns("File[yay]") - assert_nothing_raised("Raised an exception when there should have been no conflict") do - compile.send(:verify_uniqueness, resource) - end - - # Now try the case where our type is isomorphic - resources["thing"] = true - - isoconflict = mock("isoconflict") - isoconflict.expects(:ref).returns("thing") - isoconflict.expects(:type).returns("testtype") - faketype = mock("faketype") - faketype.expects(:isomorphic?).returns(false) - faketype.expects(:name).returns("whatever") - Puppet::Type.expects(:type).with("testtype").returns(faketype) - assert_nothing_raised("Raised an exception when was a conflict in non-isomorphic types") do - compile.send(:verify_uniqueness, isoconflict) - end - - # Now test for when we actually have an exception - initial = mock("initial") - resources["thing"] = initial - initial.expects(:file).returns(false) - - conflict = mock("conflict") - conflict.expects(:ref).returns("thing").times(2) - conflict.expects(:type).returns("conflict") - conflict.expects(:file).returns(false) - conflict.expects(:line).returns(false) - - faketype = mock("faketype") - faketype.expects(:isomorphic?).returns(true) - Puppet::Type.expects(:type).with("conflict").returns(faketype) - assert_raise(Puppet::ParseError, "Did not fail when two isomorphic resources conflicted") do - compile.send(:verify_uniqueness, conflict) - end - end - - def test_store_resource - # Run once when there's no conflict - compile = mkcompile - table = compile.instance_variable_get("@resource_table") - resource = mock("resource") - resource.expects(:ref).returns("yay") - compile.expects(:verify_uniqueness).with(resource) - scope = stub("scope", :resource => mock('resource')) - - compile.catalog.expects(:add_edge!).with(scope.resource, resource) - - assert_nothing_raised("Could not store resource") do - compile.store_resource(scope, resource) - end - assert_equal(resource, table["yay"], "Did not store resource in table") - - # Now for conflicts - compile = mkcompile - table = compile.instance_variable_get("@resource_table") - resource = mock("resource") - compile.expects(:verify_uniqueness).with(resource).raises(ArgumentError) - - assert_raise(ArgumentError, "Did not raise uniqueness exception") do - compile.store_resource(scope, resource) - end - assert(table.empty?, "Conflicting resource was stored in table") - end - - def test_fail_on_unevaluated - compile = mkcompile - compile.expects(:fail_on_unevaluated_overrides) - compile.expects(:fail_on_unevaluated_resource_collections) - compile.send :fail_on_unevaluated - end - - def test_store_override - # First test the case when the resource is not present. - compile = mkcompile - overrides = compile.instance_variable_get("@resource_overrides") - override = Object.new - override.expects(:ref).returns(:myref).times(2) - override.expects(:override=).with(true) - - assert_nothing_raised("Could not call store_override") do - compile.store_override(override) - end - assert_instance_of(Array, overrides[:myref], "Overrides table is not a hash of arrays") - assert_equal(override, overrides[:myref][0], "Did not store override in appropriately named array") - - # And when the resource already exists. - resource = mock 'resource' - resources = compile.instance_variable_get("@resource_table") - resources[:resref] = resource - - override = mock 'override' - resource.expects(:merge).with(override) - override.expects(:override=).with(true) - override.expects(:ref).returns(:resref) - assert_nothing_raised("Could not call store_override when the resource already exists.") do - compile.store_override(override) - end - end - - def test_resource_overrides - compile = mkcompile - overrides = compile.instance_variable_get("@resource_overrides") - overrides[:test] = :yay - resource = mock 'resource' - resource.expects(:ref).returns(:test) - - assert_equal(:yay, compile.resource_overrides(resource), "Did not return overrides from table") - end - - def test_fail_on_unevaluated_resource_collections - compile = mkcompile - collections = compile.instance_variable_get("@collections") - - # Make sure we're fine when the list is empty - assert_nothing_raised("Failed when no collections were present") do - compile.send :fail_on_unevaluated_resource_collections - end - - # And that we're fine when we've got collections but with no resources - collections << mock('coll') - collections[0].expects(:resources).returns(nil) - assert_nothing_raised("Failed when no resource collections were present") do - compile.send :fail_on_unevaluated_resource_collections - end - - # But that we do fail when we've got resource collections left. - collections.clear - - # return both an array and a string, because that's tested internally - collections << mock('coll returns one') - collections[0].expects(:resources).returns(:something) - - collections << mock('coll returns many') - collections[1].expects(:resources).returns([:one, :two]) - - assert_raise(Puppet::ParseError, "Did not fail on unevaluated resource collections") do - compile.send :fail_on_unevaluated_resource_collections - end - end - - def test_fail_on_unevaluated_overrides - compile = mkcompile - overrides = compile.instance_variable_get("@resource_overrides") - - # Make sure we're fine when the list is empty - assert_nothing_raised("Failed when no collections were present") do - compile.send :fail_on_unevaluated_overrides - end - - # But that we fail if there are any overrides left in the table. - overrides[:yay] = [] - overrides[:foo] = [] - overrides[:bar] = [mock("override")] - overrides[:bar][0].expects(:ref).returns("yay") - assert_raise(Puppet::ParseError, "Failed to fail when overrides remain") do - compile.send :fail_on_unevaluated_overrides - end - end - - def test_find_resource - compile = mkcompile - resources = compile.instance_variable_get("@resource_table") - - assert_nothing_raised("Could not call findresource when the resource table was empty") do - assert_nil(compile.findresource("yay", "foo"), "Returned a non-existent resource") - assert_nil(compile.findresource("yay[foo]"), "Returned a non-existent resource") - end - - resources["Foo[bar]"] = :yay - assert_nothing_raised("Could not call findresource when the resource table was not empty") do - assert_equal(:yay, compile.findresource("foo", "bar"), "Returned a non-existent resource") - assert_equal(:yay, compile.findresource("Foo[bar]"), "Returned a non-existent resource") - end - end - - # #620 - Nodes and classes should conflict, else classes don't get evaluated - def test_nodes_and_classes_name_conflict - # Test node then class - compile = mkcompile - node = stub :nodescope? => true - klass = stub :nodescope? => false - compile.class_set("one", node) - assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do - compile.class_set("one", klass) - end - - # and class then node - compile = mkcompile - node = stub :nodescope? => true - klass = stub :nodescope? => false - compile.class_set("two", klass) - assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do - compile.class_set("two", node) - end - end -end diff --git a/test/language/functions.rb b/test/language/functions.rb index 132ee97ac..a5d52d7ac 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -41,7 +41,7 @@ class TestLangFunctions < Test::Unit::TestCase scope = mkscope val = nil assert_nothing_raised do - val = func.evaluate(:scope => scope) + val = func.evaluate(scope) end assert_equal("output avalue", val) @@ -57,7 +57,7 @@ class TestLangFunctions < Test::Unit::TestCase val = nil assert_nothing_raised do - val = func.evaluate(:scope => scope) + val = func.evaluate(scope) end assert_equal(retval, val, "'tagged' returned %s for %s" % [val, tag]) @@ -66,7 +66,7 @@ class TestLangFunctions < Test::Unit::TestCase # Now make sure we correctly get tags. scope.resource.tag("resourcetag") assert(scope.function_tagged("resourcetag"), "tagged function did not catch resource tags") - scope.compile.catalog.tag("configtag") + scope.compiler.catalog.tag("configtag") assert(scope.function_tagged("configtag"), "tagged function did not catch catalog tags") end @@ -86,7 +86,7 @@ class TestLangFunctions < Test::Unit::TestCase scope = mkscope val = nil assert_raise(Puppet::ParseError) do - val = func.evaluate(:scope => scope) + val = func.evaluate(scope) end end @@ -117,16 +117,16 @@ class TestLangFunctions < Test::Unit::TestCase scope = mkscope assert_raise(Puppet::ParseError) do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end scope.setvar("one", "One") assert_raise(Puppet::ParseError) do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end scope.setvar("two", "Two") assert_nothing_raised do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end assert_equal("template One\ntemplate Two\n", scope.lookupvar("output"), @@ -155,13 +155,13 @@ class TestLangFunctions < Test::Unit::TestCase scope = mkscope assert_raise(Puppet::ParseError) do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end scope.setvar("yayness", "this is yayness") assert_nothing_raised do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end assert_equal("template this is yayness\n", scope.lookupvar("output"), @@ -191,7 +191,7 @@ class TestLangFunctions < Test::Unit::TestCase scope = mkscope scope.setvar("myvar", "this is yayness") assert_raise(Puppet::ParseError) do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end end @@ -264,14 +264,14 @@ class TestLangFunctions < Test::Unit::TestCase }.each do |string, value| scope = mkscope assert_raise(Puppet::ParseError) do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end scope.setvar("yayness", string) assert_equal(string, scope.lookupvar("yayness", false)) assert_nothing_raised("An empty string was not a valid variable value") do - ast.evaluate(:scope => scope) + ast.evaluate(scope) end assert_equal("template #{value}\n", scope.lookupvar("output"), @@ -308,7 +308,7 @@ class TestLangFunctions < Test::Unit::TestCase def test_realize scope = mkscope - parser = scope.compile.parser + parser = scope.compiler.parser # Make a definition parser.newdefine("mytype") @@ -318,7 +318,7 @@ class TestLangFunctions < Test::Unit::TestCase virtual = mkresource(:type => type, :title => title, :virtual => true, :params => {}, :scope => scope) - scope.compile.store_resource(scope, virtual) + scope.compiler.add_resource(scope, virtual) ref = Puppet::Parser::Resource::Reference.new( :type => type, :title => title, @@ -330,13 +330,13 @@ class TestLangFunctions < Test::Unit::TestCase end # Make sure it created a collection - assert_equal(1, scope.compile.collections.length, + assert_equal(1, scope.compiler.collections.length, "Did not set collection") assert_nothing_raised do - scope.compile.collections.each do |coll| coll.evaluate end + scope.compiler.collections.each do |coll| coll.evaluate end end - scope.compile.collections.clear + scope.compiler.collections.clear # Now make sure the virtual resource is no longer virtual assert(! virtual.virtual?, "Did not make virtual resource real") @@ -354,17 +354,17 @@ class TestLangFunctions < Test::Unit::TestCase end # Make sure it created a collection - assert_equal(1, scope.compile.collections.length, + assert_equal(1, scope.compiler.collections.length, "Did not set collection") # And the collection has our resource in it - assert_equal([none.to_s], scope.compile.collections[0].resources, + assert_equal([none.to_s], scope.compiler.collections[0].resources, "Did not set resources in collection") end def test_defined scope = mkscope - parser = scope.compile.parser + parser = scope.compiler.parser parser.newclass("yayness") parser.newdefine("rahness") @@ -385,7 +385,7 @@ class TestLangFunctions < Test::Unit::TestCase "Multiple falses were somehow true") # Now make sure we can test resources - scope.compile.store_resource(scope, mkresource(:type => "file", :title => "/tmp/rahness", + scope.compiler.add_resource(scope, mkresource(:type => "file", :title => "/tmp/rahness", :scope => scope, :source => scope.source, :params => {:owner => "root"})) @@ -420,7 +420,7 @@ class TestLangFunctions < Test::Unit::TestCase def test_include scope = mkscope - parser = scope.compile.parser + parser = scope.compiler.parser assert_raise(Puppet::ParseError, "did not throw error on missing class") do scope.function_include("nosuchclass") @@ -428,7 +428,7 @@ class TestLangFunctions < Test::Unit::TestCase parser.newclass("myclass") - scope.compile.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"]) @@ -480,7 +480,7 @@ class TestLangFunctions < Test::Unit::TestCase assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work") scope = mkscope - parser = scope.compile.parser + parser = scope.compiler.parser val = nil assert_nothing_raised("Could not call generator with no args") do diff --git a/test/language/parser.rb b/test/language/parser.rb index 1bbd894e4..2a0e9c02d 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -45,9 +45,9 @@ class TestParser < Test::Unit::TestCase assert_raise(Puppet::ParseError, "Did not fail while parsing %s" % file) { parser.file = file ast = parser.parse - config = mkcompile(parser) + config = mkcompiler(parser) config.compile - #ast.classes[""].evaluate :scope => config.topscope + #ast.classes[""].evaluate config.topscope } Puppet::Type.allclear } @@ -868,7 +868,7 @@ file { "/tmp/yayness": def test_newclass scope = mkscope - parser = scope.compile.parser + parser = scope.compiler.parser mkcode = proc do |ary| classes = ary.collect do |string| @@ -891,7 +891,7 @@ file { "/tmp/yayness": assert(parser.classes["myclass"], "Could not find definition") assert_equal("myclass", parser.classes["myclass"].classname) assert_equal(%w{original code}, - parser.classes["myclass"].code.evaluate(:scope => scope)) + parser.classes["myclass"].code.evaluate(scope)) # Newclass behaves differently than the others -- it just appends # the code to the existing class. @@ -901,7 +901,7 @@ file { "/tmp/yayness": end assert(klass, "Did not return class when appending") assert_equal(%w{original code something new}, - parser.classes["myclass"].code.evaluate(:scope => scope)) + parser.classes["myclass"].code.evaluate(scope)) # Now create the same class name in a different scope assert_nothing_raised { @@ -914,7 +914,7 @@ file { "/tmp/yayness": assert_equal("other::myclass", other.classname) assert_equal("other::myclass", other.namespace) assert_equal(%w{something diff}, - other.code.evaluate(:scope => scope)) + other.code.evaluate(scope)) # Make sure newclass deals correctly with nodes with no code klass = parser.newclass("nocode") @@ -925,7 +925,7 @@ file { "/tmp/yayness": end assert(klass, "Did not return class with no code") assert_equal(%w{yay test}, - parser.classes["nocode"].code.evaluate(:scope => scope)) + parser.classes["nocode"].code.evaluate(scope)) # Then try merging something into nothing parser.newclass("nocode2", :code => mkcode.call(%w{foo test})) @@ -936,7 +936,7 @@ file { "/tmp/yayness": end assert(klass, "Did not return class with no code") assert_equal(%w{foo test}, - parser.classes["nocode2"].code.evaluate(:scope => scope)) + parser.classes["nocode2"].code.evaluate(scope)) # And lastly, nothing and nothing klass = parser.newclass("nocode3") diff --git a/test/language/resource.rb b/test/language/resource.rb index 5a3916159..608e7c995 100755 --- a/test/language/resource.rb +++ b/test/language/resource.rb @@ -106,7 +106,6 @@ class TestResource < PuppetTest::TestCase def test_finish res = mkresource - res.expects(:add_overrides) res.expects(:add_defaults) res.expects(:add_metaparams) res.expects(:validate) @@ -266,48 +265,12 @@ class TestResource < PuppetTest::TestCase ref.expects(:definedtype).returns(type) res.expects(:finish) res.scope = mock("scope") - config = mock("config") - res.scope.expects(:compile).returns(config) - config.expects(:delete_resource).with(res) - args = {:scope => res.scope, :resource => res} - type.expects(:evaluate).with(args) + type.expects(:evaluate_code).with(res) res.evaluate end - def test_add_overrides - # Try it with nil - res = mkresource - res.scope = mock('scope') - config = mock("config") - res.scope.expects(:compile).returns(config) - config.expects(:resource_overrides).with(res).returns(nil) - res.expects(:merge).never - res.send(:add_overrides) - - # And an empty array - res = mkresource - res.scope = mock('scope') - config = mock("config") - res.scope.expects(:compile).returns(config) - config.expects(:resource_overrides).with(res).returns([]) - res.expects(:merge).never - res.send(:add_overrides) - - # And with some overrides - res = mkresource - res.scope = mock('scope') - config = mock("config") - res.scope.expects(:compile).returns(config) - returns = %w{a b} - config.expects(:resource_overrides).with(res).returns(returns) - res.expects(:merge).with("a") - res.expects(:merge).with("b") - res.send(:add_overrides) - assert(returns.empty?, "Did not clear overrides") - end - def test_proxymethods res = Parser::Resource.new :type => "evaltest", :title => "yay", :source => mock("source"), :scope => mkscope @@ -378,7 +341,7 @@ class TestResource < PuppetTest::TestCase {:name => "one", :title => "two"}, {:title => "three"}, ].each do |hash| - config = mkcompile parser + config = mkcompiler parser args = {:type => "yayness", :title => hash[:title], :source => klass, :scope => config.topscope} if hash[:name] @@ -425,7 +388,7 @@ class TestResource < PuppetTest::TestCase :code => resourcedef("file", varref("name"), "mode" => "644")) - config = mkcompile(parser) + config = mkcompiler(parser) res = mkresource :type => "yayness", :title => "foo", :params => {}, :scope => config.topscope res.virtual = true diff --git a/test/language/scope.rb b/test/language/scope.rb index ec11a864e..c96581a23 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -27,7 +27,7 @@ class TestScope < Test::Unit::TestCase end def test_variables - config = mkcompile + config = mkcompiler topscope = config.topscope midscope = config.newscope(topscope) botscope = config.newscope(midscope) @@ -94,7 +94,7 @@ class TestScope < Test::Unit::TestCase classes = ["", "one", "one::two", "one::two::three"].each do |name| klass = parser.newclass(name) Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate - scopes[name] = scope.compile.class_scope(klass) + scopes[name] = scope.compiler.class_scope(klass) end classes.each do |name| @@ -125,7 +125,7 @@ class TestScope < Test::Unit::TestCase end def test_setdefaults - config = mkcompile + config = mkcompiler scope = config.topscope @@ -151,7 +151,7 @@ class TestScope < Test::Unit::TestCase end def test_lookupdefaults - config = mkcompile + config = mkcompiler top = config.topscope # Make a subscope @@ -179,7 +179,7 @@ class TestScope < Test::Unit::TestCase end def test_parent - config = mkcompile + config = mkcompiler top = config.topscope # Make a subscope @@ -205,7 +205,7 @@ class TestScope < Test::Unit::TestCase %w{one one::two one::two::three}.each do |name| klass = parser.newclass(name) Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate - scopes[name] = scope.compile.class_scope(klass) + scopes[name] = scope.compiler.class_scope(klass) scopes[name].setvar("test", "value-%s" % name.sub(/.+::/,'')) end @@ -284,13 +284,13 @@ class TestScope < Test::Unit::TestCase ) assert_nothing_raised do - function.evaluate :scope => scope + function.evaluate scope end - scope.compile.send(:evaluate_generators) + scope.compiler.send(:evaluate_generators) [myclass, otherclass].each do |klass| - assert(scope.compile.class_scope(klass), + assert(scope.compiler.class_scope(klass), "%s was not set" % klass.classname) end end @@ -328,18 +328,17 @@ class TestScope < Test::Unit::TestCase "undef considered true") end - if defined? ActiveRecord # Verify that we recursively mark as exported the results of collectable # components. - def test_exportedcomponents - config = mkcompile + def test_virtual_definitions_do_not_get_evaluated + config = mkcompiler parser = config.parser # Create a default source config.topscope.source = parser.newclass "", "" # And a scope resource - scope_res = stub 'scope_resource', :virtual? => true, :exported? => false, :tags => [] + scope_res = stub 'scope_resource', :virtual? => true, :exported? => false, :tags => [], :builtin? => true, :type => "eh", :title => "bee" config.topscope.resource = scope_res args = AST::ASTArray.new( @@ -348,7 +347,7 @@ class TestScope < Test::Unit::TestCase :children => [nameobj("arg")] ) - # Create a top-level component + # Create a top-level define parser.newdefine "one", :arguments => [%w{arg}], :code => AST::ASTArray.new( :children => [ @@ -356,41 +355,26 @@ class TestScope < Test::Unit::TestCase ] ) - # And a component that calls it - parser.newdefine "two", :arguments => [%w{arg}], - :code => AST::ASTArray.new( - :children => [ - resourcedef("one", "ptest", {"arg" => varref("arg")}) - ] - ) - - # And then a third component that calls the second - parser.newdefine "three", :arguments => [%w{arg}], - :code => AST::ASTArray.new( - :children => [ - resourcedef("two", "yay", {"arg" => varref("arg")}) - ] - ) - - # lastly, create an object that calls our third component - obj = resourcedef("three", "boo", {"arg" => "parentfoo"}) + # create a resource that calls our third define + obj = resourcedef("one", "boo", {"arg" => "parentfoo"}) - # And mark it as exported - obj.exported = true + # And mark it as virtual + obj.virtual = true # And then evaluate it - obj.evaluate :scope => config.topscope + obj.evaluate config.topscope # And run the loop. config.send(:evaluate_generators) %w{File}.each do |type| - objects = config.resources.find_all { |r| r.type == type and r.exported } + objects = config.resources.find_all { |r| r.type == type and r.virtual } - assert(!objects.empty?, "Did not get an exported %s" % type) + assert(objects.empty?, "Virtual define got evaluated") end 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. diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 2a4ba0220..982ddfec4 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -15,6 +15,8 @@ class TestSnippets < Test::Unit::TestCase def setup super @file = Puppet::Type.type(:file) + Facter.stubs(:to_hash).returns({}) + Facter.stubs(:value).returns("whatever") end def self.snippetdir @@ -422,6 +424,11 @@ class TestSnippets < Test::Unit::TestCase 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") diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 36bb68a77..1a08ecbae 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -5,7 +5,7 @@ module PuppetTest::ParserTesting include PuppetTest AST = Puppet::Parser::AST - Compile = Puppet::Parser::Compile + Compiler = Puppet::Parser::Compiler # A fake class that we can use for testing evaluation. class FakeAST @@ -41,10 +41,10 @@ module PuppetTest::ParserTesting ) end - def mkcompile(parser = nil) + def mkcompiler(parser = nil) parser ||= mkparser node = mknode - return Compile.new(node, parser) + return Compiler.new(node, parser) end def mknode(name = nil) @@ -64,15 +64,15 @@ module PuppetTest::ParserTesting def mkscope(hash = {}) hash[:parser] ||= mkparser - compile ||= mkcompile(hash[:parser]) - compile.topscope.source = (hash[:parser].findclass("", "") || hash[:parser].newclass("")) + compiler ||= mkcompiler(hash[:parser]) + compiler.topscope.source = (hash[:parser].findclass("", "") || hash[:parser].newclass("")) - unless compile.topscope.source + unless compiler.topscope.source raise "Could not find source for scope" end # Make the 'main' stuff - compile.send(:evaluate_main) - compile.topscope + compiler.send(:evaluate_main) + compiler.topscope end def classobj(name, hash = {}) diff --git a/test/lib/puppettest/support/resources.rb b/test/lib/puppettest/support/resources.rb index 384f61c33..255c55569 100755 --- a/test/lib/puppettest/support/resources.rb +++ b/test/lib/puppettest/support/resources.rb @@ -18,7 +18,7 @@ module PuppetTest::Support::Resources if resource.is_a?(String) resource = tree_resource(resource) end - config.add_edge!(comp, resource) + config.add_edge(comp, resource) config.add_resource resource unless config.resource(resource.ref) end return comp diff --git a/test/other/transactions.rb b/test/other/transactions.rb index 79971a28b..105698da1 100755 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -348,12 +348,12 @@ class TestTransactions < Test::Unit::TestCase fcomp = Puppet::Type.type(:component).create(:name => "file") config.add_resource fcomp config.add_resource file - config.add_edge!(fcomp, file) + config.add_edge(fcomp, file) ecomp = Puppet::Type.type(:component).create(:name => "exec") config.add_resource ecomp config.add_resource exec - config.add_edge!(ecomp, exec) + config.add_edge(ecomp, exec) # 'subscribe' expects an array of arrays #component[:require] = [[file.class.name,file.name]] @@ -828,10 +828,10 @@ class TestTransactions < Test::Unit::TestCase c = trigger.new(:c) nope = Puppet::Relationship.new(a, b) yep = Puppet::Relationship.new(a, c, {:callback => :refresh}) - graph.add_edge!(nope) + graph.add_edge(nope) # And a triggering one. - graph.add_edge!(yep) + graph.add_edge(yep) # Create our transaction trans = Puppet::Transaction.new(graph) diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 6a044687e..6c5587ddd 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -708,7 +708,7 @@ class TestType < Test::Unit::TestCase res = type.create(hash) config.add_resource res if parent - config.add_edge!(parent, res) + config.add_edge(parent, res) end res end @@ -741,7 +741,7 @@ class TestType < Test::Unit::TestCase newcomp = Puppet::Type.newcomponent :type => "yay", :name => "Good[bad]" config.add_resource newcomp - config.add_edge! comp, newcomp + config.add_edge comp, newcomp exec = mk.call(6, :parent => newcomp) assert_equal("//Good[bad]/Exec[exec6]", exec.path) end diff --git a/test/ral/types/basic.rb b/test/ral/types/basic.rb index 7bbadc5bc..3c5faeee0 100755 --- a/test/ral/types/basic.rb +++ b/test/ral/types/basic.rb @@ -36,8 +36,8 @@ class TestBasic < Test::Unit::TestCase ) } @config = mk_catalog(@component, @configfile, @command) - @config.add_edge! @component, @configfile - @config.add_edge! @component, @command + @config.add_edge @component, @configfile + @config.add_edge @component, @command end def teardown |