Skip to content

Commit

Permalink
dev-cmd/tests: Add profile option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apainintheneck committed Jan 6, 2024
1 parent 3821fab commit 894b94b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def tests_args
flag "--only=",
description: "Run only <test_script>`_spec.rb`. Appending `:`<line_number> will start at a " \
"specific line."
flag "--profile=",
description: "Run the test suite serially to find the <n> slowest tests."
flag "--seed=",
description: "Randomise tests with the specified <value> instead of a random seed."

Expand Down Expand Up @@ -122,6 +124,8 @@ def tests
end
end

parallel = false if args.profile

parallel_rspec_log_name = "parallel_runtime_rspec"
parallel_rspec_log_name = "#{parallel_rspec_log_name}.generic" if args.generic?
parallel_rspec_log_name = "#{parallel_rspec_log_name}.online" if args.online?
Expand Down Expand Up @@ -157,6 +161,7 @@ def tests
--require spec_helper
]
bundle_args << "--fail-fast" if args.fail_fast?
bundle_args << "--profile" << args.profile if args.profile

# TODO: Refactor and move to extend/os
# rubocop:disable Homebrew/MoveToExtendOS
Expand Down
1 change: 1 addition & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,7 @@ _brew_tests() {
--help
--online
--only
--profile
--quiet
--seed
--verbose
Expand Down
1 change: 1 addition & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ __fish_brew_complete_arg 'tests' -l generic -d 'Run only OS-agnostic tests'
__fish_brew_complete_arg 'tests' -l help -d 'Show this message'
__fish_brew_complete_arg 'tests' -l online -d 'Include tests that use the GitHub API and tests that use any of the taps for official external commands'
__fish_brew_complete_arg 'tests' -l only -d 'Run only test_script`_spec.rb`. Appending `:`line_number will start at a specific line'
__fish_brew_complete_arg 'tests' -l profile -d 'Run the test suite serially to find the n slowest tests'
__fish_brew_complete_arg 'tests' -l quiet -d 'Make some output more quiet'
__fish_brew_complete_arg 'tests' -l seed -d 'Randomise tests with the specified value instead of a random seed'
__fish_brew_complete_arg 'tests' -l verbose -d 'Make some output more verbose'
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ _brew_tests() {
'--help[Show this message]' \
'--online[Include tests that use the GitHub API and tests that use any of the taps for official external commands]' \
'(--changed)--only[Run only test_script`_spec.rb`. Appending `:`line_number will start at a specific line]' \
'--profile[Run the test suite serially to find the n slowest tests]' \
'--quiet[Make some output more quiet]' \
'--seed[Randomise tests with the specified value instead of a random seed]' \
'--verbose[Make some output more verbose]'
Expand Down
2 changes: 2 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,8 @@ Run Homebrew's unit and integration tests.
Exit early on the first failing test.
* `--only`:
Run only *`test_script`*`_spec.rb`. Appending `:`*`line_number`* will start at a specific line.
* `--profile`:
Run the test suite serially to find the *`n`* slowest tests.
* `--seed`:
Randomise tests with the specified *`value`* instead of a random seed.

Expand Down
4 changes: 4 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,10 @@ Exit early on the first failing test\.
Run only \fItest_script\fR\fB_spec\.rb\fR\. Appending \fB:\fR\fIline_number\fR will start at a specific line\.
.
.TP
\fB\-\-profile\fR
Run the test suite serially to find the \fIn\fR slowest tests\.
.
.TP
\fB\-\-seed\fR
Randomise tests with the specified \fIvalue\fR instead of a random seed\.
.
Expand Down

0 comments on commit 894b94b

Please sign in to comment.