Skip to content

Commit 6c5f178

Browse files
author
willmeek
authored
Merge pull request #861 from pmcmaw/fix_type3x
(MODULES-6216) - Fix type3x function in stdlib
2 parents ef26708 + 1d55153 commit 6c5f178

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/puppet/parser/functions/type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Puppet::Parser::Functions
1111
unless Puppet::Parser::Functions.autoloader.loaded?(:type3x)
1212
Puppet::Parser::Functions.autoloader.load(:type3x)
1313
end
14-
function_type3x(args + [false])
14+
function_type3x(args)
1515
end
1616
end
1717

lib/puppet/parser/functions/type3x.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ module Puppet::Parser::Functions
1515
* boolean
1616
DOC
1717
) do |args|
18-
raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") if args.empty?
18+
raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1
1919

2020
value = args[0]
2121

2222
klass = value.class
2323

24-
unless [TrueClass, FalseClass, Array, Integer, Integer, Float, Hash, String].include?(klass)
24+
unless [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) # rubocop:disable Lint/UnifiedInteger
2525
raise(Puppet::ParseError, 'type3x(): Unknown type')
2626
end
2727

spec/acceptance/type3x_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper_acceptance'
3+
4+
describe 'type3x function' do
5+
describe 'success' do
6+
{
7+
%{type3x({ 'a' => 'hash' })} => 'Hash',
8+
%{type3x(['array'])} => 'Array',
9+
%{type3x(false)} => 'Boolean',
10+
%{type3x('asdf')} => 'String',
11+
%{type3x(242)} => 'Integer',
12+
%{type3x(3.14)} => 'Float',
13+
}.each do |pp, type|
14+
it "with type #{type}" do
15+
apply_manifest(pp, :catch_failures => true)
16+
end
17+
end
18+
end
19+
20+
describe 'failure' do
21+
pp_fail = <<-MANIFEST
22+
type3x('one','two')
23+
MANIFEST
24+
it 'handles improper number of arguments' do
25+
expect(apply_manifest(pp_fail, :expect_failures => true).stderr).to match(%r{Wrong number of arguments})
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)