File tree Expand file tree Collapse file tree
lib/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,11 +4,17 @@ module Puppet::Parser::Functions
44 EOS
55 ) do |arguments |
66
7- raise ( Puppet ::ParseError , "dirname(): Wrong number of arguments " +
8- "given (#{ arguments . size } for 1)" ) if arguments . size < 1
7+ if arguments . size < 1 then
8+ raise ( Puppet ::ParseError , "dirname(): No arguments given" )
9+ end
10+ if arguments . size > 1 then
11+ raise ( Puppet ::ParseError , "dirname(): Too many arguments given (#{ arguments . size } )" )
12+ end
13+ unless arguments [ 0 ] . is_a? ( String )
14+ raise ( Puppet ::ParseError , 'dirname(): Requires string as argument' )
15+ end
916
10- path = arguments [ 0 ]
11- return File . dirname ( path )
17+ return File . dirname ( arguments [ 0 ] )
1218 end
1319end
1420
Original file line number Diff line number Diff line change 1212 expect { scope . function_dirname ( [ ] ) } . to ( raise_error ( Puppet ::ParseError ) )
1313 end
1414
15+ it "should raise a ParseError if there is more than 1 argument" do
16+ expect { scope . function_dirname ( [ 'a' , 'b' ] ) } . to ( raise_error ( Puppet ::ParseError ) )
17+ end
18+
1519 it "should return dirname for an absolute path" do
1620 result = scope . function_dirname ( [ '/path/to/a/file.ext' ] )
1721 expect ( result ) . to ( eq ( '/path/to/a' ) )
2125 result = scope . function_dirname ( [ 'path/to/a/file.ext' ] )
2226 expect ( result ) . to ( eq ( 'path/to/a' ) )
2327 end
28+
29+ it "should complain about hash argument" do
30+ expect { scope . function_dirname ( [ { } ] ) } . to ( raise_error ( Puppet ::ParseError ) )
31+ end
32+ it "should complain about list argument" do
33+ expect { scope . function_dirname ( [ [ ] ] ) } . to ( raise_error ( Puppet ::ParseError ) )
34+ end
35+ it "should complain about numeric argument" do
36+ expect { scope . function_dirname ( [ 2112 ] ) } . to ( raise_error ( Puppet ::ParseError ) )
37+ end
2438end
You can’t perform that action at this time.
0 commit comments