brew/Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb
apainintheneck f6a6979711 Verify more constants are not loaded at startup
Loading different constants can be tricky with all the requires in
Homebrew so we want to strengthen the existing checks to make
sure that things are not getting required when there is a performance
penalty. This expands the existing check to include more constants
beyond `Formula` that we don't expect to be defined and that pull
in a lot of other dependencies.
2024-08-14 19:08:31 -07:00

41 lines
792 B
Ruby
Executable File

# 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