Module: Homebrew::Assertions Private
- Extended by:
- T::Helpers
- Includes:
- Context, Minitest::Assertions, Utils::Output::Mixin
- 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
- #assertions ⇒ Integer private
Instance Method Summary collapse
-
#pipe_output(cmd, input = nil, result = nil) ⇒ String
Returns the output of running the cmd with the optional input and optionally asserts the exit status.
-
#shell_output(cmd, result = 0) ⇒ String
Returns the output of running cmd and asserts the exit status.
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from Context
current, current=, #debug?, #deferred_environment_expansion?, #quiet?, #verbose?, #with_context
Instance Attribute Details
#assertions ⇒ Integer
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.
24 25 26 |
# File 'formula_assertions.rb', line 24 def assertions @assertions ||= T.let(0, T.nilable(Integer)) end |
Instance Method Details
#pipe_output(cmd, input = nil, result = nil) ⇒ String
Returns the output of running the cmd with the optional input and optionally asserts the exit status.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'formula_assertions.rb', line 52 def pipe_output(cmd, input = nil, result = nil) ohai cmd.to_s assert_path_exists cmd, "Pathname '#{cmd}' does not exist!" if cmd.is_a?(Pathname) 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) ⇒ String
Returns the output of running cmd and asserts the exit status.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'formula_assertions.rb', line 32 def shell_output(cmd, result = 0) ohai cmd.to_s assert_path_exists cmd, "Pathname '#{cmd}' does not exist!" if cmd.is_a?(Pathname) output = if cmd.is_a?(Pathname) Utils.popen_read_text("/bin/sh", "-c", 'exec "$1"', "shell_output", cmd..to_s, err: :err) else Utils.popen_read_text("/bin/sh", "-c", cmd, err: :err) end assert_equal result, $CHILD_STATUS.exitstatus output rescue Minitest::Assertion puts output if verbose? raise end |