diff --git a/Library/Homebrew/cmd/test.rb b/Library/Homebrew/cmd/test.rb index f1b9967f44..b47a85ed47 100644 --- a/Library/Homebrew/cmd/test.rb +++ b/Library/Homebrew/cmd/test.rb @@ -25,6 +25,8 @@ module Homebrew FailedAssertion = Test::Unit::AssertionFailedError end + require "formula_assertions" + def test raise FormulaUnspecifiedError if ARGV.named.empty? @@ -47,6 +49,7 @@ module Homebrew puts "Testing #{f.name}" f.extend(Test::Unit::Assertions) + f.extend(Homebrew::Assertions) begin # tests can also return false to indicate failure diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb new file mode 100644 index 0000000000..845c5480d9 --- /dev/null +++ b/Library/Homebrew/formula_assertions.rb @@ -0,0 +1,23 @@ +require 'test/unit/assertions' + +module Homebrew + module Assertions + include Test::Unit::Assertions + + # Returns the output of running cmd, and asserts the exit status + def shell_output(cmd, result=0) + output = `#{cmd}` + assert_equal result, $?.exitstatus + output + end + + # Returns the output of running the cmd, with the optional input + def pipe_output(cmd, input=nil) + IO.popen(cmd, "w+") do |pipe| + pipe.write(input) unless input.nil? + pipe.close_write + pipe.read + end + end + end +end