diff options
| author | Luke Kanies <luke@madstop.com> | 2007-08-20 19:09:26 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-08-20 19:09:26 -0500 |
| commit | 2a4e1011dbc244754f434f7eb97f3d41463e5cd4 (patch) | |
| tree | 584fe59adee0d6057d41093d4c349eb7635de2bf /test/language/ast | |
| parent | 6467c21e15b8a28e627d1395f76fe8f42ee77d70 (diff) | |
| download | puppet-2a4e1011dbc244754f434f7eb97f3d41463e5cd4.tar.gz puppet-2a4e1011dbc244754f434f7eb97f3d41463e5cd4.tar.xz puppet-2a4e1011dbc244754f434f7eb97f3d41463e5cd4.zip | |
All language tests now pass. I expect there are other failures elsewhere, but I want to commit this before delving into them. My method for fixing the tests was to do as little as possible, keeping the tests as bad or as good as they were before I started. Mostly this was about changing references to the interpreter into references to the parser (since that is where the new* methods are now for ast containers) and then dealing with the new config object and its relationship to scopes.
Diffstat (limited to 'test/language/ast')
| -rwxr-xr-x | test/language/ast/component.rb | 36 | ||||
| -rwxr-xr-x | test/language/ast/hostclass.rb | 33 | ||||
| -rwxr-xr-x | test/language/ast/resourceref.rb | 18 |
3 files changed, 52 insertions, 35 deletions
diff --git a/test/language/ast/component.rb b/test/language/ast/component.rb index 13cf60857..cf0cce976 100755 --- a/test/language/ast/component.rb +++ b/test/language/ast/component.rb @@ -16,8 +16,8 @@ class TestASTComponent < Test::Unit::TestCase include PuppetTest::ResourceTesting AST = Puppet::Parser::AST - def test_component - parser, scope, source = mkclassframing + def test_initialize + parser = mkparser # Create a new definition klass = parser.newdefine "yayness", @@ -35,27 +35,41 @@ class TestASTComponent < Test::Unit::TestCase [:random, "random"].each do |var| assert(! klass.validattr?(var), "%s was considered valid" % var.inspect) end + + end + + def test_evaluate + parser = mkparser + config = mkconfig + 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"))] + ) + # Now call it a couple of times # First try it without a required param - assert_raise(Puppet::ParseError) do - klass.evaluate(:scope => scope, + assert_raise(Puppet::ParseError, "Did not fail when a required parameter was not provided") do + klass.evaluate_resource(:scope => scope, :name => "bad", :arguments => {"owner" => "nobody"} ) end # And make sure it didn't create the file - assert_nil(scope.findresource("File[/tmp/bad]"), + assert_nil(config.findresource("File[/tmp/bad]"), "Made file with invalid params") assert_nothing_raised do - klass.evaluate(:scope => scope, + klass.evaluate_resource(:scope => scope, :title => "first", :arguments => {"mode" => "755"} ) end - firstobj = scope.findresource("File[/tmp/first]") + firstobj = config.findresource("File[/tmp/first]") assert(firstobj, "Did not create /tmp/first obj") assert_equal("file", firstobj.type) @@ -65,7 +79,7 @@ class TestASTComponent < Test::Unit::TestCase # Make sure we can't evaluate it with the same args assert_raise(Puppet::ParseError) do - klass.evaluate(:scope => scope, + klass.evaluate_resource(:scope => scope, :title => "first", :arguments => {"mode" => "755"} ) @@ -73,13 +87,13 @@ class TestASTComponent < Test::Unit::TestCase # Now create another with different args assert_nothing_raised do - klass.evaluate(:scope => scope, + klass.evaluate_resource(:scope => scope, :title => "second", :arguments => {"mode" => "755", "owner" => "daemon"} ) end - secondobj = scope.findresource("File[/tmp/second]") + secondobj = config.findresource("File[/tmp/second]") assert(secondobj, "Did not create /tmp/second obj") assert_equal("file", secondobj.type) @@ -110,7 +124,7 @@ class TestASTComponent < Test::Unit::TestCase end args[:scope] = scope assert_nothing_raised("Could not evaluate definition with %s" % hash.inspect) do - klass.evaluate(args) + klass.evaluate_resource(args) end name = hash[:name] || hash[:title] diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb index 051bee36c..f093504ec 100755 --- a/test/language/ast/hostclass.rb +++ b/test/language/ast/hostclass.rb @@ -17,10 +17,11 @@ class TestASTHostClass < Test::Unit::TestCase AST = Puppet::Parser::AST def test_hostclass - interp, scope, source = mkclassframing + scope = mkscope + parser = scope.configuration.parser # Create the class we're testing, first with no parent - klass = interp.newclass "first", + klass = parser.newclass "first", :code => AST::ASTArray.new( :children => [resourcedef("file", "/tmp", "owner" => "nobody", "mode" => "755")] @@ -43,13 +44,13 @@ class TestASTHostClass < Test::Unit::TestCase assert_equal("755", tmp[:mode]) # Now create a couple more classes. - newbase = interp.newclass "newbase", + newbase = parser.newclass "newbase", :code => AST::ASTArray.new( :children => [resourcedef("file", "/tmp/other", "owner" => "nobody", "mode" => "644")] ) - newsub = interp.newclass "newsub", + newsub = parser.newclass "newsub", :parent => "newbase", :code => AST::ASTArray.new( :children => [resourcedef("file", "/tmp/yay", @@ -60,7 +61,7 @@ class TestASTHostClass < Test::Unit::TestCase ) # Override a different variable in the top scope. - moresub = interp.newclass "moresub", + moresub = parser.newclass "moresub", :parent => "newbase", :code => AST::ASTArray.new( :children => [resourceoverride("file", "/tmp/other", @@ -92,19 +93,20 @@ class TestASTHostClass < Test::Unit::TestCase # Make sure that classes set their namespaces to themselves. This # way they start looking for definitions in their own namespace. def test_hostclass_namespace - interp, scope, source = mkclassframing + scope = mkscope + parser = scope.configuration.parser # Create a new class klass = nil assert_nothing_raised do - klass = interp.newclass "funtest" + klass = parser.newclass "funtest" end # Now define a definition in that namespace define = nil assert_nothing_raised do - define = interp.newdefine "funtest::mydefine" + define = parser.newdefine "funtest::mydefine" end assert_equal("funtest", klass.namespace, @@ -127,17 +129,18 @@ class TestASTHostClass < Test::Unit::TestCase # At the same time, make sure definitions in the parent class can be # found within the subclass (#517). def test_parent_scope_from_parentclass - interp = mkinterp + scope = mkscope + parser = scope.configuration.parser - interp.newclass("base") - fun = interp.newdefine("base::fun") - interp.newclass("middle", :parent => "base") - interp.newclass("sub", :parent => "middle") - scope = mkscope :interp => interp + 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.evalclasses("sub") + ret = scope.configuration.evaluate_classes(["sub"]) end subscope = scope.class_scope(scope.findclass("sub")) diff --git a/test/language/ast/resourceref.rb b/test/language/ast/resourceref.rb index 7b7889dc1..a3d6775a2 100755 --- a/test/language/ast/resourceref.rb +++ b/test/language/ast/resourceref.rb @@ -19,13 +19,13 @@ class TestASTResourceRef < Test::Unit::TestCase def setup super - @interp = mkinterp - @scope = mkscope :interp => @interp + @scope = mkscope + @parser = @scope.configuration.parser end def test_evaluate - @interp.newdefine "one::two" - @interp.newdefine "one-two" + @parser.newdefine "one::two" + @parser.newdefine "one-two" [%w{file /tmp/yay}, %w{one::two three}, %w{one-two three}].each do |type, title| ref = newref(type, title) @@ -41,9 +41,9 @@ class TestASTResourceRef < Test::Unit::TestCase # Related to #706, make sure resource references correctly translate to qualified types. def test_scoped_references - @interp.newdefine "one" - @interp.newdefine "one::two" - @interp.newdefine "three" + @parser.newdefine "one" + @parser.newdefine "one::two" + @parser.newdefine "three" twoscope = @scope.newscope(:type => "one", :namespace => "one") assert(twoscope.finddefine("two"), "Could not find 'two' definition") title = "title" @@ -70,8 +70,8 @@ class TestASTResourceRef < Test::Unit::TestCase end # Now run the same tests, but with the classes - @interp.newclass "four" - @interp.newclass "one::five" + @parser.newclass "four" + @parser.newclass "one::five" # First try an unqualified type assert_equal("four", newref("class", "four").evaluate(:scope => twoscope).title, |
