team-ljyzipelo

공개
87줄3.5 KB
1from pathlib import Path
2import subprocess
3import unittest
4from unittest.mock import patch
5
6import run_rust
7
8
9class RunnerTests(unittest.TestCase):
10 def test_all_manifests_have_locks(self):
11 paths = run_rust.manifests(run_rust.ROOT)
12 expected = set(run_rust.ROOT.glob("experiments/*/Cargo.toml"))
13 expected |= set(run_rust.ROOT.glob("tests/*/Cargo.toml"))
14 self.assertEqual(set(paths), expected)
15
16 def test_failure_does_not_hide_later_crates(self):
17 paths = [
18 Path("/repo/experiments/a/Cargo.toml"),
19 Path("/repo/experiments/b/Cargo.toml"),
20 ]
21 with (
22 patch.object(run_rust, "manifests", return_value=paths),
23 patch.object(run_rust.subprocess, "run", side_effect=[
24 subprocess.CompletedProcess([], 7),
25 subprocess.CompletedProcess([], 0),
26 ]),
27 ):
28 results = run_rust.run(Path("/repo"), "build")
29 self.assertEqual([row["status"] for row in results], ["failed", "passed"])
30 self.assertEqual(results[0]["exit_code"], 7)
31
32 def test_windows_exclusion_is_explicit_and_only_for_linux_tests(self):
33 paths = [
34 Path("/repo/tests/rust-file-publication/Cargo.toml"),
35 Path("/repo/experiments/rust-file-publication/Cargo.toml"),
36 ]
37 with (
38 patch.object(run_rust, "manifests", return_value=paths),
39 patch.object(run_rust.sys, "platform", "win32"),
40 patch.object(
41 run_rust.subprocess, "run",
42 return_value=subprocess.CompletedProcess([], 0),
43 ) as execute,
44 ):
45 results = run_rust.run(Path("/repo"), "test")
46 self.assertEqual(
47 [row["status"] for row in results], ["not-applicable", "passed"]
48 )
49 self.assertEqual(execute.call_count, 1)
50
51 def test_fixture_bytes_match_git_blobs(self):
52 names = subprocess.check_output(
53 ["git", "ls-files", "-z", "tests/**/fixtures/*"], cwd=run_rust.ROOT
54 ).decode("utf-8").split("\0")
55 names = [name for name in names if name]
56 self.assertTrue(names, "검증할 fixture가 없음")
57 for name in names:
58 with self.subTest(path=name):
59 expected = subprocess.check_output(
60 ["git", "show", f"HEAD:{name}"], cwd=run_rust.ROOT
61 )
62 self.assertEqual((run_rust.ROOT / name).read_bytes(), expected)
63
64 def test_cross_build_never_executes_tests(self):
65 args = run_rust.command(Path("tests/example/Cargo.toml"), "cross-build")
66 self.assertEqual(args[2], "build")
67 self.assertIn(run_rust.WINDOWS_TARGET, args)
68 self.assertNotIn("--test-threads=1", args)
69
70 def test_preflight_failure_is_reported_without_hiding_other_phase(self):
71 with (
72 patch.object(run_rust, "prepare_cross_build", side_effect=ValueError("missing linker")),
73 patch.object(run_rust, "run", return_value=[{"manifest": "sample", "status": "passed"}]),
74 ):
75 results = run_rust.execute_phases(Path("/repo"), ["build", "cross-build"])
76 self.assertEqual([row["status"] for row in results], ["passed", "failed"])
77 self.assertEqual(results[1]["reason"], "missing linker")
78
79 def test_cargo_contract(self):
80 args = run_rust.command(Path("tests/example/Cargo.toml"), "test")
81 self.assertIn("--locked", args)
82 self.assertIn("--all-features", args)
83 self.assertEqual(args[-2:], ["--", "--test-threads=1"])
84
85
86if __name__ == "__main__":
87 unittest.main()