| | @@ -1,4 +1,8 @@ |
| 1 | +추가: from contextlib import redirect_stdout |
| 2 | +추가: from io import StringIO |
| 3 | +추가: import json |
| 1 | 4 | from pathlib import Path |
| 5 | +추가: import tempfile |
| 2 | 6 | import subprocess |
| 3 | 7 | import unittest |
| 4 | 8 | from unittest.mock import patch |
| | @@ -76,6 +80,46 @@ class RunnerTests(unittest.TestCase): |
| 76 | 80 | self.assertEqual([row["status"] for row in results], ["passed", "failed"]) |
| 77 | 81 | self.assertEqual(results[1]["reason"], "missing linker") |
| 78 | 82 | |
| 83 | +추가: def test_self_check_failure_replaces_previous_success_report(self): |
| 84 | +추가: for phase, platform in (("local", "linux"), ("test", "win32")): |
| 85 | +추가: with self.subTest(phase=phase), tempfile.TemporaryDirectory( |
| 86 | +추가: dir=run_rust.ROOT / "tests/ci" |
| 87 | +추가: ) as directory: |
| 88 | +추가: root = Path(directory) |
| 89 | +추가: (root / "tests/ci").mkdir(parents=True) |
| 90 | +추가: report_path = root / f"tests/ci/{phase}-results.json" |
| 91 | +추가: with ( |
| 92 | +추가: patch.object(run_rust, "ROOT", root), |
| 93 | +추가: patch.object(run_rust.sys, "argv", ["run_rust.py", phase]), |
| 94 | +추가: patch.object(run_rust.sys, "platform", platform), |
| 95 | +추가: patch.dict(run_rust.os.environ, {"GITHUB_STEP_SUMMARY": ""}), |
| 96 | +추가: patch.object(run_rust.subprocess, "run", side_effect=[ |
| 97 | +추가: subprocess.CompletedProcess([], 0), |
| 98 | +추가: subprocess.CompletedProcess([], 7), |
| 99 | +추가: ]), |
| 100 | +추가: patch.object(run_rust.subprocess, "check_output", side_effect=[ |
| 101 | +추가: "successful-head\n", "failed-head\n", |
| 102 | +추가: ]), |
| 103 | +추가: patch.object(run_rust, "execute_phases", return_value=[ |
| 104 | +추가: {"phase": "test", "manifest": "sample", "status": "passed"}, |
| 105 | +추가: ]) as execute, |
| 106 | +추가: redirect_stdout(StringIO()), |
| 107 | +추가: ): |
| 108 | +추가: self.assertEqual(run_rust.main(), 0) |
| 109 | +추가: successful = json.loads(report_path.read_text(encoding="utf-8")) |
| 110 | +추가: self.assertEqual(successful["results"][0]["status"], "passed") |
| 111 | +추가: self.assertEqual(run_rust.main(), 7) |
| 112 | +추가: failed = json.loads(report_path.read_text(encoding="utf-8")) |
| 113 | +추가: self.assertEqual(failed["head"], "failed-head") |
| 114 | +추가: self.assertEqual(failed["results"], [{ |
| 115 | +추가: "phase": "self-check", |
| 116 | +추가: "manifest": "tests/ci", |
| 117 | +추가: "status": "failed", |
| 118 | +추가: "exit_code": 7, |
| 119 | +추가: }]) |
| 120 | +추가: self.assertFalse(failed["windows_runtime_tested"]) |
| 121 | +추가: execute.assert_called_once() |
| 122 | +추가: |
| 79 | 123 | def test_cargo_contract(self): |
| 80 | 124 | args = run_rust.command(Path("tests/example/Cargo.toml"), "test") |
| 81 | 125 | self.assertIn("--locked", args) |