Check if test result is cached and test can be skipped (stdlib only). Verifies that: 1. Test result cache file exists 2. Test artifact (DLL/SO) file exists 3. Cached result was "pass" 4. Artifact hasn't been recompiled since cache write Mirrors ci/meson/cache_utils.
(build_dir: Path, test_name: str, artifact_path: Path)
| 240 | |
| 241 | |
| 242 | def test_cached(build_dir: Path, test_name: str, artifact_path: Path) -> bool: |
| 243 | """Check if test result is cached and test can be skipped (stdlib only). |
| 244 | |
| 245 | Verifies that: |
| 246 | 1. Test result cache file exists |
| 247 | 2. Test artifact (DLL/SO) file exists |
| 248 | 3. Cached result was "pass" |
| 249 | 4. Artifact hasn't been recompiled since cache write |
| 250 | |
| 251 | Mirrors ci/meson/cache_utils.check_test_result_cached() without importing |
| 252 | that module. |
| 253 | |
| 254 | Args: |
| 255 | build_dir: Meson build directory. |
| 256 | test_name: Test name (e.g. "fl_alloca"). |
| 257 | artifact_path: Path to test artifact (DLL or SO file). |
| 258 | |
| 259 | Returns: |
| 260 | True if test result is cached and artifact hasn't changed, |
| 261 | False if test needs to be re-run. |
| 262 | """ |
| 263 | cache_file = build_dir / ".test_result_cache.json" |
| 264 | if not cache_file.exists() or not artifact_path.exists(): |
| 265 | return False |
| 266 | try: |
| 267 | with open(cache_file, "r", encoding="utf-8") as f: |
| 268 | cache = json.load(f) |
| 269 | entry = cache.get(test_name) |
| 270 | if not entry or entry.get("result") != "pass": |
| 271 | return False |
| 272 | if ( |
| 273 | abs(artifact_path.stat().st_mtime - entry.get("artifact_mtime", -1.0)) |
| 274 | > 0.001 |
| 275 | ): |
| 276 | return False |
| 277 | return True |
| 278 | except (OSError, json.JSONDecodeError, KeyError, TypeError, ValueError): |
| 279 | return False |
| 280 | |
| 281 | |
| 282 | def full_run_cache( |
no test coverage detected