| 1 | from pathlib import Path |
| 2 | import subprocess |
| 3 | import unittest |
| 4 | from unittest.mock import patch |
| 5 | |
| 6 | import run_rust |
| 7 | |
| 8 | |
| 9 | class 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_cargo_contract(self): |
| 52 | args = run_rust.command(Path("tests/example/Cargo.toml"), "test") |
| 53 | self.assertIn("--locked", args) |
| 54 | self.assertIn("--all-features", args) |
| 55 | self.assertEqual(args[-2:], ["--", "--test-threads=1"]) |
| 56 | |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | unittest.main() |