Class: Homebrew::DevCmd::Test Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::Test
- 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
- #args ⇒ Homebrew::DevCmd::Test::Args private
- #run ⇒ void private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::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 |
#run ⇒ void
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.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'dev-cmd/test.rb', line 34 def run Utils::GemSetup.install_bundler_gems!(groups: ["formula_test"], setup_path: false) require "formula_assertions" require "formula_free_port" require "utils/fork" optional_prefix_var_dirs = %w[var/cache var/log var/run] 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| next Dependable::PRUNE if dependency.installed? next if dependency.test? && dependent == f next Dependable::PRUNE unless dependency.required? end unless missing_test_deps.empty? outdated_test_deps, missing_test_deps = missing_test_deps.partition do |dependency| dependency.to_formula.any_version_installed? end if missing_test_deps.present? ofail "#{f.full_name} is missing test dependencies: #{missing_test_deps.join(" ")}\n" \ "Install with `brew install #{missing_test_deps.join(" ")}`." end if outdated_test_deps.present? ofail "#{f.full_name} has outdated test dependencies: #{outdated_test_deps.join(" ")}\n" \ "Upgrade them with `brew upgrade #{outdated_test_deps.join(" ")}`." end next end oh1 "Testing #{f.full_name}" env = ENV.to_hash begin download_queue = DownloadQueue.new begin f.enqueue_resources_and_patches(download_queue:, test: true) download_queue.fetch raise "Failed to fetch test resources." if download_queue.failed_downloads.any? ensure download_queue.shutdown end exec_args = Sandbox.ruby_command("test.rb", f.path, *args.) exec_args << "--HEAD" if f.head? Mktemp.new("#{f.name}-test", retain: args.keep_tmp?).run(chdir: false) do |staging| testpath = staging.tmpdir raise "Test path is unexpectedly unset." if testpath.nil? ENV["HOMEBREW_TEST_PATH"] = testpath.to_s Sandbox.run_or_fork( *exec_args, step: "testing #{f.full_name}", warn_without_sandbox: false, retain_tmp: args.keep_tmp?, debug: args.debug?, ) do |sandbox| 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/homebrew/locks") sandbox.deny_read_home optional_prefix_var_dirs.each do |dir| sandbox.allow_write_path_if_exists HOMEBREW_PREFIX/dir end sandbox.deny_all_network unless f.class.network_access_allowed?(:test) sandbox.allow_network path: testpath, type: :subpath end # Preserve the parent's test directory for interactive debugging. rescue Exception # rubocop:disable Lint/RescueException staging.retain! if args.debug? raise end # Rescue any possible exception types. 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 |