brew/Library/Homebrew/formula_assertions.rb
Mike McQuaid 115aafb9eb
formula_assertions: print output on assertion failed.
When doing `brew test --verbose` (as `brew test-bot` does) ensure that
the output is printed when an assertion fails to more easily debug the
test failure.
2020-03-10 09:21:30 +00:00

36 lines
985 B
Ruby

# frozen_string_literal: true
module Homebrew
module Assertions
require "test/unit/assertions"
include ::Test::Unit::Assertions
# Returns the output of running cmd, and asserts the exit status
def shell_output(cmd, result = 0)
ohai cmd
output = `#{cmd}`
assert_equal result, $CHILD_STATUS.exitstatus
output
rescue Test::Unit::AssertionFailedError
puts output if Homebrew.args.verbose?
raise
end
# 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)
ohai cmd
output = IO.popen(cmd, "w+") do |pipe|
pipe.write(input) unless input.nil?
pipe.close_write
pipe.read
end
assert_equal result, $CHILD_STATUS.exitstatus unless result.nil?
output
rescue Test::Unit::AssertionFailedError
puts output if Homebrew.args.verbose?
raise
end
end
end