From 8b793c6ab388ed606ac0ff550ca98920c22226f2 Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Mon, 19 Jan 2015 10:20:49 +0100 Subject: [PATCH] pipe_output optional result assertion added Closes Homebrew/homebrew#36024. Signed-off-by: Mike McQuaid --- Library/Homebrew/formula_assertions.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index ea12ce001a..bdcf0aef22 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -31,14 +31,17 @@ module Homebrew output end - # Returns the output of running the cmd, with the optional input - def pipe_output(cmd, input=nil) + # Returns the output of running the cmd with the optional input, and + # optionally asserts the exit status + def pipe_output(cmd, input=nil, result=nil) ohai cmd - IO.popen(cmd, "w+") do |pipe| + output = IO.popen(cmd, "w+") do |pipe| pipe.write(input) unless input.nil? pipe.close_write pipe.read end + assert_equal result, $?.exitstatus unless result.nil? + output end end end