Module: Homebrew::Assertions Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper functions available in formula test blocks.

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

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.


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'Library/Homebrew/formula_assertions.rb', line 28

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 verbose?
  raise
end

#shell_output(cmd, result = 0) ⇒ Object

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


15
16
17
18
19
20
21
22
23
# File 'Library/Homebrew/formula_assertions.rb', line 15

def shell_output(cmd, result = 0)
  ohai cmd
  output = `#{cmd}`
  assert_equal result, $CHILD_STATUS.exitstatus
  output
rescue Test::Unit::AssertionFailedError
  puts output if verbose?
  raise
end