diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-07-28 19:13:54 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-01 11:15:29 +1000 |
| commit | ef68967f2b72e609a9d69e53771a61fd9f522149 (patch) | |
| tree | b9e8baa5a45d31f03fa4fae83cb0160a71957dd9 /test/language | |
| parent | 17e62b1ec806815abea909291df1e591a825c375 (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-x | test/language/ast.rb | 5 | ||||
| -rwxr-xr-x | test/language/snippets.rb | 4 |
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 =~ /^\./ |
