diff options
| author | Daniel Pittman <daniel@rimspace.net> | 2008-07-22 17:53:06 +1000 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2008-08-01 08:54:05 +1000 |
| commit | 404450a71581f1ac2a13ff9340992e4f999f3091 (patch) | |
| tree | b05f83e245c88a6efe4a8a6d01cf7c16782b8e4c /test/language/scope.rb | |
| parent | 03c76deb60927375e9b35c74a903130930ffddf2 (diff) | |
| download | puppet-404450a71581f1ac2a13ff9340992e4f999f3091.tar.gz puppet-404450a71581f1ac2a13ff9340992e4f999f3091.tar.xz puppet-404450a71581f1ac2a13ff9340992e4f999f3091.zip | |
Add testing for the changes to resolve redmine #1427, where Kernel methods shadow
variables that the puppet template should otherwise see. Specific changes:
* Added testing of the Scope#to_hash method, which returns a hash of name and
value pairs in a scope or, optionally, in the scope and enclosing scopes.
* Use member variables rather than methods in the function tests.
* Fix up tests that fail once we move over to instance variables rather than
methods: Puppet can no longer detect an undefined variable reference, so we
end up failing any test that expected to get a parser error.
* Several tests have manual checks introduced to simulate an end user manually
writing the checks that used to be automatic, and others drop the validation
that parsing fails when a variable is not in scope.
* Added tests for legacy variable lookup and that the shadowing of local
variables by Kernel methods is still in effect.
Signed-off-by: Daniel Pittman <daniel@rimspace.net>
(cherry picked from commit 5c5f315cceadc52203e53883b77bc01c1d7a2e7f)
Diffstat (limited to 'test/language/scope.rb')
| -rwxr-xr-x | test/language/scope.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/language/scope.rb b/test/language/scope.rb index c96581a23..0fa211fc3 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -53,6 +53,34 @@ class TestScope < Test::Unit::TestCase 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") + + + # 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") + + # Check the variable we expect is present. + assert_equal({"first" => "topval"}, topscope.to_hash(), + "topscope returns the expected hash of variables") + + # Now, check that midscope does the right thing in all cases. + assert_equal({"second" => "midval"}, + midscope.to_hash(false), + "midscope non-recursive hash contains only midscope variable") + assert_equal({"first" => "topval", "second" => "midval"}, + midscope.to_hash(true), + "midscope recursive hash contains topscope variable also") + + # 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({"third" => "botval", "first" => "shadowval"}, + botscope.to_hash(false), + "botscope has the right non-recursive hash") + assert_equal({"third" => "botval", "first" => "shadowval", "second" => "midval"}, + botscope.to_hash(true), + "botscope values shadow parent scope values") end def test_lookupvar |
