summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:39:12 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:39:12 +0000
commite952029322eab81580e9c05f5310d78068d2f9bf (patch)
tree7130e03d66682bb99be96f82bdc49a51945ac567 /test
parent66546610ceb5f14d7dce1da9286def4b1497bd60 (diff)
downloadpuppet-e952029322eab81580e9c05f5310d78068d2f9bf.tar.gz
puppet-e952029322eab81580e9c05f5310d78068d2f9bf.tar.xz
puppet-e952029322eab81580e9c05f5310d78068d2f9bf.zip
Adding #541. There is now a "generate" function.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2299 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-xtest/language/functions.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 941f56c2c..ad6aa2761 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -473,6 +473,53 @@ class TestLangFunctions < Test::Unit::TestCase
val = scope.function_file([file1, file3])
end
end
+
+ def test_generate
+ command = tempfile
+ sh = %x{which sh}
+ File.open(command, "w") do |f|
+ f.puts %{#!#{sh}
+ if [ -n "$1" ]; then
+ echo "yay-$1"
+ else
+ echo yay
+ fi
+ }
+ end
+ File.chmod(0755, command)
+ assert_equal("yay\n", %x{#{command}}, "command did not work")
+ assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work")
+
+ interp = mkinterp
+ scope = mkscope(:interp => interp)
+
+ val = nil
+ assert_nothing_raised("Could not call generator with no args") do
+ val = scope.function_generate([command])
+ end
+ assert_equal("yay\n", val, "generator returned wrong results")
+
+ assert_nothing_raised("Could not call generator with args") do
+ val = scope.function_generate([command, "foo"])
+ end
+ assert_equal("yay-foo\n", val, "generator returned wrong results")
+
+ assert_raise(Puppet::ParseError, "Did not fail with an unqualified path") do
+ val = scope.function_generate([File.basename(command), "foo"])
+ end
+
+ assert_raise(Puppet::ParseError, "Did not fail when command failed") do
+ val = scope.function_generate([%x{which touch}.chomp, "/this/dir/does/not/exist"])
+ end
+
+ fake = File.join(File.dirname(command), "..")
+ dir = File.dirname(command)
+ dirname = File.basename(dir)
+ bad = File.join(dir, "..", dirname, File.basename(command))
+ assert_raise(Puppet::ParseError, "Did not fail when command failed") do
+ val = scope.function_generate([bad])
+ end
+ end
end
# $Id$