diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-04 18:24:24 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-04 18:24:24 +0000 |
| commit | 28cee40689440388994a4768bd301ae32c8ecc05 (patch) | |
| tree | c865ab44f4c9247052cf83de16ffc8ebe8b15e54 /test/language/node.rb | |
| parent | e0e291332bd4676962a28c7b220ae5c5e9651c0a (diff) | |
| download | puppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.gz puppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.xz puppet-28cee40689440388994a4768bd301ae32c8ecc05.zip | |
Merging the changes from the override-refactor branch. This is a significant rewrite of the parser, but it has little affect on the rest of the code tree.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1726 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/language/node.rb')
| -rw-r--r-- | test/language/node.rb | 72 |
1 files changed, 27 insertions, 45 deletions
diff --git a/test/language/node.rb b/test/language/node.rb index 791c44874..251e4c4aa 100644 --- a/test/language/node.rb +++ b/test/language/node.rb @@ -8,7 +8,6 @@ class TestParser < Test::Unit::TestCase def setup super Puppet[:parseonly] = true - @parser = Puppet::Parser::Parser.new() end def test_simple_hostname @@ -41,48 +40,40 @@ class TestParser < Test::Unit::TestCase unless hostnames.is_a?(Array) hostnames = [ hostnames ] end + interp = nil assert_nothing_raised { - @parser.string = "node #{hostnames.join(", ")} { }" + interp = mkinterp :Code => "node #{hostnames.join(", ")} { }" } # Strip quotes hostnames.map! { |s| s.sub(/^'(.*)'$/, "\\1") } - ast = nil + + # parse assert_nothing_raised { - ast = @parser.parse + interp.send(:parsefiles) } - # Verify that the AST has the expected structure - # and that the leaves have the right hostnames in them - assert_kind_of(AST::ASTArray, ast) - assert_equal(1, ast.children.size) - nodedef = ast.children[0] - assert_kind_of(AST::NodeDef, nodedef) - assert_kind_of(AST::ASTArray, nodedef.names) - assert_equal(hostnames.size, nodedef.names.children.size) - hostnames.size.times do |i| - hostnode = nodedef.names.children[i] - assert_kind_of(AST::HostName, hostnode) - assert_equal(hostnames[i], hostnode.value) + + # Now make sure we can look up each of the names + hostnames.each do |name| + assert(interp.nodesearch_code(name), + "Could not find node %s" % name) end end def check_nonparseable(hostname) - assert_nothing_raised { - @parser.string = "node #{hostname} { }" - } - - assert_raise(Puppet::DevError, Puppet::ParseError) { - @parser.parse + interp = nil + assert_raise(Puppet::DevError, Puppet::ParseError, "#{hostname} passed") { + interp = mkinterp :Code => "node #{hostname} { }" + interp.send(:parsefiles) } end # Make sure we can find default nodes if there's no other entry def test_default_node Puppet[:parseonly] = false - @parser = Puppet::Parser::Parser.new() fileA = tempfile() fileB = tempfile() - @parser.string = %{ + code = %{ node mynode { file { "#{fileA}": ensure => file } } @@ -91,34 +82,25 @@ node default { file { "#{fileB}": ensure => file } } } - - # First make sure it parses - ast = nil + interp = nil assert_nothing_raised { - ast = @parser.parse - } - - args = { - :ast => ast, - :facts => {}, - :names => ["mynode"] + interp = mkinterp :Code => code } - # Make sure we get a config for "mynode" - trans = nil + # First make sure it parses assert_nothing_raised { - trans = Puppet::Parser::Scope.new.evaluate(args) + interp.send(:parsefiles) } - assert(trans, "Did not get config for mynode") + # Make sure we find our normal node + assert(interp.nodesearch("mynode"), + "Did not find normal node") - args[:names] = ["othernode"] - # Now make sure the default node is used - trans = nil - assert_nothing_raised { - trans = Puppet::Parser::Scope.new.evaluate(args) - } + # Now look for the default node + default = interp.nodesearch("someother") + assert(default, + "Did not find default node") - assert(trans, "Did not get config for default node") + assert_equal("default", default.fqname) end end |
