summaryrefslogtreecommitdiffstats
path: root/test/language
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 23:51:21 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 23:51:21 +0000
commit8b60619f5857569c2971237c80cf214cb8e71b3f (patch)
treea089bce5aeef071736dfb0b5c2d8d2b02d4b7f5e /test/language
parenta6dc7f2e22bf548240064a68ae2ee04309f7de24 (diff)
adding some tests for the template function
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1341 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/language')
-rwxr-xr-xtest/language/functions.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 6b46bfd9e..ee8f33c59 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -88,6 +88,85 @@ class TestLangFunctions < Test::Unit::TestCase
val = func.evaluate(:scope => scope)
end
end
+
+ def test_multipletemplates
+ Dir.mkdir(Puppet[:templatedir])
+ onep = File.join(Puppet[:templatedir], "one")
+ twop = File.join(Puppet[:templatedir], "two")
+
+ File.open(onep, "w") do |f|
+ f.puts "template <%= one %>"
+ end
+
+ File.open(twop, "w") do |f|
+ f.puts "template <%= two %>"
+ end
+ func = nil
+ assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj("one"),
+ stringobj("two")]
+ )
+ )
+ end
+ ast = varobj("output", func)
+
+ scope = Puppet::Parser::Scope.new()
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(:scope => scope)
+ end
+
+ scope.setvar("one", "One")
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(:scope => scope)
+ end
+ scope.setvar("two", "Two")
+ assert_nothing_raised do
+ ast.evaluate(:scope => scope)
+ end
+
+ assert_equal("template One\ntemplate Two\n", scope.lookupvar("output"),
+ "Templates were not handled correctly")
+ end
+
+ # Now make sure we can fully qualify files, and specify just one
+ def test_singletemplates
+ template = tempfile()
+
+ File.open(template, "w") do |f|
+ f.puts "template <%= yayness %>"
+ end
+
+ func = nil
+ assert_nothing_raised do
+ func = Puppet::Parser::AST::Function.new(
+ :name => "template",
+ :ftype => :rvalue,
+ :arguments => AST::ASTArray.new(
+ :children => [stringobj(template)]
+ )
+ )
+ end
+ ast = varobj("output", func)
+
+ scope = Puppet::Parser::Scope.new()
+ assert_raise(Puppet::ParseError) do
+ ast.evaluate(:scope => scope)
+ end
+
+ scope.setvar("yayness", "this is yayness")
+
+ assert_nothing_raised do
+ ast.evaluate(:scope => scope)
+ end
+
+ assert_equal("template this is yayness\n", scope.lookupvar("output"),
+ "Templates were not handled correctly")
+
+ end
end
# $Id$