166 Commits

Author SHA1 Message Date
Mike McQuaid
f234423913
dev-cmd/tests: fix require ordering.
This needs to happen after `setup_environment!` so that
`HOMEBREW_TEST_GENERIC_OS` is set and `OS.linux?` and `OS.mac?` both
`return false`.
2025-06-12 16:43:50 +01:00
Rylan Polster
ce72e34b19
Filter brew tests spec files appropriately for each OS 2025-06-11 15:59:21 -04:00
Mike McQuaid
e9f55a8f71
tests: default to API mode enabled.
While we're here, also add `brew tests --no-parallel` which I relied
on during testing.

Pretty much anywhere we rely on a stubbed formula on disk to work: we
need to disable the API.
2025-06-10 15:53:27 +01:00
Mike McQuaid
dc71b7c8f6
Cleanup extend/ directory usage.
- move some things out of `extend` that don't really fit there e.g.
  `Module`s that are included but not doing any
  overriding/monkeypatching
- move some code into `extend/os` to fix all remaining
  `rubocop:todo Homebrew/MoveToExtendOS`s
- remove some unneeded `bundle` skipper code that doesn't really make
  sense given our current bottling strategy
- extract some `Pathname` extensions to `extend/pathname` for separate
  files
- move a `ENV` `Kernel` extension into `kernel.rb`
- `odeprecate` a seemingly unused backwards compatibility method
- move `readline_nonblock` from a monkeypatch to a
  `ReadlineNonblock.read` method as its only used in one place
- fix up a link in documentation
2025-06-09 19:06:16 +01:00
Mike McQuaid
cc03340af3
Reduce Homebrew/brew CI warnings
- Remove a bunch of non-actionable/unnecessary noise in GitHub Actions
  CI.
- Limit number of threads used to generate analytics API data to avoid
  reproducible failures producing errors and requiring retries.
- Move to Debian Old Stable for testing non-system `glibc`.
- Remove unneeded core taps/updates.
- Improve naming of CI jobs to clarify purpose i.e. we're testing
  things work on Linux, not Ubuntu specifically.
- Remove dedicated non-online/non-generic Linux `brew tests` jobs from
  3 to 1.

Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2025-06-09 12:47:22 +01:00
Sam Ford
ed48426a33
tests: support :needs_arm, :needs_intel metadata
This adds the ability to specify tests that depend on a certain CPU
architecture using `:needs_arm` or `:needs_intel`, similar to the
existing `:needs_macos` and `:needs_linux` metadata for tests that
depend on a certain OS.
2025-04-04 09:17:32 -04:00
apainintheneck
f916f27d82 remove all references to JSON v3
The logic has now been removed in previous commits. This just
removes some references to the `HOMEBREW_INTERNAL_JSON_V3`
environment variable along with reverting the changes to the
`Cachable` class that were originally added in
bd72ec812c3ed656dfcf8e24f77df142a1fe9cc1.
2025-02-06 21:04:08 -08:00
Mike McQuaid
9cc9dd8760
dev-cmd/tests: disable forcing brew wrapper in tests.
Otherwise, various integration tests will fail under some
configurations.
2025-01-23 16:06:23 +00:00
Sam Ford
cb514a1d04
Disable parallel for small test coverage runs
`brew tests --coverage` can fail to produce coverage information when
run on a small number of tests (e.g., `--only utils/curl`). We use
`ParallelTests::last_process?` in `tests/spec_helper.rb` to handle
the SimpleCov output but due to the way the method is implemented, it
doesn't work as expected if the number of processes is greater than
one but lower than the number of cores. I tried to address this
through changes to  `spec_helper.rb` and/or changes to `ParallelTests`
but didn't meet with any success.

This works around the issue by disabling parallel test execution when
the `--coverage` option is used and the number of files to be tested
is lower than the number of CPU cores. I've been using this workaround
for months and it works as expected on my machine.
2025-01-10 19:42:04 -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
Douglas Eichelberger
fb2fdc5249 Minor type safety improvements 2024-08-18 18:16:39 -07:00
Issy Long
d5af469e85
dev-cmd/tests: Bump to Sorbet typed: strict 2024-06-30 20:41:02 +01: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
621e51a6c9
Don't require "debug" in brew tests - it's in our RSpec config 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
Mike McQuaid
c4f2f06675
dev-cmd/tests: fix when euid != uid.
Otherwise you get:
`ruby: no -r allowed while running setuid (SecurityError)`
2024-04-11 17:26:38 +01:00
Douglas Eichelberger
c50fb2dbd2 Remove redundant cli/parser requires 2024-03-29 18:53:07 -07:00
Douglas Eichelberger
445d81db2e Port Homebrew::DevCmd::Tests 2024-03-22 09:33:28 -07:00
apainintheneck
cd5b93a2f2 internal json v3: parse ruby source checksum correctly
Currently we are including this in the API but not actually
parsing and loading it correctly from the JSON. I think this
was an oversight when addressing feedback and refactoring
the JSON shape. Not a big deal, of course, because I'm the
only person using it right now.

I found this out while testing installs using the API and I got
this error while running `brew reinstall tree`.

