summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-27 16:30:09 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-27 16:30:09 +0000
commit4c885b7aa48746b6b946c7b2b0cd0abc50216ecf (patch)
treecde888752d334b42570c702dbd9531d73363b544 /test
parentaad512371967156a39ae422f0a3ca95891f4064d (diff)
downloadpuppet-4c885b7aa48746b6b946c7b2b0cd0abc50216ecf.tar.gz
puppet-4c885b7aa48746b6b946c7b2b0cd0abc50216ecf.tar.xz
puppet-4c885b7aa48746b6b946c7b2b0cd0abc50216ecf.zip
Fixing #517 and more. Classes now support more than one namespace in their search path, parent classes automatically have their namespaces added to subclass namespaces, and (huzzah) there is a "search" function that can be used to add new namespaces into their search path.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2226 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/ast/hostclass.rb19
-rwxr-xr-xtest/language/functions.rb22
-rwxr-xr-xtest/language/scope.rb61
3 files changed, 100 insertions, 2 deletions
diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb
index 64ecc4026..1e2f518f6 100755
--- a/test/language/ast/hostclass.rb
+++ b/test/language/ast/hostclass.rb
@@ -123,11 +123,15 @@ class TestASTHostClass < Test::Unit::TestCase
end
# Make sure that our scope is a subscope of the parentclass's scope.
+ # 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
interp.newclass("base")
- interp.newclass("sub", :parent => "base")
+ fun = interp.newdefine("base::fun")
+ interp.newclass("middle", :parent => "base")
+ interp.newclass("sub", :parent => "middle")
scope = mkscope :interp => interp
ret = nil
@@ -137,10 +141,21 @@ class TestASTHostClass < Test::Unit::TestCase
subscope = scope.class_scope(scope.findclass("sub"))
assert(subscope, "could not find sub scope")
+ mscope = scope.class_scope(scope.findclass("middle"))
+ assert(mscope, "could not find middle scope")
pscope = scope.class_scope(scope.findclass("base"))
assert(pscope, "could not find parent scope")
- assert(pscope == subscope.parent, "parent scope was not set correctly")
+ assert(pscope == mscope.parent, "parent scope of middle was not set correctly")
+ assert(mscope == subscope.parent, "parent scope of sub was not set correctly")
+
+ result = mscope.finddefine("fun")
+ assert(result, "could not find parent-defined definition from middle")
+ assert(fun == result, "found incorrect parent-defined definition from middle")
+
+ result = subscope.finddefine("fun")
+ assert(result, "could not find parent-defined definition from sub")
+ assert(fun == result, "found incorrect parent-defined definition from sub")
end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 7d504cb2f..1484a1312 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -393,6 +393,28 @@ class TestLangFunctions < Test::Unit::TestCase
assert(scope.function_defined([yep]), "valid resource was not considered defined")
assert(! scope.function_defined([nope]), "invalid resource was considered defined")
end
+
+ def test_search
+ interp = mkinterp
+ scope = mkscope(:interp => interp)
+
+ fun = interp.newdefine("fun::test")
+ foo = interp.newdefine("foo::bar")
+
+ search = Puppet::Parser::Functions.function(:search)
+ assert_nothing_raised do
+ scope.function_search(["foo", "fun"])
+ end
+
+ ffun = ffoo = nil
+ assert_nothing_raised do
+ ffun = scope.finddefine("test")
+ ffoo = scope.finddefine('bar')
+ end
+
+ assert(ffun, "Could not find definition in 'fun' namespace")
+ assert(ffoo, "Could not find definition in 'foo' namespace")
+ end
end
# $Id$
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 9b7f1baea..bf89dbba2 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -592,6 +592,67 @@ Host <<||>>"
assert_equal("root", testing["owner"])
end
+
+ def test_namespaces
+ interp, scope, source = mkclassframing
+
+ assert_equal([""], scope.namespaces,
+ "Started out with incorrect namespaces")
+ assert_nothing_raised { scope.add_namespace("fun::test") }
+ assert_equal(["fun::test"], scope.namespaces,
+ "Did not add namespace correctly")
+ assert_nothing_raised { scope.add_namespace("yay::test") }
+ assert_equal(["fun::test", "yay::test"], scope.namespaces,
+ "Did not add extra namespace correctly")
+ end
+
+ def test_findclass_and_finddefine
+ interp = mkinterp
+
+ # Make sure our scope calls the interp findclass method with
+ # the right namespaces
+ scope = mkscope :interp => interp
+
+ interp.metaclass.send(:attr_accessor, :last)
+
+ methods = [:findclass, :finddefine]
+ methods.each do |m|
+ interp.meta_def(m) do |namespace, name|
+ @checked ||= []
+ @checked << [namespace, name]
+
+ # Only return a value on the last call.
+ if @last == namespace
+ ret = @checked.dup
+ @checked.clear
+ return ret
+ else
+ return nil
+ end
+ end
+ end
+
+ test = proc do |should|
+ interp.last = scope.namespaces[-1]
+ methods.each do |method|
+ result = scope.send(method, "testing")
+ assert_equal(should, result,
+ "did not get correct value from %s with namespaces %s" %
+ [method, scope.namespaces.inspect])
+ end
+ end
+
+ # Start with the empty namespace
+ assert_nothing_raised { test.call([["", "testing"]]) }
+
+ # Now add a namespace
+ scope.add_namespace("a")
+ assert_nothing_raised { test.call([["a", "testing"]]) }
+
+ # And another
+ scope.add_namespace("b")
+ assert_nothing_raised { test.call([["a", "testing"], ["b", "testing"]]) }
+ end
end
# $Id$