summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-10-21 17:24:09 -0700
committerNick Lewis <nick@puppetlabs.com>2011-04-12 12:47:31 -0700
commit31f8e660c8f4c0ec01f140322cf7c585144a0888 (patch)
tree115f2b3d2b31c005b4b0de81b74d9195fa6ca495 /test
parentd5dc3036eda210f318160e2442f7b65e0995ee23 (diff)
downloadpuppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.tar.gz
puppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.tar.xz
puppet-31f8e660c8f4c0ec01f140322cf7c585144a0888.zip
Refactor en route to #5027 -- remove usestring parameter from lookupvar
The usestring parameter to lookupvar was objectionable for several reasons; first, it performed a function orthogonal to the main purpose of the method, second its default was the least common value, and third it was causing other code to work for reasons that were not obvious (extlookup). This refactor breaks the value-transforming function out into a seperate method which allows the user to specify the value to be used in lieu of :undef and removes the parameter. The function, Scope#undef_as(default,exp) is written so that it can be used in user code (templates, functions, etc.) if needed. This refactor will introduce a user-visible behaviour change in the case where users were counting on lookupvar to return "" for undefined variables. The best solution is to have them use undef_as, replacing: lookupvar('myvar') with undef_as('',lookupvar('myvar')) (with the option to specify another default value if desired). If this is too objectionable, we could rename the existing lookupvar as raw_lookupvar and define def lookupvar(v) undef_as('',raw_lookupvar(v)) end to restore the present behaviour.
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/functions.rb10
-rwxr-xr-xtest/language/scope.rb23
2 files changed, 10 insertions, 23 deletions
diff --git a/test/language/functions.rb b/test/language/functions.rb
index e882b68f3..84b1b3861 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -382,17 +382,15 @@ class TestLangFunctions < Test::Unit::TestCase
}.each do |string, value|
scope = mkscope
scope.setvar("yayness", string)
- assert_equal(string, scope.lookupvar("yayness", false))
+ assert_equal(string, scope.lookupvar("yayness"))
assert_nothing_raised("An empty string was not a valid variable value") do
ast.evaluate(scope)
end
-
- assert_equal(
- "template #{value}\n", scope.lookupvar("output"),
-
- "#{string.inspect} did not get evaluated correctly")
+ assert_equal(
+ "template #{value}\n", scope.lookupvar("output"),
+ "#{string.inspect} did not get evaluated correctly")
end
end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index c4154dc27..ccc359651 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -42,22 +42,22 @@ class TestScope < Test::Unit::TestCase
# Set a variable in the top and make sure all three can get it
topscope.setvar("first", "topval")
scopes.each do |name, scope|
- assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}")
+ assert_equal("topval", scope.lookupvar("first"), "Could not find var in #{name}")
end
# Now set a var in the midscope and make sure the mid and bottom can see it but not the top
midscope.setvar("second", "midval")
- assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope")
+ assert_equal(:undefined, scopes[:top].lookupvar("second"), "Found child var in top scope")
[:mid, :bot].each do |name|
- assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}")
+ assert_equal("midval", scopes[name].lookupvar("second"), "Could not find var in #{name}")
end
# And set something in the bottom, and make sure we only find it there.
botscope.setvar("third", "botval")
[:top, :mid].each do |name|
- assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope")
+ assert_equal(:undefined, scopes[name].lookupvar("third"), "Found child var in top scope")
end
- assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope")
+ assert_equal("botval", scopes[:bot].lookupvar("third"), "Could not find var in bottom scope")
# Test that the scopes convert to hash structures correctly.
@@ -260,18 +260,7 @@ Host <<||>>"
scope = mkscope
scope.setvar("testing", :undef)
-
-
- assert_equal(
- :undef, scope.lookupvar("testing", false),
-
- "undef was not returned as :undef when not string")
-
-
- assert_equal(
- "", scope.lookupvar("testing", true),
-
- "undef was not returned as '' when string")
+ assert_equal(:undef, scope.lookupvar("testing"), "undef was not returned as :undef")
end
end