From c003e805bea98f6d0be62c0938ccad4f4a7e4ce0 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Sun, 27 Jul 2014 10:34:22 -0700 Subject: add helpers for formula tests --- Library/Homebrew/cmd/test.rb | 3 +++ Library/Homebrew/formula_assertions.rb | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Library/Homebrew/formula_assertions.rb (limited to 'Library') 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 -- cgit v1.2.3