Module: Homebrew::Assertions

Includes:
Test::Unit::Assertions
Defined in:
brew/Library/Homebrew/formula_assertions.rb

Instance Method Summary collapse

Instance Method Details

#pipe_output(cmd, input = nil, result = nil) ⇒ Object

Returns the output of running the cmd with the optional input, and optionally asserts the exit status



19
20
21
22
23
24
25
26
27
28
# File 'brew/Library/Homebrew/formula_assertions.rb', line 19

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
end

#shell_output(cmd, result = 0) ⇒ Object

Returns the output of running cmd, and asserts the exit status



10
11
12
13
14
15
# File 'brew/Library/Homebrew/formula_assertions.rb', line 10

def shell_output(cmd, result = 0)
  ohai cmd
  output = `#{cmd}`
  assert_equal result, $CHILD_STATUS.exitstatus
  output
end