-
Notifications
You must be signed in to change notification settings - Fork 1
/
summary.gawk
71 lines (62 loc) · 1.89 KB
/
summary.gawk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-FileCopyrightText: 2022-2024 Paul Colby <[email protected]>
# SPDX-License-Identifier: MIT
#
# Summarise a set of QTest TAP (Test Anything Protocol) output files as a
# GitHub Flavored Markdown table. Typical usage is something like:
#
# testFoo -o foo.tap,tap -o -,txt
# testBar -o bar.tap,tap -o -,txt
# ...
# gawk --file summary.gawk --sandbox *.tap >> $GITHUB_STEP_SUMMARY
#
BEGIN {
RS="\r?\n" # Allow both DOS and *nix line endings.
IGNORECASE = 1 # Non-zero number means yes.
maxNameLength = 0
}
# Reset the test name at the beginning of each TAP file.
BEGINFILE {
testName=""
}
# If we have test results, and no test name yet, default to the current TAP file name.
/^(not )?ok .*/ && !testName {
name=FILENAME
sub("^.*/", "", name)
sub(".tap$", "", name)
setTestName(name)
}
# QtTest sets the test name on the second line of the TAP file.
FNR==2 && NF==2 && $1=="#" {
setTestName($2)
}
function setTestName(name) {
testName=name
if (length(testName) > maxNameLength)
maxNameLength = length(testName)
}
# Handle skipped tests.
/^ok .*[^\\]#\s*SKIP/ {
tests[testName]["skip"]++
}
# Handle passed (but not skipped) tests.
/^ok / && !/^ok .*[^\\]#\s*SKIP/ {
tests[testName]["pass"]++
}
# Handle failed tests.
/^not ok / {
tests[testName]["fail"]++
}
END {
nameDashes = "-"
while (length(nameDashes) < maxNameLength) nameDashes = nameDashes "-"
printf "| Test result | Passed | Failed | Skipped | %-*s |\n", maxNameLength, "Test name"
printf "|:------------------------|-------:|-------:|--------:|:%*s-|\n", maxNameLength, nameDashes
PROCINFO["sorted_in"] = "@ind_str_asc"
for (name in tests) {
printf "| %-18s %4s | %6u | %6u | %7u | %-*s |\n",
(tests[name]["fail"]) ? ":x:" : ":heavy_check_mark:",
(tests[name]["fail"]) ? "fail" : "pass",
tests[name]["pass"], tests[name]["fail"], tests[name]["skip"],
maxNameLength, name
}
}