Skip to content

Commit 36a7b29

Browse files
committed
Merge branch 'pull-126'
2 parents 15266d9 + 69248df commit 36a7b29

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

lib/puppet/parser/functions/validate_cmd.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'puppet/util/execution'
2+
13
module Puppet::Parser::Functions
24
newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args|
35
Perform validation of a string with an external command.
@@ -28,14 +30,18 @@ module Puppet::Parser::Functions
2830

2931
# Test content in a temporary file
3032
tmpfile = Tempfile.new("validate_cmd")
31-
tmpfile.write(content)
32-
tmpfile.close
33-
output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null`
34-
r = $?
35-
File.delete(tmpfile.path)
36-
if output
37-
msg += "\nOutput is:\n#{output}"
33+
begin
34+
tmpfile.write(content)
35+
if Puppet::Util::Execution.respond_to?('execute')
36+
Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
37+
else
38+
Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
39+
end
40+
rescue Puppet::ExecutionFailure => detail
41+
msg += "\n#{detail}"
42+
raise Puppet::ParseError, msg
43+
ensure
44+
tmpfile.unlink
3845
end
39-
raise Puppet::ParseError, (msg) unless r == 0
4046
end
4147
end

spec/unit/puppet/parser/functions/validate_cmd_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
describe "Test output message" do
7676
it "validate_cmd('whatever', 'kthnksbye') should fail" do
77-
expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.*not found/
77+
expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
7878
end
7979
end
8080
end

0 commit comments

Comments
 (0)