diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 04:49:56 +0000 |
| commit | 9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61 (patch) | |
| tree | e41fbeb90e4050ea2af6d37e7b443cf9f84be162 /test/language | |
| parent | be711d357857f5e6d4a28a22bd60dd89e9e136c0 (diff) | |
Not downcasing facts any longer, closing #210 (although not using the patch from mpalmer, since I had not noticed the patch was there). Also, making all nodes, classes, and definitions case insensitive, closing #344. Finally, I added case insensitivity to the language in general, which should preserve backwards compatibility and probably makes the most sense in the long run anyway.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1964 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/language')
| -rwxr-xr-x | test/language/ast.rb | 21 | ||||
| -rwxr-xr-x | test/language/ast/casestatement.rb | 67 | ||||
| -rwxr-xr-x | test/language/ast/selector.rb | 53 | ||||
| -rwxr-xr-x | test/language/interpreter.rb | 30 | ||||
| -rwxr-xr-x | test/language/node.rb | 4 |
5 files changed, 152 insertions, 23 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb index 3fb6f5c0d..ffec7e66a 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -16,26 +16,7 @@ class TestAST < Test::Unit::TestCase include PuppetTest::RailsTesting include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - - # A fake class that we can use for testing evaluation. - class FakeAST - attr_writer :evaluate - - def evaluate(*args) - return @evaluate - end - - def initialize(val = nil) - if val - @evaluate = val - end - end - - def safeevaluate(*args) - evaluate() - end - end - + if defined? ActiveRecord # Verify that our collection stuff works. def test_collection diff --git a/test/language/ast/casestatement.rb b/test/language/ast/casestatement.rb new file mode 100755 index 000000000..493474909 --- /dev/null +++ b/test/language/ast/casestatement.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2006-12-22. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppettest/parsertesting' + +class TestCaseStatement < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + AST = Puppet::Parser::AST + + class ActiveAST < FakeAST + def self.clear + $evaluated = [] + end + def evaluate + $evaluated ||= [] + $evaluated << @evaluate + end + end + + def test_evaluate + ast = nil + scope = mkscope + param = nameobj("MyParam") + + hash = { + "myparam" => ActiveAST.new("lower"), + "MyParam" => ActiveAST.new("upper"), + true => ActiveAST.new(true) + } + options = ["myparam", "MyParam"].collect do |p| + AST::CaseOpt.new(:value => FakeAST.new(p), :statements => hash[p]) + end + assert_nothing_raised do + ast = AST::CaseStatement.new(:test => param, :options => options) + end + + # Start out case-sensitive + Puppet[:casesensitive] = true + + result = nil + assert_nothing_raised do + result = ast.evaluate :scope => scope + end + assert(result, "did not get valid result") + assert_equal(["upper"], $evaluated, "Did not match case-sensitively") + assert(! hash["myparam"].evaluated?, "lower value was evaluated even though it did not match") + + # Now try it case-insensitive + Puppet[:casesensitive] = false + $evaluated.clear + hash["MyParam"].reset + assert_nothing_raised do + result = ast.evaluate :scope => scope + end + assert(result, "did not get valid result") + assert_equal(["lower"], result, "Did not match case-insensitively") + assert(! hash["MyParam"].evaluated?, "upper value was evaluated even though it did not match") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/language/ast/selector.rb b/test/language/ast/selector.rb new file mode 100755 index 000000000..343134348 --- /dev/null +++ b/test/language/ast/selector.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby +# +# Created by Luke A. Kanies on 2006-12-22. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +require 'puppettest/parsertesting' + +class TestSelector < Test::Unit::TestCase + include PuppetTest + include PuppetTest::ParserTesting + AST = Puppet::Parser::AST + + def test_evaluate + sel = nil + scope = mkscope + param = nameobj("MyParam") + + hash = { + "myparam" => FakeAST.new("lower"), + "MyParam" => FakeAST.new("upper") + } + values = ["myparam", "MyParam"].collect do |p| + AST::ResourceParam.new(:param => FakeAST.new(p), :value => hash[p]) + end + assert_nothing_raised do + sel = AST::Selector.new(:param => param, :values => values) + end + + # Start out case-sensitive + Puppet[:casesensitive] = true + + result = nil + assert_nothing_raised do + result = sel.evaluate :scope => scope + end + assert_equal("upper", result, "Did not match case-sensitively") + assert(! hash["myparam"].evaluated?, "lower value was evaluated even though it did not match") + + # Now try it case-insensitive + Puppet[:casesensitive] = false + hash["MyParam"].reset + assert_nothing_raised do + result = sel.evaluate :scope => scope + end + assert_equal("lower", result, "Did not match case-insensitively") + assert(! hash["MyParam"].evaluated?, "upper value was evaluated even though it did not match") + end +end + +# $Id$
\ No newline at end of file diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb index a19bec288..e82461d1b 100755 --- a/test/language/interpreter.rb +++ b/test/language/interpreter.rb @@ -610,7 +610,35 @@ class TestInterpreter < Test::Unit::TestCase end assert(klass, "Did not return class with no code") assert_nil(interp.findclass("", "nocode3").code) - + end + + # Make sure class, node, and define methods are case-insensitive + def test_structure_case_insensitivity + interp = mkinterp + + result = nil + assert_nothing_raised do + result = interp.newclass "Yayness" + end + assert_equal(result, interp.findclass("", "yayNess")) + + assert_nothing_raised do + result = interp.newdefine "FunTest" + end + assert_equal(result, interp.finddefine("", "fUntEst"), + "%s was not matched" % "fUntEst") + + assert_nothing_raised do + result = interp.newnode("MyNode").shift + end + assert_equal(result, interp.nodesearch("mYnOde"), + "mYnOde was not matched") + + assert_nothing_raised do + result = interp.newnode("YayTest.Domain.Com").shift + end + assert_equal(result, interp.nodesearch("yaYtEst.domAin.cOm"), + "yaYtEst.domAin.cOm was not matched") end # Now make sure we get appropriate behaviour with parent class conflicts. diff --git a/test/language/node.rb b/test/language/node.rb index 3f5ff5561..ccdc77fda 100755 --- a/test/language/node.rb +++ b/test/language/node.rb @@ -58,8 +58,8 @@ class TestParser < Test::Unit::TestCase # 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) + assert(interp.nodesearch(name), + "Could not find node %s" % name.inspect) end end |
