Enable in tests only via ENV

This commit is contained in:
Douglas Eichelberger 2025-09-14 11:31:41 -07:00
parent 8d542100a8
commit 1cfee5a1d3
No known key found for this signature in database
GPG Key ID: F90193CBD547EB81
3 changed files with 55 additions and 73 deletions

View File

@ -249,6 +249,7 @@ module Homebrew
ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if args.generic? ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if args.generic?
ENV["HOMEBREW_TEST_ONLINE"] = "1" if args.online? ENV["HOMEBREW_TEST_ONLINE"] = "1" if args.online?
ENV["HOMEBREW_SORBET_RUNTIME"] = "1" ENV["HOMEBREW_SORBET_RUNTIME"] = "1"
ENV["HOMEBREW_SORBET_RECURSIVE"] = "1"
ENV["USER"] ||= system_command!("id", args: ["-nu"]).stdout.chomp ENV["USER"] ||= system_command!("id", args: ["-nu"]).stdout.chomp

View File

@ -471,6 +471,11 @@ module Homebrew
"of macOS. This is useful in development on new macOS versions.", "of macOS. This is useful in development on new macOS versions.",
boolean: true, boolean: true,
}, },
HOMEBREW_SORBET_RECURSIVE: {
description: "If set along with `$HOMEBREW_SORBET_RUNTIME`, enable recursive typechecking using Sorbet. " \
"Auomatically enabled when running tests.",
boolean: true,
},
HOMEBREW_SORBET_RUNTIME: { HOMEBREW_SORBET_RUNTIME: {
description: "If set, enable runtime typechecking using Sorbet. " \ description: "If set, enable runtime typechecking using Sorbet. " \
"Set by default for `$HOMEBREW_DEVELOPER` or when running some developer commands.", "Set by default for `$HOMEBREW_DEVELOPER` or when running some developer commands.",

View File

@ -10,6 +10,55 @@ require "extend/module"
# There are mechanisms to achieve a middle ground (`default_checked_level`). # There are mechanisms to achieve a middle ground (`default_checked_level`).
if ENV["HOMEBREW_SORBET_RUNTIME"] if ENV["HOMEBREW_SORBET_RUNTIME"]
T::Configuration.enable_final_checks_on_hooks T::Configuration.enable_final_checks_on_hooks
if ENV["HOMEBREW_SORBET_RECURSIVE"] == "1"
module T
module Types
class FixedArray < Base
def valid?(obj) = recursively_valid?(obj)
end
class FixedHash < Base
def valid?(obj) = recursively_valid?(obj)
end
class Intersection < Base
def valid?(obj) = recursively_valid?(obj)
end
class TypedArray < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class TypedEnumerable < Base
def valid?(obj) = recursively_valid?(obj)
end
class TypedEnumeratorChain < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class TypedEnumeratorLazy < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class TypedHash < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class TypedRange < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class TypedSet < TypedEnumerable
def valid?(obj) = recursively_valid?(obj)
end
class Union < Base
def valid?(obj) = recursively_valid?(obj)
end
end
end
end
else else
# Redefine `T.let`, etc. to make the `checked` parameter default to `false` rather than `true`. # Redefine `T.let`, etc. to make the `checked` parameter default to `false` rather than `true`.
# @private # @private
@ -47,76 +96,3 @@ else
T::Configuration.call_validation_error_handler = ->(signature, opts) {} T::Configuration.call_validation_error_handler = ->(signature, opts) {}
T::Configuration.inline_type_error_handler = ->(error, opts) {} T::Configuration.inline_type_error_handler = ->(error, opts) {}
end end
# TODO: only do this in specs
module T
module Types
class FixedArray < Base
def valid?(obj)
recursively_valid?(obj)
end
end
class FixedHash < Base
def valid?(obj)
recursively_valid?(obj)
end
end
class Intersection < Base
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedArray < TypedEnumerable
# overrides Base
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedEnumerable < Base
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedEnumeratorChain < TypedEnumerable
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedEnumeratorLazy < TypedEnumerable
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedHash < TypedEnumerable
# overrides Base
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedRange < TypedEnumerable
def valid?(obj)
recursively_valid?(obj)
end
end
class TypedSet < TypedEnumerable
def valid?(obj)
recursively_valid?(obj)
end
end
class Union < Base
def valid?(obj)
recursively_valid?(obj)
end
end
end
end