add helpers for formula tests

This commit is contained in:
Adam Vandenberg 2014-07-27 10:34:22 -07:00
parent f4ae1c9e1b
commit c003e805be
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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