Skip to content

Commit cd35152

Browse files
feedback
Created using spr 1.3.6
2 parents 530b3fa + caea209 commit cd35152

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

.ci/generate_test_report_lib.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
2727
# We hit the end of the log without finding a build failure, go to
2828
# the next log.
2929
return failures
30+
# index will point to the line that starts with Failed:. The progress
31+
# indicator is the line before this and contains a pretty printed version
32+
# of the target being built. We use this and remove the progress information
33+
# to get a succinct name for the target.
3034
failing_action = ninja_log[index - 1].split("] ")[1]
3135
failure_log = []
3236
while (
3337
index < len(ninja_log)
3438
and not ninja_log[index].startswith("[")
35-
and not ninja_log[index].startswith(
36-
"ninja: build stopped: subcommand failed"
37-
)
39+
and not ninja_log[index].startswith("ninja: build stopped:")
3840
and len(failure_log) < NINJA_LOG_SIZE_THRESHOLD
3941
):
4042
failure_log.append(ninja_log[index])
@@ -46,7 +48,7 @@ def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
4648
def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, str]]:
4749
"""Extracts failure messages from ninja output.
4850
49-
This patch takes stdout/stderr from ninja in the form of a list of files
51+
This function takes stdout/stderr from ninja in the form of a list of files
5052
represented as a list of lines. This function then returns tuples containing
5153
the name of the target and the error message.
5254
@@ -65,6 +67,25 @@ def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, s
6567
return failures
6668

6769

70+
def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
71+
"""Formats ninja failures into summary views for the report."""
72+
output = []
73+
for build_failure in ninja_failures:
74+
failed_action, failure_message = build_failure
75+
output.extend(
76+
[
77+
"<details>",
78+
f"<summary>{failed_action}</summary>",
79+
"",
80+
"```",
81+
failure_message,
82+
"```",
83+
"</details>",
84+
]
85+
)
86+
return output
87+
88+
6889
# Set size_limit to limit the byte size of the report. The default is 1MB as this
6990
# is the most that can be put into an annotation. If the generated report exceeds
7091
# this limit and failures are listed, it will be generated again without failures
@@ -129,24 +150,12 @@ def generate_report(
129150
else:
130151
report.extend(
131152
[
132-
"The build failed before running any tests. Click on the "
153+
"The build failed before running any tests. Click on a "
133154
"failure below to see the details.",
134155
"",
135156
]
136157
)
137-
for build_failure in ninja_failures:
138-
failed_action, failure_message = build_failure
139-
report.extend(
140-
[
141-
"<details>",
142-
f"<summary>{failed_action}</summary>",
143-
"",
144-
"```",
145-
failure_message,
146-
"```",
147-
"</details>",
148-
]
149-
)
158+
report.extend(_format_ninja_failures(ninja_failures))
150159
report.extend(
151160
[
152161
"",
@@ -203,26 +212,14 @@ def plural(num_tests):
203212
[
204213
"",
205214
"All tests passed but another part of the build **failed**. "
206-
"Detailed information about the build failure could not be "
207-
"automatically obtained.",
215+
"Information about the build failure could not be automatically "
216+
"obtained.",
208217
"",
209218
SEE_BUILD_FILE_STR,
210219
]
211220
)
212221
else:
213-
for build_failure in ninja_failures:
214-
failed_action, failure_message = build_failure
215-
report.extend(
216-
[
217-
"<details>",
218-
f"<summary>{failed_action}</summary>",
219-
"",
220-
"```",
221-
failure_message,
222-
"```",
223-
"</details>",
224-
]
225-
)
222+
report.extend(_format_ninja_failures(ninja_failures))
226223

227224
if failures or return_code != 0:
228225
report.extend(["", UNRELATED_FAILURES_STR])

.ci/generate_test_report_lib_test.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def test_find_failure_ninja_logs(self):
2727
"[2/5] test/2.stamp",
2828
"[3/5] test/3.stamp",
2929
"[4/5] test/4.stamp",
30-
"FAILED: test/4.stamp",
31-
"touch test/4.stamp",
30+
"FAILED: touch test/4.stamp",
3231
"Wow! This system is really broken!",
3332
"[5/5] test/5.stamp",
3433
],
@@ -41,8 +40,7 @@ def test_find_failure_ninja_logs(self):
4140
"test/4.stamp",
4241
dedent(
4342
"""\
44-
FAILED: test/4.stamp
45-
touch test/4.stamp
43+
FAILED: touch test/4.stamp
4644
Wow! This system is really broken!"""
4745
),
4846
),
@@ -175,7 +173,7 @@ def test_title_only_failure_ninja_log(self):
175173
"""\
176174
# Foo
177175
178-
The build failed before running any tests. Click on the failure below to see the details.
176+
The build failed before running any tests. Click on a failure below to see the details.
179177
180178
<details>
181179
<summary>test/4.stamp</summary>
@@ -279,7 +277,7 @@ def test_no_failures_build_failed(self):
279277
280278
* 1 test passed
281279
282-
All tests passed but another part of the build **failed**. Detailed information about the build failure could not be automatically obtained.
280+
All tests passed but another part of the build **failed**. Information about the build failure could not be automatically obtained.
283281
284282
Download the build's log file to see the details.
285283

0 commit comments

Comments
 (0)