diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ea0440005..4c2288a20c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -233,17 +233,22 @@ jobs: run: | python -m unittest discover -s tests/semantic > "$RUNNER_TEMP/semantic.log" 2>&1 & semantic=$! + failed=() while IFS= read -r t; do if grep -Eq "$PYTEST_FILE_MARKERS" "$t" || ! grep -q '__main__' "$t"; then continue fi echo "== $t" - python -I "$t" || exit 1 + python -I "$t" || failed+=("$t") done < <(find tests -path 'tests/semantic' -prune -o -type f -name 'test_*.py' -print | LC_ALL=C sort) status=0 wait "$semantic" || status=$? echo "== tests/semantic" cat "$RUNNER_TEMP/semantic.log" + if (( ${#failed[@]} )); then + for t in "${failed[@]}"; do echo "::error file=$t::$t failed"; done + status=1 + fi exit "$status" - name: Install llvm-mc and SPIRV-Tools run: | @@ -306,10 +311,15 @@ jobs: - name: Tests (standard library only, Linux) shell: bash run: | + failed=() while IFS= read -r t; do if grep -Eq "$PYTEST_FILE_MARKERS" "$t" || ! grep -q '__main__' "$t"; then continue fi echo "== $t" - python -I "$t" || exit 1 + python -I "$t" || failed+=("$t") done < <(find tests -path 'tests/semantic' -prune -o -type f -name 'test_*.py' -print | LC_ALL=C sort) + if (( ${#failed[@]} )); then + for t in "${failed[@]}"; do echo "::error file=$t::$t failed"; done + exit 1 + fi diff --git a/scripts/run_semantic_tests.py b/scripts/run_semantic_tests.py index 514e781330..f9b5e185cf 100644 --- a/scripts/run_semantic_tests.py +++ b/scripts/run_semantic_tests.py @@ -288,8 +288,9 @@ def main(argv=None): if __name__ == "__main__": - try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode + try: # a redirected stdout/stderr is strict ANSI code page under -I; write '?' for what it cannot encode sys.stdout.reconfigure(errors="replace") + sys.stderr.reconfigure(errors="replace") except (AttributeError, ValueError, OSError): pass try: diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index d360114303..ff49ba7e1d 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py @@ -604,4 +604,9 @@ def report(index: int) -> None: if __name__ == "__main__": + try: # a redirected stdout/stderr is strict ANSI code page under -I; write '?' for what it cannot encode + sys.stdout.reconfigure(errors="replace") + sys.stderr.reconfigure(errors="replace") + except (AttributeError, ValueError, OSError): + pass sys.exit(main()) diff --git a/tests/test_ci_registration.py b/tests/test_ci_registration.py index cb01dee81a..1f340230d8 100644 --- a/tests/test_ci_registration.py +++ b/tests/test_ci_registration.py @@ -682,6 +682,18 @@ def test_step_script_reads_the_check_loop(self): self.assertIn('python -I "$t"', script) self.assertIn("-name 'test_*.py'", script) + def test_linux_stdlib_step_collects_all_failures(self): + script = step_script(ROOT, "Tests (standard library only, Linux)") + self.assertIn('failed=()', script) + self.assertIn('python -I "$t" || failed+=("$t")', script) + self.assertIn('::error file=$t::$t failed', script) + + def test_macos_stdlib_step_collects_all_failures(self): + script = step_script(ROOT, "Translator semantic tests and tests (standard library only, no game data)") + self.assertIn('failed=()', script) + self.assertIn('python -I "$t" || failed+=("$t")', script) + self.assertIn('::error file=$t::$t failed', script) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_run_semantic_tests.py b/tests/test_run_semantic_tests.py index 7fc75e3722..987528402c 100644 --- a/tests/test_run_semantic_tests.py +++ b/tests/test_run_semantic_tests.py @@ -409,6 +409,11 @@ def test_posix_sigint_cancels_queued_modules_and_stops_runner(self): self.assertNotIn("5 files,", stdout) self.assertEqual(len(os.listdir(marker_dir)), 2) + def test_cli_reconfigures_streams_cleanly(self): + result = cli("unused-suite", "-h") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("Run the translator regression suite", result.stdout) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_run_wine_tests.py b/tests/test_run_wine_tests.py index 7ba55d2f8e..006d2046d5 100644 --- a/tests/test_run_wine_tests.py +++ b/tests/test_run_wine_tests.py @@ -900,6 +900,12 @@ def test_wine_quoting_is_still_split(self): with self.assertRaises(argparse.ArgumentTypeError): rwt.wine_command(" ") + def test_cli_help_under_python_isolated(self): + result = subprocess.run([sys.executable, "-I", str(Path(rwt.__file__).resolve()), "--help"], + capture_output=True, text=True, timeout=15) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("Run the Windows build's CTest tests under Wine", result.stdout) + if __name__ == "__main__": unittest.main()