Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/coverage_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def main(argv=None):
if args.threads:
cmd += ["--threads", str(args.threads)]
proc = subprocess.run(cmd, capture_output=True, text=True)
if proc.returncode != 0:
print(f"sweep exited with code {proc.returncode}\n{proc.stderr[-2000:]}", file=sys.stderr)
return 2
try:
run = sweep_json(proc.stdout)
except ValueError as e:
Expand Down
26 changes: 25 additions & 1 deletion scripts/test_coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import io
import json
import subprocess
import tempfile
import unittest
from contextlib import redirect_stderr
from pathlib import Path
from unittest.mock import patch

from coverage_gate import compare, sweep_json
from coverage_gate import compare, main, sweep_json

STAGES = {
"CS": {"total": 100, "translated": 95, "unsupported": 5, "validator_failed": 0, "panicked": 0, "timeout": 0},
Expand Down Expand Up @@ -68,5 +73,24 @@ def test_raises_without_a_report(self):
sweep_json("no json here")


class FailedSweepTests(unittest.TestCase):
def test_nonzero_exit_rejects_valid_report_and_preserves_baseline(self):
report = json.dumps(run(CS={"total": 95, "unsupported": 0}))
failed = subprocess.CompletedProcess(["xcl"], 7, stdout=report, stderr="worker failed")
with tempfile.TemporaryDirectory() as directory:
baseline = Path(directory) / "baseline.json"
original = json.dumps(run()).encode("utf-8")
for options in ([], ["--update"]):
with self.subTest(options=options), patch("coverage_gate.subprocess.run", return_value=failed):
baseline.write_bytes(original)
errors = io.StringIO()
with redirect_stderr(errors):
code = main(["--xcl", "xcl", "--rpf", "pack", "--baseline", str(baseline), *options])
self.assertEqual(baseline.read_bytes(), original)
self.assertEqual(code, 2)
self.assertIn("7", errors.getvalue())
self.assertIn("worker failed", errors.getvalue())


if __name__ == "__main__":
unittest.main()
Loading