Skip to content

Commit bc90629

Browse files
committed
Reformat test report output, blend spec + report in same section
Change disposition of the report from separate output and specification sections, to a combined specification, result and output for each test. This greatly improves the accessibility for the generated PDF, keeping all relevant information in one place, and eliminating the unintuitive link to the Test Specification from the output. Links are problematic in printed media. Each test's heading now includes colored PASS/FAIL/SKIP which lines up nicely in the generated Table of Contents, similar in fashion to how write_report_result_tree() already works. Several unicode symbols were tested instead of the spelled-out result, e.g., ☑ but the result was very difficult to read. The call to write_report_result_tree() is temporarily dropped in this commit, only to reintroduce it in the next in a new Test Info section under the Test Summary. Signed-off-by: Joachim Wiberg <[email protected]>
1 parent bf84347 commit bc90629

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

9pm.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -328,47 +328,53 @@ def write_report_result_tree(file, includes, data, depth):
328328

329329
string = f"{indent}"
330330
string += f"{stars}"
331-
string += f" [.{test['result']}]#{test['result'].upper()}#"
331+
string += f" {resultfmt(test)}"
332332
if 'outfile' in test:
333333
string += f" <<output-{test['name']},{test['name']}>>"
334334
else:
335335
string += f" {test['name']}"
336336

337-
# Append (Spec) if there's a test specification
338-
if 'test-spec-sha' in test:
339-
string += f" <<incl-{test['test-spec-sha']},(Spec)>>"
340-
341337
file.write(f"{string}\n")
342338

343339
if 'suite' in test:
344340
write_report_result_tree(file, includes, test, depth + 1)
345341

346-
def write_report_output(file, data, depth):
347-
for test in data['suite']:
342+
def resultfmt(test):
343+
result = test.get('result', 'unknown')
344+
if result == 'masked-fail':
345+
return "[.fail line-through]#FAIL#"
346+
elif result == 'masked-skip':
347+
return "[.skip line-through]#SKIP#"
348+
else:
349+
return f"[.{result}]#{result.upper()}#"
348350

351+
def write_report_output(file, data, depth, is_first=True):
352+
"""For each test in suite, write specification¹, result, and output"""
353+
for test in data['suite']:
349354
if 'outfile' in test:
350-
file.write(f"\n=== {test['name']}\n")
351-
352-
if 'test-spec-sha' in test:
353-
file.write(f"\n<<incl-{test['test-spec-sha']},Test Specification>>\n")
355+
# Add page break before each test, except first one
356+
if is_first:
357+
is_first = False
358+
else:
359+
file.write("\n<<<\n")
354360

361+
# Test heading is always from 'name:' in the suite file
355362
file.write(f"\n[[output-{test['name']}]]\n")
356-
file.write(f"----\n")
357-
file.write(f"include::{test['outfile']}[]\n")
358-
file.write(f"----\n")
363+
file.write(f"\n=== {resultfmt(test)} {test['name']}\n")
359364

360-
if 'suite' in test:
361-
write_report_output(file, test, depth + 1)
365+
# Skip headnig from test spec.
366+
if 'test-spec' in test:
367+
file.write("include::{}[lines=2..-1]\n" . format(test['test-spec']))
362368

363-
def write_report_specifications(file, data, depth):
364-
for test in data['suite']:
365-
366-
if 'test-spec-sha' in test:
367-
file.write(f"\n[[incl-{test['test-spec-sha']}]]\n")
368-
file.write("include::{}[]\n" . format(test['test-spec']))
369+
file.write("\n==== Output\n")
370+
file.write("----\n")
371+
file.write(f"include::{test['outfile']}[]\n")
372+
file.write("----\n")
369373

370374
if 'suite' in test:
371-
write_report_specifications(file, test, depth + 1)
375+
is_first = write_report_output(file, test, depth + 1, is_first)
376+
377+
return is_first
372378

373379
def write_report_project_info(file, config):
374380
if 'PROJECT-NAME' not in config or 'PROJECT-ROOT' not in config:
@@ -409,18 +415,8 @@ def write_report(data, config):
409415

410416
file.write("\n<<<\n")
411417
file.write("\n== Test Result\n\n")
412-
413-
includes = []
414-
write_report_result_tree(file, includes, data, 0)
415-
416-
file.write("\n<<<\n")
417-
file.write("\n== Test Output\n")
418418
write_report_output(file, data, 0)
419419

420-
file.write("\n<<<\n")
421-
file.write("\n== Test Specification\n")
422-
write_report_specifications(file, data, 0)
423-
424420

425421
def write_github_result_tree(file, data, depth):
426422
icon_map = {

0 commit comments

Comments
 (0)