Module: Homebrew::Assertions Private

Includes:
Context, Minitest::Assertions
Defined in:
formula_assertions.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions available in formula test blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

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

Instance Attribute Details

#assertionsObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



17
18
19
# File 'formula_assertions.rb', line 17

def assertions
  @assertions ||= 0
end

Instance Method Details

#assert_false(act, msg = nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



55
56
57
58
# File 'formula_assertions.rb', line 55

def assert_false(act, msg = nil)
  odisabled "assert_false", "assert(!...) or assert_equal(false, ...)"
  assert_equal(false, act, msg)
end

#assert_true(act, msg = nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



50
51
52
53
# File 'formula_assertions.rb', line 50

def assert_true(act, msg = nil)
  odisabled "assert_true", "assert(...) or assert_equal(true, ...)"
  assert_equal(true, act, msg)
end

#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.



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'formula_assertions.rb', line 75

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 Minitest::Assertion
  puts output if verbose?
  raise
end

#shell_output(cmd, result = 0) ⇒ Object

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



62
63
64
65
66
67
68
69
70
# File 'formula_assertions.rb', line 62

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