blob: 9c0a5c411b08e497682d8ab911117a684e76e39e [file] [log] [blame]
Anders Roxell65be7682022-12-08 12:02:43 +01001#!/usr/bin/env python3
2import sys
3import re
4
5
6def slugify(line):
7 non_ascii_pattern = r"[^A-Za-z0-9_-]+"
8 line = re.sub(r"\[\d{1,5}\]", "", line)
9 return re.sub(
10 r"_-", "_", re.sub(r"(^_|_$)", "", re.sub(non_ascii_pattern, "_", line))
11 )
12
13
14tests = ""
15for line in sys.stdin:
16 if "# selftests: " in line:
17 tests = slugify(line.replace("\n", "").split("selftests:")[1])
18 elif re.search(r"^.*?not ok \d{1,5} ", line):
19 match = re.match(r"^.*?not ok (.*?)$", line)
20 ascii_test_line = slugify(re.sub("# .*$", "", match.group(1)))
21 if f"selftests_{tests}" in output:
22 output = re.sub(r"^.*_selftests_", "", output)
23 print(f"{output}")
24 elif re.search(r"^.*?ok \d{1,5} ", line):
25 match = re.match(r"^.*?ok (.*?)$", line)
26 if "# SKIP" in match.group(1):
27 ascii_test_line = slugify(re.sub("# SKIP", "", match.group(1)))
28 output = f"{tests}_{ascii_test_line} skip"
29 else:
30 ascii_test_line = slugify(match.group(1))
31 output = f"{tests}_{ascii_test_line} pass"
32 if f"selftests_{tests}" in output:
33 output = re.sub(r"^.*_selftests_", "", output)
34 print(f"{output}")