#!/usr/bin/env python3 """Summarise an NUnit results file and exit non-zero if anything failed. Unity's own docs state there is no common exit-code definition across the components under test, so the results XML is the authority, not $?. """ import sys import xml.etree.ElementTree as ET def main(path): try: root = ET.parse(path).getroot() except FileNotFoundError: print(f"no results at {path} — the run did not get far enough to write one") return 1 except ET.ParseError as exc: print(f"could not parse {path}: {exc}") return 1 total = int(root.get("total") or 0) passed = int(root.get("passed") or 0) failed = int(root.get("failed") or 0) skipped = int(root.get("skipped") or 0) for case in root.iter("test-case"): if case.get("result") == "Passed": continue print(f"FAIL {case.get('fullname')}") message = case.find("failure/message") if message is not None and message.text: for line in message.text.strip().splitlines()[:6]: print(f" {line}") if total == 0: print("no tests ran") else: print(f"{passed}/{total} passed" + (f", {skipped} skipped" if skipped else "")) return 1 if failed else 0 if __name__ == "__main__": sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else ".test-results/editmode.xml"))