diff options
Diffstat (limited to 'tests/test_first_light_harness_paths.py')
| -rw-r--r-- | tests/test_first_light_harness_paths.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_first_light_harness_paths.py b/tests/test_first_light_harness_paths.py index 58ab34800..438dce472 100644 --- a/tests/test_first_light_harness_paths.py +++ b/tests/test_first_light_harness_paths.py | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | """CPU-only checks for the first-light harness lookup.""" | 1 | """CPU-only checks for the first-light harness lookup.""" |
| 2 | 2 | ||
| 3 | import contextlib | ||
| 4 | import io | ||
| 3 | import os | 5 | import os |
| 4 | from pathlib import Path | 6 | from pathlib import Path |
| 5 | import sys | 7 | import sys |
| @@ -49,6 +51,50 @@ class FirstLightHarnessPathsTests(unittest.TestCase): | |||
| 49 | environment.unlink() | 51 | environment.unlink() |
| 50 | self.assertEqual(first_light.find_harness(None), str(configured)) | 52 | self.assertEqual(first_light.find_harness(None), str(configured)) |
| 51 | 53 | ||
| 54 | def put_sources(self) -> Path: | ||
| 55 | test = self.root / "runtime" / "test" | ||
| 56 | test.mkdir(parents=True, exist_ok=True) | ||
| 57 | (test / "vk_harness.cpp").write_text('#include "../src/table.h"\n', encoding="utf-8") | ||
| 58 | (self.root / "runtime" / "src").mkdir(exist_ok=True) | ||
| 59 | (self.root / "runtime" / "src" / "table.h").write_text("", encoding="utf-8") | ||
| 60 | return test | ||
| 61 | |||
| 62 | def find_with_stderr(self) -> tuple[str, str]: | ||
| 63 | err = io.StringIO() | ||
| 64 | with contextlib.redirect_stderr(err): | ||
| 65 | found = first_light.find_harness(None) | ||
| 66 | return found, err.getvalue() | ||
| 67 | |||
| 68 | def test_a_harness_older_than_its_sources_is_reported(self) -> None: | ||
| 69 | # Old #7148: a harness built before a pull drew with the old program and said nothing. | ||
| 70 | harness = self.put_harness("runtime", "build", "linux") | ||
| 71 | self.put_sources() | ||
| 72 | os.utime(harness, (1_000_000, 1_000_000)) | ||
| 73 | found, err = self.find_with_stderr() | ||
| 74 | self.assertEqual(found, str(harness)) | ||
| 75 | self.assertIn("WARNING", err) | ||
| 76 | self.assertIn("runtime/test/vk_harness.cpp", err) | ||
| 77 | self.assertIn("runtime/src/table.h", err) | ||
| 78 | self.assertIn("--target vk_harness", err) | ||
| 79 | |||
| 80 | def test_a_current_harness_is_used_quietly(self) -> None: | ||
| 81 | self.put_sources() | ||
| 82 | harness = self.put_harness("runtime", "build", "linux") | ||
| 83 | future = os.path.getmtime(self.root / "runtime" / "src" / "table.h") + 60 | ||
| 84 | os.utime(harness, (future, future)) | ||
| 85 | found, err = self.find_with_stderr() | ||
| 86 | self.assertEqual(found, str(harness)) | ||
| 87 | self.assertEqual(err, "") | ||
| 88 | |||
| 89 | def test_a_harness_outside_the_build_folder_is_not_compared(self) -> None: | ||
| 90 | self.put_sources() | ||
| 91 | explicit = self.put_harness("explicit") | ||
| 92 | os.utime(explicit, (1_000_000, 1_000_000)) | ||
| 93 | err = io.StringIO() | ||
| 94 | with contextlib.redirect_stderr(err): | ||
| 95 | self.assertEqual(first_light.find_harness(str(explicit)), str(explicit)) | ||
| 96 | self.assertEqual(err.getvalue(), "") | ||
| 97 | |||
| 52 | 98 | ||
| 53 | if __name__ == "__main__": | 99 | if __name__ == "__main__": |
| 54 | unittest.main() | 100 | unittest.main() |