File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,17 @@ module Puppet::Parser::Functions
4
4
EOS
5
5
) do |arguments |
6
6
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
9
16
10
- path = arguments [ 0 ]
11
- return File . dirname ( path )
17
+ return File . dirname ( arguments [ 0 ] )
12
18
end
13
19
end
14
20
Original file line number Diff line number Diff line change 12
12
expect { scope . function_dirname ( [ ] ) } . to ( raise_error ( Puppet ::ParseError ) )
13
13
end
14
14
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
+
15
19
it "should return dirname for an absolute path" do
16
20
result = scope . function_dirname ( [ '/path/to/a/file.ext' ] )
17
21
expect ( result ) . to ( eq ( '/path/to/a' ) )
21
25
result = scope . function_dirname ( [ 'path/to/a/file.ext' ] )
22
26
expect ( result ) . to ( eq ( 'path/to/a' ) )
23
27
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
24
38
end
You can’t perform that action at this time.
0 commit comments