()
| 69 | |
| 70 | |
| 71 | def main() -> int: |
| 72 | parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) |
| 73 | for flag in ("previous", "fresh", "suites", "commit", "out"): |
| 74 | parser.add_argument("--" + flag, required=True) |
| 75 | args = parser.parse_args() |
| 76 | |
| 77 | _, fresh_lines = read_functions(os.path.join(args.fresh, "functions.tsv")) |
| 78 | fresh_by_id, _ = read_functions(os.path.join(args.fresh, "functions.tsv")) |
| 79 | previous_by_id, _ = read_functions(os.path.join(args.previous, "functions.tsv")) |
| 80 | fresh_ids = {key: ident for ident, key in fresh_by_id.items()} |
| 81 | with open(os.path.join(args.fresh, "meta.json"), encoding="utf-8") as handle: |
| 82 | fresh_meta = json.load(handle) |
| 83 | with open(os.path.join(args.previous, "meta.json"), encoding="utf-8") as handle: |
| 84 | previous_meta = json.load(handle) |
| 85 | with open(args.suites, encoding="utf-8") as handle: |
| 86 | listed = [line.strip() for line in handle if line.strip()] |
| 87 | |
| 88 | fresh_rows = read_tests(os.path.join(args.fresh, "tests.tsv")) |
| 89 | previous_rows = read_tests(os.path.join(args.previous, "tests.tsv")) |
| 90 | rerun = {row[0] for row in fresh_rows} |
| 91 | if not rerun <= set(listed): |
| 92 | fail("a re-run suite is not listed by the new runner") |
| 93 | |
| 94 | merged = [row for row in fresh_rows] |
| 95 | for suite, test, status, reason, ids in previous_rows: |
| 96 | if suite in rerun or suite not in listed: |
| 97 | continue |
| 98 | mapped = sorted({fresh_ids[previous_by_id[i]] for i in ids |
| 99 | if i in previous_by_id and previous_by_id[i] in fresh_ids}) |
| 100 | merged.append((suite, test, status, reason, mapped)) |
| 101 | merged.sort(key=lambda row: (row[0], row[1])) |
| 102 | |
| 103 | suite_meta = {entry["suite"]: entry for entry in previous_meta.get("suites", [])} |
| 104 | for entry in fresh_meta.get("suites", []): |
| 105 | suite_meta[entry["suite"]] = entry |
| 106 | counts: dict[str, list[int]] = {} |
| 107 | for suite, test, status, _, _ in merged: |
| 108 | tally = counts.setdefault(suite, [0, 0]) |
| 109 | if test != SETUP: |
| 110 | tally[0] += 1 |
| 111 | tally[1] += status != "complete" |
| 112 | suites = [] |
| 113 | for suite in sorted(counts): |
| 114 | entry = dict(suite_meta.get(suite, {"suite": suite, "exit": 0})) |
| 115 | entry["tests"], entry["incomplete"] = counts[suite] |
| 116 | suites.append(entry) |
| 117 | |
| 118 | os.makedirs(args.out, exist_ok=True) |
| 119 | with open(os.path.join(args.out, "functions.tsv"), "w", encoding="utf-8", newline="\n") as handle: |
| 120 | handle.write("".join(line + "\n" for line in fresh_lines)) |
| 121 | with open(os.path.join(args.out, "tests.tsv"), "w", encoding="utf-8", newline="\n") as handle: |
| 122 | for suite, test, status, reason, ids in merged: |
| 123 | handle.write(f"{suite}:{test}\t{status}\t{reason}\t{' '.join(map(str, ids))}\n") |
| 124 | meta = dict(fresh_meta) |
| 125 | meta.update({"commit": args.commit, "tests": sum(c[0] for c in counts.values()), |
| 126 | "incomplete": sum(c[1] for c in counts.values()), "suites": suites}) |
| 127 | with open(os.path.join(args.out, "meta.json"), "w", encoding="utf-8", newline="\n") as handle: |
| 128 | json.dump(meta, handle, indent=1) |
no test coverage detected