]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Fix testcases for Future Parser and resolve issue with values_at in assuming that...
authorTravis Fields <travis@puppetlabs.com>
Tue, 28 Oct 2014 22:27:24 +0000 (15:27 -0700)
committerTravis Fields <travis@puppetlabs.com>
Tue, 28 Oct 2014 22:27:24 +0000 (15:27 -0700)
12 files changed:
lib/puppet/parser/functions/values_at.rb
spec/acceptance/abs_spec.rb
spec/acceptance/any2array_spec.rb
spec/acceptance/bool2num_spec.rb
spec/acceptance/count_spec.rb
spec/acceptance/ensure_packages_spec.rb
spec/acceptance/merge_spec.rb
spec/acceptance/type_spec.rb
spec/acceptance/validate_cmd_spec.rb
spec/acceptance/values_spec.rb
spec/acceptance/zip_spec.rb
spec/spec_helper_acceptance.rb

index d3e69d97fc13271a33a56c08d30e78d95eee8ae9..f350f5391bdbd280331c6a7c437f5ecb3079fd89 100644 (file)
@@ -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
index 8e056424ed6f33234b90069e5b985cfb88471b01..6e41e2fde191cebe8ca7b1b5a3b1f01aace297d9 100755 (executable)
@@ -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|
index 467d6afda0317f6f094d414fd2e9cedf7b8c769d..18ea4cd9b03bb055cf7c26648d9d22fa7b9796e2 100755 (executable)
@@ -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
index 7a70311ca7a9b7e023f52a87c07904c4c9bca59e..52ff75bcfa057c1e8a717d86ae0770787a8f43ba 100755 (executable)
@@ -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|
index 51a40ba5c179d777e8637f64e6d55193179af310..fe7ca9dcf1af37fad8d6bf60923a2f9b4a49f9b3 100755 (executable)
@@ -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|
index 12da0cdc238191dc2080caa9bf470513148d75b6..53c10356b6af0a4866afc5ad94ae42a81ddee19e 100755 (executable)
@@ -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", }')
index a60e784ee67ecd223f1f2792cadc7c8fac6bd313..227b99429228f9845dffe2ea7afa8651e4f3c779 100755 (executable)
@@ -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
index 0043aad7cdd492bb468532e1b723a08c127b9cf4..15fa217daa791fdc227605b94347bf4e94456049 100755 (executable)
@@ -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
index 385676d14b066d60f8fb60a9b1a23d5282616783..a899a1d525aedfd45945d21fc7a2da06365df15a 100755 (executable)
@@ -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/)
index 7ef956e0489bb28e74aab099475232308cf0436a..a2eff329d2336bfa53251a18ebf0a782a3b4f569 100755 (executable)
@@ -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
index 0e924e8492f6154c075ee9707d50abd4a8680f07..139079e31abebcb786fda3fecad17a16d31a8f71 100755 (executable)
@@ -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
index e9ccc68fd6569cf211f5bf8fa56135210b828197..e2f6b7643708298c0979c5f8e667c640b4a2d261 100755 (executable)
@@ -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