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 | |
| parent | 17e62b1ec806815abea909291df1e591a825c375 (diff) | |
| download | puppet-ef68967f2b72e609a9d69e53771a61fd9f522149.tar.gz puppet-ef68967f2b72e609a9d69e53771a61fd9f522149.tar.xz puppet-ef68967f2b72e609a9d69e53771a61fd9f522149.zip | |
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')
| -rw-r--r-- | test/data/snippets/ifexpression.pp | 12 | ||||
| -rw-r--r-- | test/data/snippets/ifexpression.rb | 6 | ||||
| -rwxr-xr-x | test/language/ast.rb | 5 | ||||
| -rwxr-xr-x | test/language/snippets.rb | 4 |
4 files changed, 19 insertions, 8 deletions
diff --git a/test/data/snippets/ifexpression.pp b/test/data/snippets/ifexpression.pp new file mode 100644 index 000000000..29a637291 --- /dev/null +++ b/test/data/snippets/ifexpression.pp @@ -0,0 +1,12 @@ +$one = 1 +$two = 2 + +if ($one < $two) and (($two < 3) or ($two == 2)) { + notice("True!") +} + +if "test regex" =~ /(.*) regex/ { + file { + "/tmp/${1}iftest": ensure => file, mode => 0755 + } +} diff --git a/test/data/snippets/ifexpression.rb b/test/data/snippets/ifexpression.rb deleted file mode 100644 index eea3b855b..000000000 --- a/test/data/snippets/ifexpression.rb +++ /dev/null @@ -1,6 +0,0 @@ -$one = 1 -$two = 2 - -if ($one < $two) and (($two < 3) or ($two == 2)) { - notice("True!") -} 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 =~ /^\./ |
