]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
validate_cmd: Use Puppet::Util.execute
authorRaphaël Pinson <raphael.pinson@camptocamp.com>
Tue, 5 Feb 2013 08:01:48 +0000 (09:01 +0100)
committerRaphaël Pinson <raphael.pinson@camptocamp.com>
Wed, 6 Feb 2013 17:03:11 +0000 (18:03 +0100)
lib/puppet/parser/functions/validate_cmd.rb
spec/unit/puppet/parser/functions/validate_cmd_spec.rb

index 00fe1ae2b9ad251f46c5e9a5e64ac961ca6e4a47..4f6a766c0bae6aa4baa93c61a1c611358897165a 100644 (file)
@@ -1,3 +1,5 @@
+require 'puppet/util/execution'
+
 module Puppet::Parser::Functions
   newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args|
     Perform validation of a string with an external command.
@@ -30,15 +32,12 @@ module Puppet::Parser::Functions
     tmpfile = Tempfile.new("validate_cmd")
     begin
       tmpfile.write(content)
-      output = `#{checkscript} #{tmpfile.path} 2>&1 1>/dev/null`
-      r = $?
+      Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
+    rescue Puppet::ExecutionFailure => detail
+      msg += "\n#{detail}"
+      raise Puppet::ParseError, msg
     ensure
-      tmpfile.close
       tmpfile.unlink
     end
-    if output
-      msg += "\nOutput is:\n#{output}"
-    end
-    raise Puppet::ParseError, (msg) unless r == 0
   end
 end
index 0730a591c010de84238059a6cecbbb7bcbda2e0f..69ea7f4960aa00f9acb04430f9029ba44cf46aeb 100644 (file)
@@ -74,7 +74,7 @@ describe Puppet::Parser::Functions.function(:validate_cmd) do
 
     describe "Test output message" do
       it "validate_cmd('whatever', 'kthnksbye') should fail" do
-          expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.*not found/
+          expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
       end
     end
   end