Skip to content

Commit 9a85e76

Browse files
committed
Parse message from errors and failures
1 parent c033797 commit 9a85e76

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

ruby/bin/annotate

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ job_pattern = '-(.*).xml' if !job_pattern || job_pattern.empty?
1616
failure_format = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT']
1717
failure_format = 'classname' if !failure_format || failure_format.empty?
1818

19-
class Failure < Struct.new(:name, :failed_test, :body, :job, :type)
19+
class Failure < Struct.new(:name, :failed_test, :body, :job, :type, :message)
2020
end
2121

2222
junit_report_files = Dir.glob(File.join(junits_dir, "**", "*"))
@@ -33,6 +33,16 @@ def text_content(element)
3333
end
3434
end
3535

36+
def message_content(element)
37+
# Handle empty attributes
38+
message = element.attributes['message'];
39+
if message.nil? || message.empty?
40+
nil
41+
else
42+
message.to_s
43+
end
44+
end
45+
3646
junit_report_files.sort.each do |file|
3747
next if File.directory?(file)
3848

@@ -46,10 +56,10 @@ junit_report_files.sort.each do |file|
4656
name = testcase.attributes['name'].to_s
4757
failed_test = testcase.attributes[failure_format].to_s
4858
testcase.elements.each("failure") do |failure|
49-
failures << Failure.new(name, failed_test, text_content(failure), job, :failure)
59+
failures << Failure.new(name, failed_test, text_content(failure), job, :failure, message_content(failure))
5060
end
5161
testcase.elements.each("error") do |error|
52-
failures << Failure.new(name, failed_test, text_content(error), job, :error)
62+
failures << Failure.new(name, failed_test, text_content(error), job, :error, message_content(error))
5363
end
5464
end
5565
end
@@ -77,6 +87,9 @@ puts [
7787
failures.each do |failure|
7888
puts "<details>"
7989
puts "<summary><code>#{failure.name} in #{failure.failed_test}</code></summary>\n\n"
90+
if failure.message
91+
puts "<p>#{failure.message.chomp.strip}</p>\n\n"
92+
end
8093
if failure.body
8194
puts "<pre><code>#{failure.body.chomp.strip}</code></pre>\n\n"
8295
end

ruby/tests/annotate_test.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<details>
3434
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
3535
36+
<p>expected: 250 got: 500 (compared using eql?)</p>
37+
3638
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
3739
3840
expected: 250
@@ -50,6 +52,8 @@
5052
<details>
5153
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
5254
55+
<p>expected: 700 got: 500 (compared using eql?)</p>
56+
5357
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
5458
5559
expected: 700
@@ -67,6 +71,8 @@
6771
<details>
6872
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
6973
74+
<p>expected: 700 got: 500 (compared using eql?)</p>
75+
7076
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
7177
7278
expected: 700
@@ -84,6 +90,8 @@
8490
<details>
8591
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
8692
93+
<p>expected: 250 got: 500 (compared using eql?)</p>
94+
8795
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
8896
8997
expected: 250
@@ -118,6 +126,8 @@
118126
<details>
119127
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
120128
129+
<p>expected: 250 got: 500 (compared using eql?)</p>
130+
121131
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
122132
123133
expected: 250
@@ -135,6 +145,8 @@
135145
<details>
136146
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
137147
148+
<p>expected: 700 got: 500 (compared using eql?)</p>
149+
138150
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
139151
140152
expected: 700
@@ -152,6 +164,8 @@
152164
<details>
153165
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
154166
167+
<p>expected: 700 got: 500 (compared using eql?)</p>
168+
155169
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
156170
157171
expected: 700
@@ -169,6 +183,8 @@
169183
<details>
170184
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
171185
186+
<p>expected: 250 got: 500 (compared using eql?)</p>
187+
172188
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
173189
174190
expected: 250
@@ -201,6 +217,8 @@
201217
<details>
202218
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
203219
220+
<p>expected: 250 got: 500 (compared using eql?)</p>
221+
204222
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
205223
206224
expected: 250
@@ -235,6 +253,8 @@
235253
<details>
236254
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
237255
256+
<p>expected: 250 got: 500 (compared using eql?)</p>
257+
238258
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
239259
240260
expected: 250
@@ -252,6 +272,8 @@
252272
<details>
253273
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
254274
275+
<p>expected: 700 got: 500 (compared using eql?)</p>
276+
255277
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
256278
257279
expected: 700
@@ -269,6 +291,8 @@
269291
<details>
270292
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in ./spec/models/account_spec.rb</code></summary>
271293
294+
<p>expected: 700 got: 500 (compared using eql?)</p>
295+
272296
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
273297
274298
expected: 700
@@ -286,6 +310,8 @@
286310
<details>
287311
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in ./spec/models/account_spec.rb</code></summary>
288312
313+
<p>expected: 250 got: 500 (compared using eql?)</p>
314+
289315
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
290316
291317
expected: 250
@@ -320,6 +346,8 @@
320346
<details>
321347
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
322348
349+
<p>expected: 250 got: 500 (compared using eql?)</p>
350+
323351
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
324352
325353
expected: 250
@@ -337,6 +365,8 @@
337365
<details>
338366
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
339367
368+
<p>expected: 700 got: 500 (compared using eql?)</p>
369+
340370
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
341371
342372
expected: 700
@@ -354,6 +384,8 @@
354384
<details>
355385
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
356386
387+
<p>expected: 700 got: 500 (compared using eql?)</p>
388+
357389
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
358390
359391
expected: 700
@@ -371,6 +403,8 @@
371403
<details>
372404
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
373405
406+
<p>expected: 250 got: 500 (compared using eql?)</p>
407+
374408
<pre><code>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
375409
376410
expected: 250
@@ -403,6 +437,38 @@
403437
<details>
404438
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
405439
440+
<p>expected: 250 got: 500 (compared using eql?)</p>
441+
442+
</details>
443+
OUTPUT
444+
445+
assert_equal 0, status.exitstatus
446+
end
447+
448+
it "handles missing message attributes" do
449+
output, status = Open3.capture2e("#{__dir__}/../bin/annotate", "#{__dir__}/missing-message-attribute/")
450+
451+
assert_equal <<~OUTPUT, output
452+
Parsing junit.xml
453+
--- ❓ Checking failures
454+
4 testcases found
455+
There are 3 failures/errors 😭
456+
--- ✍️ Preparing annotation
457+
1 failure and 2 errors:
458+
459+
<details>
460+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
461+
462+
</details>
463+
464+
<details>
465+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 100 by default in spec.models.account_spec</code></summary>
466+
467+
</details>
468+
469+
<details>
470+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 50 by default in spec.models.account_spec</code></summary>
471+
406472
</details>
407473
OUTPUT
408474

@@ -423,6 +489,8 @@
423489
<details>
424490
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
425491
492+
<p>expected: 250 got: 500 (compared using eql?)</p>
493+
426494
<pre><code>First line of failure output
427495
Second line of failure output</code></pre>
428496
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="rspec" tests="2" skipped="0" failures="0" errors="1" time="49.290713" timestamp="2018-04-18T23:29:42+00:00" hostname="626d214475e4">
3+
<testcase classname="spec.models.account_spec" name="Account#maximum_jobs_added_by_pipeline_changer returns 500 if the account is ABC" file="./spec/models/account_spec.rb" time="0.020013"/>
4+
<testcase classname="spec.models.account_spec" name="Account#maximum_jobs_added_by_pipeline_changer returns 250 by default" file="./spec/models/account_spec.rb" time="0.967127">
5+
<failure type="RSpec::Expectations::ExpectationNotMetError"></failure>
6+
</testcase>
7+
<testcase classname="spec.models.account_spec" name="Account#maximum_jobs_added_by_pipeline_changer returns 100 by default" file="./spec/models/account_spec.rb" time="0.967127">
8+
<error type="RSpec::Expectations::ExpectationNotMetError"></error>
9+
</testcase>
10+
<testcase classname="spec.models.account_spec" name="Account#maximum_jobs_added_by_pipeline_changer returns 50 by default" file="./spec/models/account_spec.rb" time="0.967127">
11+
<error message="" type="RSpec::Expectations::ExpectationNotMetError"></error>
12+
</testcase>
13+
</testsuite>

0 commit comments

Comments
 (0)