Module: Homebrew::Assertions Private

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

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

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.



15
16
17
# File 'formula_assertions.rb', line 15

def assertions
  @assertions ||= 0
end

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.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'formula_assertions.rb', line 34

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.



21
22
23
24
25
26
27
28
29
# File 'formula_assertions.rb', line 21

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