191 Commits

Author SHA1 Message Date
Mike McQuaid
084ddca27a
Cleanup and fix homebrew-services migration 2025-03-13 15:22:01 +00:00
Mike McQuaid
8adc188992
Import brew alias and brew unalias commands
Import these from the homebrew/aliases tap and deprecate that tap.

This required a little messing around with class/module/constant names
to get `brew tests` and `brew typecheck` to play nicely.

I added also added Sorbet type signatures and integration tests.
2025-02-07 14:31:50 +00:00
Rylan Polster
c023b70e8f
Mirror real installation directory structure for tests 2025-01-23 03:11:59 -05:00
Mike McQuaid
e69124045a
Remove BuildPulse and use CodeCov instead
Now we're successfully sending flaky test results to CodeCov, let's
remove BuildPulse code and docs.
2024-12-24 10:32:55 +00:00
Bo Anderson
46cb9ec947
spec_helper: clarify comment and scope to all OS 2024-10-27 15:45:46 +00:00
Mike McQuaid
92fee908ba
spec_helper: improve parallel test handling.
- Clarify the comment of why we have SimpleCov special logic for
  parallel tests
- use a nicer ParallelTests API for checking which process to output
  the coverage format on
2024-10-26 11:20:37 +01:00
Douglas Eichelberger
2d16333bbc Replace removable constants with overridable methods 2024-10-07 18:33:03 -07:00
Michael Cho
112c692a53
test/spec_helper: require standalone before warnings 2024-09-27 12:48:27 -04:00
Kevin
c3c1528611
Revert "Use cp -c when copying files" 2024-06-17 21:17:10 -07:00
Daiki Mizukami
4edbbfd794
Utils::Cp: Add tests 2024-06-11 20:27:37 +09:00
apainintheneck
56ecd42ebd dev-cmd/tests: skip tests that require core if it's not tapped
There were a few tests which require core to be tapped and fail
if it isn't. This is annoying if someone is trying to contribute
to the project and they're using the JSON API instead of having
the core repo tapped locally.

I'm just skipping these because it's the simplest thing to do.
The tests that failed are mostly rubocop tests so it's fine
if they only run on CI.
2024-05-03 00:32:50 -07:00
Markus Reiter
480e264d9a
Lint Ruby docs. 2024-05-01 11:35:21 +02:00
Issy Long
4c64193b9b
Set HOMEBREW_DEBUG when running brew tests --debug
- This will cause the "debug" gem to be required in `spec_helper.rb`, so we can do interactive debugging.
2024-04-17 23:26:40 +01:00
Issy Long
073e739005
Use the debug gem from portable Ruby
- This is cleaner than vendoring a whole bunch of new gems and pinning `psych`.
- Thanks for the pointer, Bo!
- It doesn't work, though?

