diff --git a/scripts/coverage_gate.py b/scripts/coverage_gate.py index e7ed84d66a..d2038b1db1 100644 --- a/scripts/coverage_gate.py +++ b/scripts/coverage_gate.py @@ -24,7 +24,8 @@ def sweep_json(stdout): """The report line of `xcl shaders --direct --json` output (the last JSON line).""" - for line in reversed(stdout.splitlines()): + # Unicode line separators can occur inside JSON strings, including program names. + for line in reversed(stdout.split("\n")): line = line.strip() if line.startswith("{"): return json.loads(line) diff --git a/scripts/test_coverage_gate.py b/scripts/test_coverage_gate.py index 314e3916e8..ee4af931d7 100644 --- a/scripts/test_coverage_gate.py +++ b/scripts/test_coverage_gate.py @@ -63,6 +63,14 @@ def test_takes_the_last_json_line(self): out = "some progress\n" + json.dumps({"stages": STAGES, "all": {}}) + "\n" self.assertEqual(sweep_json(out)["stages"], STAGES) + def test_unicode_line_separators_in_report_strings(self): + for separator in ("\u0085", "\u2028", "\u2029"): + with self.subTest(separator=repr(separator)): + report = run() + report["unsupported"] = [{"example": f"dir{separator}name.dxbc FSSM#0"}] + out = "progress\r\n" + json.dumps(report, ensure_ascii=False) + "\r\n" + self.assertEqual(sweep_json(out), report) + def test_raises_without_a_report(self): with self.assertRaises(ValueError): sweep_json("no json here")