2014-07-27 10:34:22 -07:00
|
|
|
module Homebrew
|
|
|
|
module Assertions
|
2015-01-13 12:33:50 -05:00
|
|
|
if defined?(Gem)
|
|
|
|
begin
|
|
|
|
gem "minitest", "< 5.0.0"
|
|
|
|
rescue Gem::LoadError
|
|
|
|
require "test/unit/assertions"
|
|
|
|
else
|
|
|
|
require "minitest/unit"
|
|
|
|
require "test/unit/assertions"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
require "test/unit/assertions"
|
|
|
|
end
|
|
|
|
|
|
|
|
if defined?(MiniTest::Assertion)
|
|
|
|
FailedAssertion = MiniTest::Assertion
|
|
|
|
elsif defined?(Minitest::Assertion)
|
|
|
|
FailedAssertion = Minitest::Assertion
|
|
|
|
else
|
|
|
|
FailedAssertion = Test::Unit::AssertionFailedError
|
|
|
|
end
|
|
|
|
|
2014-07-27 10:34:22 -07:00
|
|
|
include Test::Unit::Assertions
|
|
|
|
|
|
|
|
# Returns the output of running cmd, and asserts the exit status
|
|
|
|
def shell_output(cmd, result=0)
|
2014-07-29 21:59:49 -07:00
|
|
|
ohai cmd
|
2014-07-27 10:34:22 -07:00
|
|
|
output = `#{cmd}`
|
|
|
|
assert_equal result, $?.exitstatus
|
|
|
|
output
|
|
|
|
end
|
|
|
|
|
2015-01-19 10:20:49 +01:00
|
|
|
# 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)
|
2014-07-29 21:59:49 -07:00
|
|
|
ohai cmd
|
2015-01-19 10:20:49 +01:00
|
|
|
output = IO.popen(cmd, "w+") do |pipe|
|
2014-07-27 10:34:22 -07:00
|
|
|
pipe.write(input) unless input.nil?
|
|
|
|
pipe.close_write
|
|
|
|
pipe.read
|
|
|
|
end
|
2015-01-19 10:20:49 +01:00
|
|
|
assert_equal result, $?.exitstatus unless result.nil?
|
|
|
|
output
|
2014-07-27 10:34:22 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|