Skip to content

Commit 02cec82

Browse files
author
Nicole Lopez
committed
update readme on usage, add incorrect arg handling to annotate script + test
1 parent e44679e commit 02cec82

File tree

3 files changed

+74
-64
lines changed

3 files changed

+74
-64
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@ The artifact glob path to find the JUnit XML files.
2727
Example: `tmp/junit-*.xml`
2828

2929
### `job-uuid-file-pattern` (optional)
30+
Default: `-(.*).xml`
3031

3132
The regular expression (with capture group) that matches the job UUID in the junit file names. This is used to create the job links in the annotation.
3233

3334
To use this, configure your test reporter to embed the `$BUILDKITE_JOB_ID` environment variable into your junit file names. For example `"junit-buildkite-job-$BUILDKITE_JOB_ID.xml"`.
3435

35-
Default: `-(.*).xml`
36-
3736
### `failure-format` (optional)
37+
Default: `classname`
3838

3939
This setting controls the format of your failed test in the main annotation summary.
4040

4141
There are two options for this:
42-
* `classname` (default) -- will display: `MyClass::UnderTest text of the failed expectation in path.to.my_class.under_test`
43-
* `file` -- will display: `MyClass::UnderTest text of the failed expectation in path/to/my_class/under_test.file_ext`
42+
* `classname`
43+
* displays: `MyClass::UnderTest text of the failed expectation in path.to.my_class.under_test`
44+
* `file`
45+
* displays: `MyClass::UnderTest text of the failed expectation in path/to/my_class/under_test.file_ext`
4446

4547
## Developing
4648

ruby/bin/annotate

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ job_pattern = '-(.*).xml' if !job_pattern || job_pattern.empty?
1414

1515
failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT']
1616
failure_format = 'classname' if !failure_format || failure_format.empty?
17+
if !%w(classname file).include?(failure_format)
18+
raise ArgumentError.new("Invalid failure-format #{failure_format} provided -- leave this setting blank or specify `file` or `classname`")
19+
end
1720

1821
class Failure < Struct.new(:name, :failed_test, :body, :job, :type)
1922
end

ruby/tests/annotate_test.rb

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -216,88 +216,93 @@
216216
end
217217

218218
it "uses the file path instead of classname for annotation content when specified" do
219-
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=file", "#{__dir__}/../bin/annotate", "#{__dir__}/test-failure-and-error/")
219+
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=file", "#{__dir__}/../bin/annotate", "#{__dir__}/test-failure-and-error/")
220220

221-
assert_equal <<~OUTPUT, output
222-
Parsing junit-1.xml
223-
Parsing junit-2.xml
224-
Parsing junit-3.xml
225-
--- ❓ Checking failures
226-
There are 4 failures/errors 😭
227-
--- ✍️ Preparing annotation
228-
2 failures and 2 errors:
221+
assert_equal <<~OUTPUT, output
222+
Parsing junit-1.xml
223+
Parsing junit-2.xml
224+
Parsing junit-3.xml
225+
--- ❓ Checking failures
226+
There are 4 failures/errors 😭
227+
--- ✍️ Preparing annotation
228+
2 failures and 2 errors:
229229
230-
<details>
231-
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
230+
<details>
231+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
232232
233-
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
233+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
234234
235-
expected: 250
236-
got: 500
235+
expected: 250
236+
got: 500
237237
238-
(compared using eql?)
239-
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
240-
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
241-
./spec/support/log.rb:17:in `run'
242-
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
238+
(compared using eql?)
239+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
240+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
241+
./spec/support/log.rb:17:in `run'
242+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
243243
244-
in <a href="#1">Job #1</a>
245-
</details>
244+
in <a href="#1">Job #1</a>
245+
</details>
246246
247-
<details>
248-
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
247+
<details>
248+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
249249
250-
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
250+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
251251
252-
expected: 700
253-
got: 500
252+
expected: 700
253+
got: 500
254254
255-
(compared using eql?)
256-
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
257-
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
258-
./spec/support/log.rb:17:in `run'
259-
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
255+
(compared using eql?)
256+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
257+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
258+
./spec/support/log.rb:17:in `run'
259+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
260260
261-
in <a href="#2">Job #2</a>
262-
</details>
261+
in <a href="#2">Job #2</a>
262+
</details>
263263
264-
<details>
265-
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
264+
<details>
265+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
266266
267-
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
267+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
268268
269-
expected: 700
270-
got: 500
269+
expected: 700
270+
got: 500
271+
272+
(compared using eql?)
273+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
274+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
275+
./spec/support/log.rb:17:in `run'
276+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
271277
272-
(compared using eql?)
273-
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
274-
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
275-
./spec/support/log.rb:17:in `run'
276-
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
278+
in <a href="#3">Job #3</a>
279+
</details>
277280
278-
in <a href="#3">Job #3</a>
279-
</details>
281+
<details>
282+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
280283
281-
<details>
282-
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
284+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
283285
284-
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
286+
expected: 250
287+
got: 500
285288
286-
expected: 250
287-
got: 500
289+
(compared using eql?)
290+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
291+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
292+
./spec/support/log.rb:17:in `run'
293+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
288294
289-
(compared using eql?)
290-
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
291-
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
292-
./spec/support/log.rb:17:in `run'
293-
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
295+
in <a href="#3">Job #3</a>
296+
</details>
297+
OUTPUT
294298

295-
in <a href="#3">Job #3</a>
296-
</details>
297-
OUTPUT
299+
assert_equal 0, status.exitstatus
300+
end
298301

299-
assert_equal 0, status.exitstatus
300-
end
302+
it "raises an error when an invalid failure-format is provided" do
303+
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=kittens", "#{__dir__}/../bin/annotate", "#{__dir__}/test-failure-and-error/")
304+
assert_equal false, status.success?
305+
end
301306

302307
it "handles failures across multiple files in sub dirs" do
303308
output, status = Open3.capture2e("#{__dir__}/../bin/annotate", "#{__dir__}/tests-in-sub-dirs/")

0 commit comments

Comments
 (0)