Skip to content

Commit 40a7021

Browse files
committed
Correctly handle sub-directories
1 parent 072d08e commit 40a7021

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

ruby/bin/annotate

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ job_pattern = '-(.*).xml' if !job_pattern || job_pattern.empty?
1414

1515
class Failure < Struct.new(:name, :classname, :body, :job); end
1616

17-
junit_report_files = Dir.glob(File.join(junits_dir, "*"))
17+
junit_report_files = Dir.glob(File.join(junits_dir, "**", "*"))
1818
all_failures = []
1919

2020
junit_report_files.each do |file|
21+
next if File.directory?(file)
22+
2123
STDERR.puts "Parsing #{file.sub(junits_dir, '')}"
2224
job = File.basename(file)[/#{job_pattern}/, 1]
2325
xml = File.read(file)

ruby/tests/annotate_test.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,53 @@
9494

9595
assert_equal 0, status.exitstatus
9696
end
97+
98+
it "handles failures across multiple files in sub dirs" do
99+
output, status = Open3.capture2e("#{__dir__}/../bin/annotate", "#{__dir__}/tests-in-sub-dirs/")
100+
101+
assert_equal <<~OUTPUT, output
102+
Parsing sub-dir/junit-1.xml
103+
Parsing sub-dir/junit-2.xml
104+
--- ❓ Checking failures
105+
There are 2 failures 😭
106+
--- ✍️ Preparing annotation
107+
There were 2 failures:
108+
109+
<details>
110+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 250 by default in spec.models.account_spec</code></summary>
111+
112+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
113+
114+
expected: 250
115+
got: 500
116+
117+
(compared using eql?)
118+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
119+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
120+
./spec/support/log.rb:17:in `run'
121+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
122+
123+
in <a href="#1">Job #1</a>
124+
</details>
125+
126+
<details>
127+
<summary><code>Account#maximum_jobs_added_by_pipeline_changer returns 700 if the account is XYZ in spec.models.account_spec</code></summary>
128+
129+
<code><pre>Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
130+
131+
expected: 700
132+
got: 500
133+
134+
(compared using eql?)
135+
./spec/models/account_spec.rb:78:in `block (3 levels) in <top (required)>'
136+
./spec/support/database.rb:16:in `block (2 levels) in <top (required)>'
137+
./spec/support/log.rb:17:in `run'
138+
./spec/support/log.rb:66:in `block (2 levels) in <top (required)>'</pre></code>
139+
140+
in <a href="#2">Job #2</a>
141+
</details>
142+
OUTPUT
143+
144+
assert_equal 0, status.exitstatus
145+
end
97146
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="rspec" tests="2" skipped="0" failures="1" errors="0" 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 message=" expected: 250 got: 500 (compared using eql?) " type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
6+
7+
expected: 250
8+
got: 500
9+
10+
(compared using eql?)
11+
./spec/models/account_spec.rb:78:in `block (3 levels) in &lt;top (required)&gt;&apos;
12+
./spec/support/database.rb:16:in `block (2 levels) in &lt;top (required)&gt;&apos;
13+
./spec/support/log.rb:17:in `run&apos;
14+
./spec/support/log.rb:66:in `block (2 levels) in &lt;top (required)&gt;&apos;</failure>
15+
</testcase>
16+
</testsuite>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="rspec" tests="1" skipped="0" failures="1" errors="0" 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 700 if the account is XYZ" file="./spec/models/account_spec.rb" time="0.967127">
4+
<failure message=" expected: 700 got: 500 (compared using eql?) " type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect(account.maximum_jobs_added_by_pipeline_changer).to eql(250)
5+
6+
expected: 700
7+
got: 500
8+
9+
(compared using eql?)
10+
./spec/models/account_spec.rb:78:in `block (3 levels) in &lt;top (required)&gt;&apos;
11+
./spec/support/database.rb:16:in `block (2 levels) in &lt;top (required)&gt;&apos;
12+
./spec/support/log.rb:17:in `run&apos;
13+
./spec/support/log.rb:66:in `block (2 levels) in &lt;top (required)&gt;&apos;</failure>
14+
</testcase>
15+
</testsuite>

0 commit comments

Comments
 (0)