```
Warning: Cannot verify integrity of '60fc4212023d3fef00e6de4b9f3f0d63402cf3eca00778d09f4f2d3481b524a1--tree.rb'.
No checksum was provided.
```
2024-02-28 21:34:31 -08:00
Issy Long
f4218a6316
Fix RuboCop Performance/MapCompact offenses
- Rename an iterator variable since it would make the line too long.
2024-02-25 22:59:59 +00:00
Douglas Eichelberger
583852cb0a Add missing SystemCommand::Mixin to fix CI 2024-01-31 14:55:04 -08:00
apainintheneck
894b94bfd7 dev-cmd/tests: Add profile option
This will allow us to more easily measure test performance. The only
downside here is that we can't use it with parallel rspec because
it will show the n slowest tests for each parallel rspec run which
is not what we want.
2024-01-06 12:51:15 -08:00
Bo Anderson
89531e9ff3
Update all dependencies 2023-12-15 16:24:46 +00:00
Bo Anderson
14c1dce38b
Allow HOMEBREW_RUBY3 in tests 2023-10-27 15:58:43 +01:00
Bo Anderson
71f558229a
Test on Ruby 3.1 2023-09-29 04:46:16 +01:00
Bo Anderson
3b1c171184
Further split up Gemfile into groups 2023-09-27 17:33:44 +01:00
Mike McQuaid
597f0840a3
dev-cmd/tests: add --fail-fast.
This is useful when testing very slow test files with many tests.
2023-08-10 16:27:37 +01:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Bo Anderson
b84bed7385
Revert "Revert "Split prof gems into their own group""
This reverts commit 7b336ed8cd3eb20461fdc45ce67e5318e53920c4.
2023-04-10 16:54:48 +01:00
Mike McQuaid
7b336ed8cd
Revert "Split prof gems into their own group" 2023-04-04 08:49:27 +01:00
Bo Anderson
8bafbcd65a
Split prof gems into their own group 2023-03-31 13:32:38 +01:00
Nanda H Krishna
b8fb963516
dev-cmd/tests: temporary fix for BuildPulse failure 2023-03-31 03:50:05 -04:00
Issy Long
a480982e75
dev-cmd/tests: Deal with TODO for a BuildPulse bug that's fixed
- This does what the comment told us to do, use the bang variant of
  `system_command` to not swallow the errors.
2023-03-29 20:54:42 +01:00
Douglas Eichelberger
cc5b013cb9 Remove compatibility layer 2023-03-14 14:49:34 -07:00
Douglas Eichelberger
0b04b99e68 brew typecheck --suggest-typed --update 2023-03-09 20:32:46 -08:00
Bo Anderson
c32a1b8104
dev-cmd/tests: ignore BuildPulse failures for now 2023-03-01 22:21:45 +00:00
Bo Anderson
f4067ac5fe
dev-cmd/tests: better output for BuildPulse failures 2023-03-01 20:42:50 +00:00
Mike McQuaid
80232af31d
More tweaks to testing output and speed
- Never bother to do `brew cleanup` after `brew install`
- Skip `brew test-bot --only-cleanup-before` in more places it's not
  needed
- Move `brew config`/`brew doctor` into the default formula run
  (through `brew test-bot --only-setup`)
- Install `buildpulse-test-reporter` rather than letting `brew tests`
  do it
- Improve the formatting of the `brew tests` step
- Further shorten the code coverage filenames
- Don't output BuildPulse results upload status unless failed
2023-02-17 16:17:45 +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
EricFromCanada
dfc9906184
internal messaging fixes 2023-02-10 23:17:16 -05:00
Mike McQuaid
2a5d41d41b
Revert "Merge pull request #14547 from Homebrew/revert-14412-homebrew_install_from_api_default"
This reverts commit f4e60482791d2ff628efadfdbf0d14d9237d2d29, reversing
changes made to e26784f424061ca16987afcb21e036c66a298492.
2023-02-07 19:25:40 +01:00
Mike McQuaid
0575903868
Revert "HOMEBREW_INSTALL_FROM_API: make the default for everyone." 2023-02-07 15:13:23 +01:00
Mike McQuaid
5f6c69bca2
HOMEBREW_INSTALL_FROM_API: make the default for everyone.
- remove all places we check the flag so it's a no-op now
- flip the messaging to refer to `HOMEBREW_NO_INSTALL_FROM_API` where
  relevant
- adjust the documentation
2023-02-05 18:13:08 +01:00
apainintheneck
c477b9aab3 Cleanup after adding os specific rubocop
- Change name of rubocop warning
- Disable linting on remaining offending lines
- Add todos to move lines with disabled linting
  checks to extend/os in the future
2022-11-29 23:13:50 -08:00
Mike McQuaid
59f4b5226a
tests: test on Ubuntu 18.04. 2022-11-09 14:45:43 +00:00
Mike McQuaid
2961132e01
tests: fix under GitHub Codespaces. 2022-11-03 16:33:04 +00:00
Bo Anderson
eac32f0b20
Additional fixes for Ruby 3 compatibility 2022-10-18 01:54:59 +01:00