summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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