2014-07-27 10:34:22 -07:00
|
|
|
module Homebrew
|
|
|
|
module Assertions
|
2017-06-25 13:04:36 +01:00
|
|
|
require "test/unit/assertions"
|
2016-01-19 15:42:37 +01:00
|
|
|
include ::Test::Unit::Assertions
|
2014-07-27 10:34:22 -07:00
|
|
|
|
|
|
|
# Returns the output of running cmd, and asserts the exit status
|
2015-08-03 13:09:07 +01:00
|
|
|
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}`
|
2017-06-10 20:12:55 +03:00
|
|
|
assert_equal result, $CHILD_STATUS.exitstatus
|
2014-07-27 10:34:22 -07:00
|
|
|
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
|
2015-08-03 13:09:07 +01:00
|
|
|
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
|
2017-06-10 20:12:55 +03:00
|
|
|
assert_equal result, $CHILD_STATUS.exitstatus unless result.nil?
|
2015-01-19 10:20:49 +01:00
|
|
|
output
|
2014-07-27 10:34:22 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|