Skip to content

Commit

Permalink
Fix testcases for Future Parser and resolve issue with values_at in a…
Browse files Browse the repository at this point in the history
…ssuming that it was dealing with a string
  • Loading branch information
Travis Fields committed Oct 28, 2014
1 parent 759cbde commit 51f1d57
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/puppet/parser/functions/values_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module Puppet::Parser::Functions
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
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/abs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pp = <<-EOS
$input = '-34.56'
$output = abs($input)
notify { $output: }
notify { "$output": }
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand All @@ -19,7 +19,7 @@
pp = <<-EOS
$input = -34.56
$output = abs($input)
notify { $output: }
notify { "$output": }
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/any2array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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

Expand All @@ -42,7 +42,7 @@
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
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/bool2num_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
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|
Expand All @@ -18,11 +18,11 @@
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|
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pp = <<-EOS
$input = [1,2,3,4]
$output = count($input)
notify { $output: }
notify { "$output": }
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand All @@ -19,7 +19,7 @@
pp = <<-EOS
$input = [1,1,1,2]
$output = count($input, 1)
notify { $output: }
notify { "$output": }
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/ensure_packages_spec.rb
Original file line number Diff line number Diff line change
@@ -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", }')
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/validate_cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
} 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/)
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
$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
Expand Down
28 changes: 20 additions & 8 deletions spec/acceptance/zip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
$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
Expand All @@ -21,8 +24,11 @@
$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:
Expand All @@ -35,8 +41,11 @@
$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?
Expand All @@ -46,8 +55,11 @@
$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
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@

# 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
Expand All @@ -38,3 +43,10 @@
end
end
end

def is_future_parser_enabled?
if default[:default_apply_opts]
return default[:default_apply_opts][:parser] == 'future'
end
return false
end

0 comments on commit 51f1d57

Please sign in to comment.