Skip to content

Commit 7588066

Browse files
committed
Simplified code and added ability to show skipped tests
1 parent 27ae0a3 commit 7588066

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

ruby/bin/annotate

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ failure_format = 'classname' if !failure_format || failure_format.empty?
1919

2020
report_slowest = ENV['BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST'].to_i
2121

22-
class Failure < Struct.new(:name, :unit_name, :body, :job, :type, :message)
22+
class Failure < Struct.new(:name, :unit_name, :body, :job, :message)
2323
end
2424

2525
class Timing < Struct.new(:name, :unit_name, :time)
2626
end
2727

2828
junit_report_files = Dir.glob(File.join(junits_dir, "**", "*"), File::FNM_DOTMATCH)
2929
testcases = 0
30-
skipped = 0
31-
failures = []
30+
tests = {
31+
failure: [],
32+
error: [],
33+
skipped: []
34+
}
3235
timings = []
3336

3437
def text_content(element)
@@ -65,29 +68,22 @@ junit_report_files.sort.each do |file|
6568
unit_name = testcase.attributes[failure_format].to_s
6669
time = testcase.attributes['time'].to_f
6770
timings << Timing.new(name, unit_name, time)
68-
testcase.elements.each("failure") do |failure|
69-
failures << Failure.new(name, unit_name, text_content(failure), job, :failure, message_content(failure))
70-
end
71-
testcase.elements.each("error") do |error|
72-
failures << Failure.new(name, unit_name, text_content(error), job, :error, message_content(error))
73-
end
74-
testcase.elements.each("skipped") do |skip|
75-
skipped += 1
71+
testcase.elements.each("failure | error | skipped") do |elem|
72+
tests[elem.name.to_sym] << Failure.new(name, unit_name, text_content(elem), job, message_content(elem))
7673
end
7774
end
7875
end
7976

8077
STDERR.puts "--- ✍️ Preparing annotation"
8178

82-
failures_count = failures.select {|f| f.type == :failure }.length
83-
errors_count = failures.select {|f| f.type == :error }.length
84-
85-
puts "Failures: #{failures_count}"
86-
puts "Errors: #{errors_count}"
87-
puts "Skipped: #{skipped}"
79+
puts "Failures: #{tests[:failure].length}"
80+
puts "Errors: #{tests[:error].length}"
81+
puts "Skipped: #{tests[:skipped].length}"
8882
puts "Total tests: #{testcases}"
8983

90-
failures.each do |failure|
84+
tests.delete(:skipped) unless ENV.fetch('BUILDKITE_PLUGIN_JUNIT_ANNOTATE_SKIPPED_FORMAT', 'none') != 'none'
85+
86+
tests.values.flatten.each do |failure|
9187
puts ""
9288
puts "<details>"
9389
puts "<summary><code>#{CGI.escapeHTML failure.name} in #{CGI.escapeHTML failure.unit_name}</code></summary>\n\n"
@@ -119,4 +115,4 @@ if report_slowest > 0
119115
puts "</details>"
120116
end
121117

122-
exit 64 if failures.any? # special exit code to signal test failures
118+
exit 64 if tests.values.flatten.any? # special exit code to signal test failures

0 commit comments

Comments
 (0)