summaryrefslogtreecommitdiffstats
path: root/test/language
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-28 19:13:54 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-08-01 11:15:29 +1000
commitef68967f2b72e609a9d69e53771a61fd9f522149 (patch)
treeb9e8baa5a45d31f03fa4fae83cb0160a71957dd9 /test/language
parent17e62b1ec806815abea909291df1e591a825c375 (diff)
Fix #2033 - Allow regexp in if expression
This changeset introduces regexp in if expression with the use of the =~ (match) and !~ (not match) operator. Usage: if $uname =~ /Linux|Debian/ { ... } Moreover this patch creates ephemeral variables ($0 to $9) in the current scope which contains the regex captures: if $uname =~ /(Linux|Debian)/ { notice("this is a $1 system") } Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'test/language')
-rwxr-xr-xtest/language/ast.rb5
-rwxr-xr-xtest/language/snippets.rb4
2 files changed, 7 insertions, 2 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 8c0f31aba..ed11bc16d 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -15,6 +15,7 @@ class TestAST < Test::Unit::TestCase
include PuppetTest::Support::Collection
def test_if
+ scope = mkscope
astif = nil
astelse = nil
fakeelse = FakeAST.new(:else)
@@ -35,14 +36,14 @@ class TestAST < Test::Unit::TestCase
# We initialized it to true, so we should get that first
ret = nil
assert_nothing_raised {
- ret = astif.evaluate("yay")
+ ret = astif.evaluate(scope)
}
assert_equal(:if, ret)
# Now set it to false and check that
faketest.evaluate = false
assert_nothing_raised {
- ret = astif.evaluate("yay")
+ ret = astif.evaluate(scope)
}
assert_equal(:else, ret)
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index 87ad9e770..cfca10e13 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -481,6 +481,10 @@ class TestSnippets < Test::Unit::TestCase
assert_mode_equal(0600, path)
end
+ def snippet_ifexpression
+ assert_file("/tmp/testiftest","if test");
+ end
+
# Iterate across each of the snippets and create a test.
Dir.entries(snippetdir).sort.each { |file|
next if file =~ /^\./