diff --git a/Library/Homebrew/test/global_spec.rb b/Library/Homebrew/test/global_spec.rb index 9a7450abd8f8d..a28374ef21a46 100644 --- a/Library/Homebrew/test/global_spec.rb +++ b/Library/Homebrew/test/global_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe Homebrew, :integration_test do - it "does not invoke `require \"formula\"` at startup" do - expect { brew "verify-formula-undefined" } + it "does not require slow dependencies at startup" do + expect { brew "verify-undefined" } .to not_to_output.to_stdout .and not_to_output.to_stderr .and be_a_success diff --git a/Library/Homebrew/test/support/helper/cmd/brew-verify-formula-undefined.rb b/Library/Homebrew/test/support/helper/cmd/brew-verify-formula-undefined.rb deleted file mode 100755 index f2c73f27b47b6..0000000000000 --- a/Library/Homebrew/test/support/helper/cmd/brew-verify-formula-undefined.rb +++ /dev/null @@ -1,23 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -require "cli/parser" - -module Homebrew - module Cmd - class VerifyFormulaUndefined < AbstractCommand - end - end -end - -parser = Homebrew::CLI::Parser.new(Homebrew::Cmd::VerifyFormulaUndefined) do - usage_banner <<~EOS - `verify-formula-undefined` - - Verifies that `require "formula"` has not been performed at startup. - EOS -end - -parser.parse - -Homebrew.failed = defined?(Formula) && Formula.respond_to?(:[]) diff --git a/Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb b/Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb new file mode 100755 index 0000000000000..1ff079737c28e --- /dev/null +++ b/Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb @@ -0,0 +1,40 @@ +# typed: strict +# frozen_string_literal: true + +require "cli/parser" + +UNDEFINED_CONSTANTS = %w[ + Cask::Cask + Formula + Formulary + Homebrew::API + Tap +].freeze + +module Homebrew + module Cmd + class VerifyUndefined < AbstractCommand + end + end +end + +parser = Homebrew::CLI::Parser.new(Homebrew::Cmd::VerifyUndefined) do + usage_banner <<~EOS + `verify-undefined` + + Verifies that the following constants have not been defined + at startup to make sure that startup times stay consistent. + + Contants: + #{UNDEFINED_CONSTANTS.join("\n")} + EOS +end + +parser.parse + +UNDEFINED_CONSTANTS.each do |constant_name| + Object.const_get(constant_name) + ofail "#{constant_name} should not be defined at startup" +rescue NameError + # We expect this to error as it should not be defined. +end