Class: Homebrew::DevCmd::Test Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/test.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/test.rbi

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

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Test::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/test.rbi', line 10

def args; end

#runvoid

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.

This method returns an undefined value.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'dev-cmd/test.rb', line 33

def run
  Homebrew.install_bundler_gems!(groups: ["formula_test"], setup_path: false)

  require "formula_assertions"
  require "formula_free_port"
  require "utils/fork"

  args.named.to_resolved_formulae.each do |f|
    # Cannot test uninstalled formulae
    unless f.latest_version_installed?
      ofail "Testing requires the latest version of #{f.full_name}"
      next
    end

    # Cannot test formulae without a test method
    unless f.test_defined?
      ofail "#{f.full_name} defines no test"
      next
    end

    # Don't test unlinked formulae
    if !args.force? && !f.keg_only? && !f.linked?
      ofail "#{f.full_name} is not linked"
      next
    end

    # Don't test formulae missing test dependencies
    missing_test_deps = f.recursive_dependencies do |dependent, dependency|
      Dependency.prune if dependency.installed?
      next if dependency.test? && dependent == f

      Dependency.prune unless dependency.required?
    end.map(&:to_s)
    unless missing_test_deps.empty?
      ofail "#{f.full_name} is missing test dependencies: #{missing_test_deps.join(" ")}"
      next
    end

    oh1 "Testing #{f.full_name}"

    env = ENV.to_hash

    begin
      exec_args = HOMEBREW_RUBY_EXEC_ARGS + %W[
        --
        #{HOMEBREW_LIBRARY_PATH}/test.rb
        #{f.path}
      ].concat(args.options_only)

      exec_args << "--HEAD" if f.head?

      if Sandbox.available?
        sandbox = Sandbox.new
        f.logs.mkpath
        sandbox.record_log(f.logs/"test.sandbox.log")
        sandbox.allow_write_temp_and_cache
        sandbox.allow_write_log(f)
        sandbox.allow_write_xcode
        sandbox.allow_write_path(HOMEBREW_PREFIX/"var/cache")
        sandbox.allow_write_path(HOMEBREW_PREFIX/"var/homebrew/locks")
        sandbox.allow_write_path(HOMEBREW_PREFIX/"var/log")
        sandbox.allow_write_path(HOMEBREW_PREFIX/"var/run")
        sandbox.deny_all_network unless f.class.network_access_allowed?(:test)
        sandbox.run(*exec_args)
      else
        Utils.safe_fork do
          exec(*exec_args)
        end
      end
    rescue Exception => e # rubocop:disable Lint/RescueException
      retry if retry_test?(f)

      require "utils/backtrace"
      ofail "#{f.full_name}: failed"
      $stderr.puts e, Utils::Backtrace.clean(e)
    ensure
      ENV.replace(env)
    end
  end
end