diff options
| author | Adam Vandenberg | 2014-07-27 10:34:22 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2014-08-01 07:58:09 -0700 |
| commit | a87e0daf665c880d1241730b56777a26c4d07230 (patch) | |
| tree | 0014c68f5f410dd7c39ca3236efe52629a91afcb /Library | |
| parent | 1387c8522d72bab8150f2e27510257abadd09911 (diff) | |
| download | homebrew-a87e0daf665c880d1241730b56777a26c4d07230.tar.bz2 | |
add helpers for formula tests
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/test.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/formula_assertions.rb | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/test.rb b/Library/Homebrew/cmd/test.rb index f1b9967f4..b47a85ed4 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 000000000..845c5480d --- /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 |