```
❯ brew tests --only=migrator --debug
Error: cannot load such file -- debug/debug.so
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/frame_info.rb:16:in `require'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/frame_info.rb:16:in `rescue in <module:DEBUGGER__>'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/frame_info.rb:13:in `<module:DEBUGGER__>'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/frame_info.rb:3:in `<top (required)>'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/session.rb:31:in `require_relative'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug/session.rb:31:in `<top (required)>'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug.rb:3:in `require_relative'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/lib/ruby/gems/3.1.0/gems/debug-1.6.3/lib/debug.rb:3:in `<top (required)>'
/opt/homebrew/Library/Homebrew/dev-cmd/tests.rb:48:in `require'
/opt/homebrew/Library/Homebrew/dev-cmd/tests.rb:48:in `run'
/opt/homebrew/Library/Homebrew/brew.rb:89:in `<main>'
```
2024-04-17 23:26:40 +01:00
Issy Long
f2a64f3808
Fix RuboCop and exclude psych from RBI generation 2024-04-17 22:25:12 +01:00
Issy Long
1daeb5bee0
Set up the debug gem for test debugging
- This processed that we'd requested a debugger, but didn't drop us into
  a debugging console until I
  [stopped the stdin disablement](https://github.com/Homebrew/brew/issues/16708#issuecomment-1953483970).

Usage:

```
❯ git diff
diff --git a/Library/Homebrew/test/migrator_spec.rb b/Library/Homebrew/test/migrator_spec.rb
index 87fadd5e95..db4700810a 100644
--- a/Library/Homebrew/test/migrator_spec.rb
+++ b/Library/Homebrew/test/migrator_spec.rb
@@ -69,6 +69,8 @@ RSpec.describe Migrator do
       tab.source["tap"] = "homebrew/core"
       tab.write

+      binding.break
+
       expect do
         described_class.new(new_formula, "oldname")
       end.to raise_error(Migrator::MigratorDifferentTapsError)

issyl0 at pictor in /opt/homebrew on bye-byebug
❯ brew tests --only=migrator --debug
Randomized with seed 59158
1 process for 1 spec, ~ 1 spec per process
.==> Relinking newname
.==> Unlinking oldname
...==> Moving oldname versions to /private/tmp/homebrew-tests-20240403-85464-3uogqr/cellar/newname
....==> Migrating formula oldname to newname
==> Unlinking oldname
==> Moving oldname versions to /private/tmp/homebrew-tests-20240403-85464-3uogqr/cellar/newname
==> Relinking newname
....[67, 76] in ~/migrator_spec.rb
    67|       tab = Tab.empty
    68|       tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
    69|       tab.source["tap"] = "homebrew/core"
    70|       tab.write
    71|
=>  72|       binding.break
    73|
    74|       expect do
    75|         described_class.new(new_formula, "oldname")
    76|       end.to raise_error(Migrator::MigratorDifferentTapsError)
=>#0    block in <top (required)> (3 levels) at ~/migrator_spec.rb:72
  #1    [C] BasicObject#instance_exec at /opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:263
  # and 68 frames (use `bt' command for all frames)
(rdbg@/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/rspec#85464) p tab
(rdbg@/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/rspec#85464) p    # command(rdbg@/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/rspec#85464) p     # command t    # command ta    # command tab    # command(rdbg@/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/rspec#85464) p tab    # command
=> #<Tab:0x0000000107156be0 @aliases=[], @arch=nil, @built_as_bottle=false, @built_on={"os"=>"Macintosh", "os_version"=>"macOS 14", "cpu_family"=>"arm_firestorm_icestorm"}, @compiler=:clang, @homebrew_version="4.2.16-55-gc8f60ec-dirty", @installed_as_dependency=false, @installed_on_request=false, @loaded_from_api=false, @poured_from_bottle=false, @runtime_dependencies=nil, @source={"path"=>nil, "tap"=>"homebrew/core", "tap_git_head"=>nil, "spec"=>"stable", "versions"=>{"stable"=>nil, "head"=>nil, "version_scheme"=>0}}, @source_modified_time=0, @stdlib=nil, @tabfile=#<Pathname:/private/tmp/homebrew-tests-20240403-85464-3uogqr/cellar/oldname/0.1/INSTALL_RECEIPT.json>, @time=nil, @unused_options=[], @used_options=[]>
(rdbg@/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/rspec#85464)
```
2024-04-17 22:25:12 +01:00
Issy Long
11c1960729
Remove byebug since it doesn't work in tests anymore
- Byebug was introduced in [2020](https://github.com/Homebrew/brew/pull/7577) for hooking into tests for debugging.
- It does not work anymore in so far as it does not stop at breakpoints when following the instructions to trigger them in tests.
2024-04-17 22:24:21 +01:00
Douglas Eichelberger
914e53e9d5 Move isolated matchers into the specs that uses them 2024-03-30 20:24:06 -07:00
Douglas Eichelberger
fde7d380f7 Don't include FileUtils everywhere 2024-03-30 19:10:56 -07:00
Douglas Eichelberger
c1a4a806e1 rm unused OutputAsTTY helper 2024-03-30 18:44:39 -07:00
apainintheneck
74aea8e92d spec_helper: add :no_api test scope
This sets the HOMEBREW_NO_INSTALL_FROM_API environment variable
to prevent the selected tests from using the API. We will need
this as we transition to having the API be enabled by default
when running the tests but it's also nice as a sanity check
with the :needs_utils_curl scope in a few places.
2024-03-19 22:18:02 -07:00
apainintheneck
b66097fa3d spec_helper: add check for unexpected network calls
Any test that is not tagged as :needs_network and that makes
a call to an unapproved method in the `Utils::Curl` module
will raise an error unless that method gets mocked somehow.

tests: add exceptions for tests that use curl to download local files

These are acceptable ways to use curl in local, non-network tests.
For those edge cases we allow you to bypass the check with :needs_utils_curl.
2024-03-18 20:57:23 -07:00
Douglas Eichelberger
468c7b32e0 Remove unused matcher 2024-03-17 23:08:33 -07:00
Douglas Eichelberger
820d320835 Remove and refactor rspec-its use 2024-03-17 22:47:37 -07:00
apainintheneck
3834ef1b73 tap: cache more things at the Tap level
I added two new methods to cache both installed and all taps.
All taps includes core taps no matter if they're installed locally
since they're always provided by the API anyway.

This makes it easier to cache `Tap.each` while making the code
easier to reason about. It also will be useful because we'll
be able to avoid the `Tap.select(&:installed?` pattern that has
recently invaded the codebase.

Note: I also stopped clearing all tap instance caches before
tests. Running `Tap.each` would cache existing taps which would
lead to unexpected behavior since the only existing tap before
each test is the core tap. This is the only tap whose directory
is not cleaned up between tests so we just clear it's cache directly.
We also now clear all tap instances after tests as well regardless
of whether the API was used that time.
2024-03-08 23:22:00 -08:00
apainintheneck
f2c5f6723c test: clear tap instance caches between test runs again
The core taps exist outside of the normal cache busting cycle
so they need to clear explicitly at the instance level.
Just to be sure we should clear all of them each time.

This essentially reverts part of the change in this PR.
- https://github.com/Homebrew/brew/pull/16746
2024-02-27 19:35:30 -08:00
apainintheneck
5cc1c85a5f cachable: Move registry to test directory
Now we only include the cachable registry when running tests.
We basically just load it first and add a bunch of methods to
it before loading the rest of the formula files when we require
global.rb. I added a check to make sure this require order is
preserved.

I also made a bunch of methods private, stop excluding classes
that inherit from casks since it's unnecessary and add more docs.
2024-02-26 20:41:10 -08:00
apainintheneck
536ae08a44 cachable: make sure to clear caches between tests
This adds a registry for all modules and classes that
cachable is included in. The registry allows us to
programmatically clear all caches in between tests
so that we don't forget to do that when adding a new
class or refactoring code. The goal here is to reduce
the number of flaky tests in the future.
2024-02-25 17:47:30 -08:00
Markus Reiter
9cfc7ef9bd
Clear all tap caches before each test. 2024-02-22 17:56:47 +01:00
Douglas Eichelberger
c2e48ec79c Extract find_files to helper 2024-02-19 08:28:12 -08:00
Douglas Eichelberger
d7ebf97467
Turn on disable_monkey_patching 2024-02-19 13:57:28 +00:00
Douglas Eichelberger
2255b9d43d
Enable verify_partial_doubles 2024-02-19 13:57:27 +00:00
Douglas Eichelberger
d6b3f5031a
Enable and fix warnings 2024-02-19 13:57:27 +00:00
Issy Long
bc5e422815
Merge pull request #16497 from issyl0/rubocop-new-rules-style-array-intersect
Fix RuboCop `Style/ArrayIntersect` offenses
2024-01-19 13:00:30 +00:00
Bo Anderson
ec0434c549
Tweak library load path insertion to be as early as possible 2024-01-18 14:54:14 +00:00
Issy Long
0e27dc2564
Fix RuboCop Style/ArrayIntersect offenses 2024-01-18 14:11:43 +00:00
Markus Reiter
4b7aed84fa
Add test for print_stdout: :debug. 2023-10-10 03:42:22 +02:00
Bo Anderson
e4623cc8f4
Improve performance of brew readall 2023-09-28 14:05:09 +01:00
Mike McQuaid
b7114651ac
utils/curl: include or use explicitly.
Include or use `Utils::Curl` explicitly everywhere it is used.
2023-09-04 22:17:57 -04:00
Douglas Eichelberger
9075cbae62 brew style --fix 2023-04-21 09:58:50 -07:00
Douglas Eichelberger
ac1e6ded9a git grep -l '# typed: false' | xargs gsed -i 's|# typed: false||g' 2023-04-21 09:57:47 -07:00
Douglas Eichelberger
cc5b013cb9 Remove compatibility layer 2023-03-14 14:49:34 -07:00
Issy Long
298bb65dfb
rubocop: Entirely disable Metrics cops
- These are arbitrary length limits that had a load of disables in code.
- The limits were only increasing over time rather than decreasing.
- Fixing the problematic code to be shorter would take a long time for
  questionable gain since the problem has been around so long.
2023-02-21 00:34:17 +00:00
Issy Long
f8654bd363
rubocop: In-line disables of Metrics/{Module,Block,Class}Length
- We're not going to make the really long things be any shorter any time soon.
- The instructions in issue 14685 say, pragmatically, "disable all the rubocop
  rules we're never going to realistically fix e.g. Metrics/ClassLength". But
  that felt like a slippery slope to more _really_ long modules/classes/blocks,
  and the limits are here for a reason.
2023-02-19 16:33:23 +00:00
Mike McQuaid
a743e9277f
workflows/tests: faster, more reliable tests.
- Extract update tests into separate tests.
- Make `brew tests --online` run only once in its own job. This job
  could be made non-required to fight flakiness.
- Split up the various macOS runs into several steps now that we have
  more parallel macOS workers available.
- Cleanup some flaky tests.
2023-02-17 15:26:18 +00:00
Douglas Eichelberger
f126f0d39b Refactor away rspec/wait 2023-01-25 10:07:42 -08:00
apainintheneck
b7e28ef48f Make :formula? the default on Linux
This makes :formula? the default whenever
defined throughout the codebase on Linux.
It also makes :cask? illegal for all Linux
users.
2022-12-04 19:43:12 -08:00
Mike McQuaid
416af82670
macOS Ventura (and related) test fixes
- fix `check_for_config_scripts` test, no idea why this wasn't working
- don't autoretry tests if `focus` or `byebug` are enabled
- add a ARM64 Ventura bottle symlink
2022-10-20 11:28:27 +01:00
apainintheneck
a178fc6a88 Cleanup no cask on linux specs 2022-10-02 08:51:17 -07:00
apainintheneck
5d27b70757 Set --formula by default on linux 2022-10-01 17:28:07 -07:00