diff options
| author | evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> | 2026-11-23 15:06:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 08:06:41 -0600 |
| commit | 94083ce36378bdae7e202b000f7e19602a6a6963 (patch) | |
| tree | 9adeaaaf6dc579d362dbf8d3b9d96c0c3e47c3cc /scripts/ci_expected_failures.py | |
| parent | 72bf7aeef4905f997f5b96367aac7c3307d5d74b (diff) | |
ci_expected_failures: --help works and a bad argument is one error line with exit 2 (EGEN-CIEXPECTED-CLI) (#6320)
Squash-merged after review of PR #6320 - ci_expected_failures: --help works and a bad argument is one error line with exit 2 (EGEN-CIEXPECTED-CLI)
Diffstat (limited to 'scripts/ci_expected_failures.py')
| -rw-r--r-- | scripts/ci_expected_failures.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/scripts/ci_expected_failures.py b/scripts/ci_expected_failures.py index b07b8de3c..2e8fafb20 100644 --- a/scripts/ci_expected_failures.py +++ b/scripts/ci_expected_failures.py | |||
| @@ -4,8 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | FAILED_LIST is a file with one failed test name per line, EXIT_STATUS the test runner's exit status, and each | 5 | FAILED_LIST is a file with one failed test name per line, EXIT_STATUS the test runner's exit status, and each |
| 6 | EXPECTED argument one or more whitespace-separated test names (so a workflow can pass one quoted list). Exits 1 when a | 6 | EXPECTED argument one or more whitespace-separated test names (so a workflow can pass one quoted list). Exits 1 when a |
| 7 | test outside EXPECTED failed, or when the runner failed without naming a test (a crash, a build error). An expected | 7 | test outside EXPECTED failed, or when the runner failed without naming a test (a crash, a build error); 2 on a usage |
| 8 | failure that passed gets a GitHub Actions notice, so the list in the workflow can shrink. | 8 | error, including a non-integer EXIT_STATUS or a FAILED_LIST that cannot be read, reported as one line. `--help` prints |
| 9 | this text. An expected failure that passed gets a GitHub Actions notice, so the list in the workflow can shrink. | ||
| 9 | """ | 10 | """ |
| 10 | 11 | ||
| 11 | import sys | 12 | import sys |
| @@ -26,13 +27,25 @@ def judge(failed: list[str], status: int, expected: list[str]) -> tuple[int, lis | |||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | def main(argv: list[str]) -> int: | 29 | def main(argv: list[str]) -> int: |
| 30 | if argv and argv[0] in ("-h", "--help"): | ||
| 31 | print(__doc__.strip()) | ||
| 32 | return 0 | ||
| 29 | if len(argv) < 2: | 33 | if len(argv) < 2: |
| 30 | print(__doc__.strip(), file=sys.stderr) | 34 | print(__doc__.strip(), file=sys.stderr) |
| 31 | return 2 | 35 | return 2 |
| 32 | with open(argv[0], encoding="utf-8") as f: | 36 | try: |
| 33 | failed = [line.strip() for line in f if line.strip()] | 37 | status = int(argv[1]) |
| 38 | except ValueError: | ||
| 39 | print(f"ci_expected_failures: EXIT_STATUS {argv[1]!r} is not an integer", file=sys.stderr) | ||
| 40 | return 2 | ||
| 41 | try: | ||
| 42 | with open(argv[0], encoding="utf-8") as f: | ||
| 43 | failed = [line.strip() for line in f if line.strip()] | ||
| 44 | except OSError as e: | ||
| 45 | print(f"ci_expected_failures: {argv[0]}: {e.strerror or e}", file=sys.stderr) | ||
| 46 | return 2 | ||
| 34 | expected = [name for arg in argv[2:] for name in arg.split()] | 47 | expected = [name for arg in argv[2:] for name in arg.split()] |
| 35 | code, lines = judge(failed, int(argv[1]), expected) | 48 | code, lines = judge(failed, status, expected) |
| 36 | print("\n".join(lines)) | 49 | print("\n".join(lines)) |
| 37 | return code | 50 | return code |
| 38 | 51 | ||