Skip to content

Commit cfc79e9

Browse files
committed
Merge pull request #344 from cyberious/TestCaseFixes
Fix testcases for Future Parser and resolve issue with values_at in assuming that it was dealing with a string
2 parents 759cbde + 51f1d57 commit cfc79e9

12 files changed

+55
-26
lines changed

lib/puppet/parser/functions/values_at.rb

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module Puppet::Parser::Functions
4949
indices_list = []
5050

5151
indices.each do |i|
52+
i = i.to_s
5253
if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/)
5354
start = m[1].to_i
5455
stop = m[3].to_i

spec/acceptance/abs_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pp = <<-EOS
88
$input = '-34.56'
99
$output = abs($input)
10-
notify { $output: }
10+
notify { "$output": }
1111
EOS
1212

1313
apply_manifest(pp, :catch_failures => true) do |r|
@@ -19,7 +19,7 @@
1919
pp = <<-EOS
2020
$input = -34.56
2121
$output = abs($input)
22-
notify { $output: }
22+
notify { "$output": }
2323
EOS
2424

2525
apply_manifest(pp, :catch_failures => true) do |r|

spec/acceptance/any2array_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
EOS
2626

2727
apply_manifest(pp, :catch_failures => true) do |r|
28-
expect(r.stdout).to match(/Notice: Output: testarray/)
28+
expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
2929
end
3030
end
3131

@@ -42,7 +42,7 @@
4242
EOS
4343

4444
apply_manifest(pp, :catch_failures => true) do |r|
45-
expect(r.stdout).to match(/Notice: Output: testarray/)
45+
expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/)
4646
end
4747
end
4848
end

spec/acceptance/bool2num_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
55
describe 'success' do
66
['false', 'f', '0', 'n', 'no'].each do |bool|
7-
it 'should convert a given boolean, #{bool}, to 0' do
7+
it "should convert a given boolean, #{bool}, to 0" do
88
pp = <<-EOS
9-
$input = #{bool}
9+
$input = "#{bool}"
1010
$output = bool2num($input)
11-
notify { $output: }
11+
notify { "$output": }
1212
EOS
1313

1414
apply_manifest(pp, :catch_failures => true) do |r|
@@ -18,11 +18,11 @@
1818
end
1919

2020
['true', 't', '1', 'y', 'yes'].each do |bool|
21-
it 'should convert a given boolean, #{bool}, to 1' do
21+
it "should convert a given boolean, #{bool}, to 1" do
2222
pp = <<-EOS
23-
$input = #{bool}
23+
$input = "#{bool}"
2424
$output = bool2num($input)
25-
notify { $output: }
25+
notify { "$output": }
2626
EOS
2727

2828
apply_manifest(pp, :catch_failures => true) do |r|

spec/acceptance/count_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pp = <<-EOS
88
$input = [1,2,3,4]
99
$output = count($input)
10-
notify { $output: }
10+
notify { "$output": }
1111
EOS
1212

1313
apply_manifest(pp, :catch_failures => true) do |r|
@@ -19,7 +19,7 @@
1919
pp = <<-EOS
2020
$input = [1,1,1,2]
2121
$output = count($input, 1)
22-
notify { $output: }
22+
notify { "$output": }
2323
EOS
2424

2525
apply_manifest(pp, :catch_failures => true) do |r|

spec/acceptance/ensure_packages_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env ruby -S rspec
22
require 'spec_helper_acceptance'
33

4-
describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('operatingsystem') != 'windows') do
55
describe 'success' do
66
it 'ensure_packages a package' do
77
apply_manifest('package { "rake": ensure => absent, provider => "gem", }')

spec/acceptance/merge_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
EOS
1515

1616
apply_manifest(pp, :catch_failures => true) do |r|
17-
expect(r.stdout).to match(/merge\[one\] is "1"/)
17+
expect(r.stdout).to match(/merge\[one\] is ("1"|1)/)
1818
expect(r.stdout).to match(/merge\[two\] is "dos"/)
19-
expect(r.stdout).to match(/merge\[three\] is {"five"=>"5"}/)
19+
expect(r.stdout).to match(/merge\[three\] is {"five"=>("5"|5)}/)
2020
end
2121
end
2222
end

spec/acceptance/type_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env ruby -S rspec
22
require 'spec_helper_acceptance'
33

4-
describe 'type function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
4+
describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || !(is_future_parser_enabled?)) do
55
describe 'success' do
66
it 'types arrays' do
77
pp = <<-EOS

spec/acceptance/validate_cmd_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
} else {
3838
$two = '/bin/aoeu'
3939
}
40-
validate_cmd($one,$two,"aoeu is dvorak)
40+
validate_cmd($one,$two,"aoeu is dvorak")
4141
EOS
4242

4343
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/)

spec/acceptance/values_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
$output = values($arg)
1414
notice(inline_template('<%= @output.sort.inspect %>'))
1515
EOS
16+
if is_future_parser_enabled?
17+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 2, 3\]/)
18+
else
19+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/)
20+
end
1621

17-
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/)
1822
end
1923
end
2024
describe 'failure' do

spec/acceptance/zip_spec.rb

+20-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
$output = zip($one,$two)
1212
notice(inline_template('<%= @output.inspect %>'))
1313
EOS
14-
15-
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
14+
if is_future_parser_enabled?
15+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/)
16+
else
17+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
18+
end
1619
end
1720
it 'zips two arrays of numbers & bools together' do
1821
pp = <<-EOS
@@ -21,8 +24,11 @@
2124
$output = zip($one,$two)
2225
notice(inline_template('<%= @output.inspect %>'))
2326
EOS
24-
25-
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
27+
if is_future_parser_enabled?
28+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/)
29+
else
30+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
31+
end
2632
end
2733
it 'zips two arrays of numbers together and flattens them' do
2834
# XXX This only tests the argument `true`, even though the following are valid:
@@ -35,8 +41,11 @@
3541
$output = zip($one,$two,true)
3642
notice(inline_template('<%= @output.inspect %>'))
3743
EOS
38-
39-
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
44+
if is_future_parser_enabled?
45+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/)
46+
else
47+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
48+
end
4049
end
4150
it 'handles unmatched length' do
4251
# XXX Is this expected behavior?
@@ -46,8 +55,11 @@
4655
$output = zip($one,$two)
4756
notice(inline_template('<%= @output.inspect %>'))
4857
EOS
49-
50-
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
58+
if is_future_parser_enabled?
59+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/)
60+
else
61+
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
62+
end
5163
end
5264
end
5365
describe 'failure' do

spec/spec_helper_acceptance.rb

+12
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
2626

2727
# Configure all nodes in nodeset
2828
c.before :suite do
29+
if ENV['FUTURE_PARSER'] == 'true'
30+
default[:default_apply_opts] ||= {}
31+
default[:default_apply_opts].merge!({:parser => 'future'})
32+
end
2933
hosts.each do |host|
3034
if host['platform'] !~ /windows/i
3135
copy_root_module_to(host, :source => proj_root, :module_name => 'stdlib')
3236
end
37+
3338
end
3439
hosts.each do |host|
3540
if host['platform'] =~ /windows/i
@@ -38,3 +43,10 @@
3843
end
3944
end
4045
end
46+
47+
def is_future_parser_enabled?
48+
if default[:default_apply_opts]
49+
return default[:default_apply_opts][:parser] == 'future'
50+
end
51+
return false
52+
end

0 commit comments

Comments
 (0)