summaryrefslogtreecommitdiffstats
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
parenta6dc7f2e22bf548240064a68ae2ee04309f7de24 (diff)
downloadpuppet-8b60619f5857569c2971237c80cf214cb8e71b3f.tar.gz
puppet-8b60619f5857569c2971237c80cf214cb8e71b3f.tar.xz
puppet-8b60619f5857569c2971237c80cf214cb8e71b3f.zip
adding some tests for the template function
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1341 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/functions.rb2
-rwxr-xr-xtest/language/functions.rb79
-rw-r--r--test/puppettest.rb5
3 files changed, 84 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 3a9f0cd35..cec7c02c5 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -142,7 +142,7 @@ module Functions
raise Puppet::ParseError, "Could not interpret template %s: %s" %
[file, detail]
end
- end.join("\n")
+ end.join("")
end
end
end
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$
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 5c5973689..f601a3660 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -901,12 +901,15 @@ module ParserTesting
end
def varobj(name, value)
+ unless value.is_a? AST
+ value = stringobj(value)
+ end
assert_nothing_raised("Could not create %s code" % name) {
return AST::VarDef.new(
:file => tempfile(),
:line => rand(100),
:name => nameobj(name),
- :value => stringobj(value)
+ :value => value
)
}
end