Skip to content

Commit e163eb8

Browse files
committed
Enhance test suite to emit JUnit XML test reports
In preparation for detecting flaky tests with BuildPulse, this commit sets up the rspec_junit_formatter gem to output JUnit XML reports of the test suite, which is the format used by BuildPulse and various other tooling that interprets test results. Because the test suite uses the parallel_tests gem, this commit incorporates some related changes to make all the parallel_tests gem and the rspec_junit_formatter gem to cooperate with each other. rspec_junit_formatter writes everything to a single XML file. That works fine when there's only one process writing to the file. By default, whatever process finishes last will write to the file and clobber the output of all the other processes that wrote to the file. 🙈 To prevent this issue, the parallel_tests wiki recommends adding a `.rspec_parallel` file to specify its RSpec options (https://github.com/grosser/parallel_tests/wiki#with-rspec_junit_formatter----by-jgarber), then the project can specify different files for each process to write to like so: --format RspecJunitFormatter --out tmp/rspec<%= ENV['TEST_ENV_NUMBER'] %>.xml However, prior to this commit, the Homebrew/brew test suite specified its RSpec options via the command line. Unfortunately though, there's no way (AFAICT) to set the equivalent of these options via the command line: --format RspecJunitFormatter --out tmp/rspec<%= ENV['TEST_ENV_NUMBER'] %>.xml So, we need to use a `.rspec_parallel` file to specify these options ☝️. However, it appears that RSpec allows you to specify formatters _either_ in an options file (like `.rspec_parallel`) _or_ via command-line args. But if you specify any formatters via command-line args, then all formatters in the options file are ignored. (I suspect that's somehow related to this bit of code in rspec-core: https://github.com/rspec/rspec-core/blob/v3.10.0/lib/rspec/core/configuration_options.rb#L64.) With that in mind, in order to have the RspecJunitFormatter configured in `.rspec_parallel`, we need to move the other formatters into `.rpsec_parallel` as well, instead of passing them as command-line args. Therefore, this commit moves all the formatters into a `.rspec_parallel` file.
1 parent 09f7bc2 commit e163eb8

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/Library/Homebrew/test/.gem
1515
/Library/Homebrew/test/.subversion
1616
/Library/Homebrew/test/coverage
17+
/Library/Homebrew/test/junit
1718
/Library/Homebrew/test/fs_leak_log
1819
/Library/Homebrew/vendor/portable-ruby
1920
/Library/Taps
@@ -133,6 +134,7 @@
133134
**/vendor/bundle/ruby/*/gems/rspec-*/
134135
**/vendor/bundle/ruby/*/gems/rspec-core-*/
135136
**/vendor/bundle/ruby/*/gems/rspec-expectations-*/
137+
**/vendor/bundle/ruby/*/gems/rspec_junit_formatter-*/
136138
**/vendor/bundle/ruby/*/gems/rspec-its-*/
137139
**/vendor/bundle/ruby/*/gems/rspec-mocks-*/
138140
**/vendor/bundle/ruby/*/gems/rspec-retry-*/

Library/Homebrew/.rspec_parallel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--format NoSeedProgressFormatter
2+
--format ParallelTests::RSpec::RuntimeLogger
3+
--out <%= ENV["PARALLEL_RSPEC_LOG_PATH"] %>
4+
--format RspecJunitFormatter
5+
--out test/junit/rspec<%= ENV["TEST_ENV_NUMBER"] %>.xml
6+
<%= "--format RSpec::Github::Formatter" if ENV["GITHUB_ACTIONS"] %>

Library/Homebrew/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gem "ronn", require: false
1212
gem "rspec", require: false
1313
gem "rspec-github", require: false
1414
gem "rspec-its", require: false
15+
gem "rspec_junit_formatter", require: false
1516
gem "rspec-retry", require: false
1617
gem "rspec-wait", require: false
1718
gem "rubocop", require: false

Library/Homebrew/Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ GEM
109109
rspec-support (3.10.2)
110110
rspec-wait (0.0.9)
111111
rspec (>= 3, < 4)
112+
rspec_junit_formatter (0.4.1)
113+
rspec-core (>= 2, < 4, != 2.12.0)
112114
rubocop (1.17.0)
113115
parallel (~> 1.10)
114116
parser (>= 3.0.0.0)
@@ -194,6 +196,7 @@ DEPENDENCIES
194196
rspec-retry
195197
rspec-sorbet
196198
rspec-wait
199+
rspec_junit_formatter
197200
rubocop
198201
rubocop-ast
199202
rubocop-performance

Library/Homebrew/dev-cmd/tests.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def tests
111111
else
112112
"#{HOMEBREW_CACHE}/#{parallel_rspec_log_name}"
113113
end
114+
ENV["PARALLEL_RSPEC_LOG_PATH"] = parallel_rspec_log_path
114115

115116
parallel_args = if ENV["CI"]
116117
%W[
@@ -133,13 +134,8 @@ def tests
133134
--seed #{seed}
134135
--color
135136
--require spec_helper
136-
--format NoSeedProgressFormatter
137-
--format ParallelTests::RSpec::RuntimeLogger
138-
--out #{parallel_rspec_log_path}
139137
]
140138

141-
bundle_args << "--format" << "RSpec::Github::Formatter" if ENV["GITHUB_ACTIONS"]
142-
143139
unless OS.mac?
144140
bundle_args << "--tag" << "~needs_macos" << "--tag" << "~cask"
145141
files = files.reject { |p| p =~ %r{^test/(os/mac|cask)(/.*|_spec\.rb)$} }

0 commit comments

Comments
 (0)