diff options
author | Travis Fields <travis@puppetlabs.com> | 2014-10-28 15:27:24 -0700 |
---|---|---|
committer | Travis Fields <travis@puppetlabs.com> | 2014-10-28 15:27:24 -0700 |
commit | 51f1d574d92cf686ac79e57e69d8aff31caf2925 (patch) | |
tree | c955c144ec2386607f2ad7ac69edb1bcf44df320 | |
parent | 759cbdec886bebb859d8def9323c139faf99c024 (diff) |
Fix testcases for Future Parser and resolve issue with values_at in assuming that it was dealing with a string
-rw-r--r-- | lib/puppet/parser/functions/values_at.rb | 1 | ||||
-rwxr-xr-x | spec/acceptance/abs_spec.rb | 4 | ||||
-rwxr-xr-x | spec/acceptance/any2array_spec.rb | 4 | ||||
-rwxr-xr-x | spec/acceptance/bool2num_spec.rb | 12 | ||||
-rwxr-xr-x | spec/acceptance/count_spec.rb | 4 | ||||
-rwxr-xr-x | spec/acceptance/ensure_packages_spec.rb | 2 | ||||
-rwxr-xr-x | spec/acceptance/merge_spec.rb | 4 | ||||
-rwxr-xr-x | spec/acceptance/type_spec.rb | 2 | ||||
-rwxr-xr-x | spec/acceptance/validate_cmd_spec.rb | 2 | ||||
-rwxr-xr-x | spec/acceptance/values_spec.rb | 6 | ||||
-rwxr-xr-x | spec/acceptance/zip_spec.rb | 28 | ||||
-rwxr-xr-x | spec/spec_helper_acceptance.rb | 12 |
12 files changed, 55 insertions, 26 deletions
diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index d3e69d9..f350f53 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -49,6 +49,7 @@ Would return ['a','c','d']. indices_list = [] indices.each do |i| + i = i.to_s if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/) start = m[1].to_i stop = m[3].to_i diff --git a/spec/acceptance/abs_spec.rb b/spec/acceptance/abs_spec.rb index 8e05642..6e41e2f 100755 --- a/spec/acceptance/abs_spec.rb +++ b/spec/acceptance/abs_spec.rb @@ -7,7 +7,7 @@ describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati pp = <<-EOS $input = '-34.56' $output = abs($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -19,7 +19,7 @@ describe 'abs function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati pp = <<-EOS $input = -34.56 $output = abs($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/any2array_spec.rb b/spec/acceptance/any2array_spec.rb index 467d6af..18ea4cd 100755 --- a/spec/acceptance/any2array_spec.rb +++ b/spec/acceptance/any2array_spec.rb @@ -25,7 +25,7 @@ describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/) end end @@ -42,7 +42,7 @@ describe 'any2array function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/Notice: Output: testarray/) + expect(r.stdout).to match(/Notice: Output: (\[|)test(,\s|)array(\]|)/) end end end diff --git a/spec/acceptance/bool2num_spec.rb b/spec/acceptance/bool2num_spec.rb index 7a70311..52ff75b 100755 --- a/spec/acceptance/bool2num_spec.rb +++ b/spec/acceptance/bool2num_spec.rb @@ -4,11 +4,11 @@ require 'spec_helper_acceptance' describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do ['false', 'f', '0', 'n', 'no'].each do |bool| - it 'should convert a given boolean, #{bool}, to 0' do + it "should convert a given boolean, #{bool}, to 0" do pp = <<-EOS - $input = #{bool} + $input = "#{bool}" $output = bool2num($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -18,11 +18,11 @@ describe 'bool2num function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op end ['true', 't', '1', 'y', 'yes'].each do |bool| - it 'should convert a given boolean, #{bool}, to 1' do + it "should convert a given boolean, #{bool}, to 1" do pp = <<-EOS - $input = #{bool} + $input = "#{bool}" $output = bool2num($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/count_spec.rb b/spec/acceptance/count_spec.rb index 51a40ba..fe7ca9d 100755 --- a/spec/acceptance/count_spec.rb +++ b/spec/acceptance/count_spec.rb @@ -7,7 +7,7 @@ describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera pp = <<-EOS $input = [1,2,3,4] $output = count($input) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| @@ -19,7 +19,7 @@ describe 'count function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera pp = <<-EOS $input = [1,1,1,2] $output = count($input, 1) - notify { $output: } + notify { "$output": } EOS apply_manifest(pp, :catch_failures => true) do |r| diff --git a/spec/acceptance/ensure_packages_spec.rb b/spec/acceptance/ensure_packages_spec.rb index 12da0cd..53c1035 100755 --- a/spec/acceptance/ensure_packages_spec.rb +++ b/spec/acceptance/ensure_packages_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'ensure_packages function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'ensure_packages function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || fact('operatingsystem') != 'windows') do describe 'success' do it 'ensure_packages a package' do apply_manifest('package { "rake": ensure => absent, provider => "gem", }') diff --git a/spec/acceptance/merge_spec.rb b/spec/acceptance/merge_spec.rb index a60e784..227b994 100755 --- a/spec/acceptance/merge_spec.rb +++ b/spec/acceptance/merge_spec.rb @@ -14,9 +14,9 @@ describe 'merge function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera EOS apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/merge\[one\] is "1"/) + expect(r.stdout).to match(/merge\[one\] is ("1"|1)/) expect(r.stdout).to match(/merge\[two\] is "dos"/) - expect(r.stdout).to match(/merge\[three\] is {"five"=>"5"}/) + expect(r.stdout).to match(/merge\[three\] is {"five"=>("5"|5)}/) end end end diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb index 0043aad..15fa217 100755 --- a/spec/acceptance/type_spec.rb +++ b/spec/acceptance/type_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'type function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do +describe 'type function', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) || !(is_future_parser_enabled?)) do describe 'success' do it 'types arrays' do pp = <<-EOS diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb index 385676d..a899a1d 100755 --- a/spec/acceptance/validate_cmd_spec.rb +++ b/spec/acceptance/validate_cmd_spec.rb @@ -37,7 +37,7 @@ describe 'validate_cmd function', :unless => UNSUPPORTED_PLATFORMS.include?(fact } else { $two = '/bin/aoeu' } - validate_cmd($one,$two,"aoeu is dvorak) + validate_cmd($one,$two,"aoeu is dvorak") EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/aoeu is dvorak/) diff --git a/spec/acceptance/values_spec.rb b/spec/acceptance/values_spec.rb index 7ef956e..a2eff32 100755 --- a/spec/acceptance/values_spec.rb +++ b/spec/acceptance/values_spec.rb @@ -13,8 +13,12 @@ describe 'values function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('oper $output = values($arg) notice(inline_template('<%= @output.sort.inspect %>')) EOS + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 2, 3\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/) + end - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "2", "3"\]/) end end describe 'failure' do diff --git a/spec/acceptance/zip_spec.rb b/spec/acceptance/zip_spec.rb index 0e924e8..139079e 100755 --- a/spec/acceptance/zip_spec.rb +++ b/spec/acceptance/zip_spec.rb @@ -11,8 +11,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/) + end end it 'zips two arrays of numbers & bools together' do pp = <<-EOS @@ -21,8 +24,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/) + end end it 'zips two arrays of numbers together and flattens them' do # XXX This only tests the argument `true`, even though the following are valid: @@ -35,8 +41,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two,true) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/) + end end it 'handles unmatched length' do # XXX Is this expected behavior? @@ -46,8 +55,11 @@ describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operati $output = zip($one,$two) notice(inline_template('<%= @output.inspect %>')) EOS - - expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/) + if is_future_parser_enabled? + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/) + else + expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/) + end end end describe 'failure' do diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e9ccc68..e2f6b76 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -26,10 +26,15 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do + if ENV['FUTURE_PARSER'] == 'true' + default[:default_apply_opts] ||= {} + default[:default_apply_opts].merge!({:parser => 'future'}) + end hosts.each do |host| if host['platform'] !~ /windows/i copy_root_module_to(host, :source => proj_root, :module_name => 'stdlib') end + end hosts.each do |host| if host['platform'] =~ /windows/i @@ -38,3 +43,10 @@ RSpec.configure do |c| end end end + +def is_future_parser_enabled? + if default[:default_apply_opts] + return default[:default_apply_opts][:parser] == 'future' + end + return false +end |