Skip to content

Commit 9811cfc

Browse files
committed
fix(test): ALWAYS_RUN_ALL covers test/run infra; cases.py runs new tests via rung 5 (soundness)
1 parent f7a692f commit 9811cfc

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

toolchain/mfc/test/coverage.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,27 @@ def save_map(path: Path, entries: dict, *, n_tests: int, git_sha: str, gfortran_
3939
json.dump(payload, f, indent=2, sort_keys=True)
4040

4141

42-
ALWAYS_RUN_ALL_EXACT = frozenset(["CMakeLists.txt"])
42+
# Test-definition file: changing it adds/modifies tests, but only the tests it touches
43+
# (their param_hash changes -> not in map -> rung 5 runs them). NOT in ALWAYS_RUN_ALL so a
44+
# test addition doesn't blanket-run the whole suite.
45+
CASES_PY = "toolchain/mfc/test/cases.py"
46+
47+
ALWAYS_RUN_ALL_EXACT = frozenset(
48+
[
49+
"CMakeLists.txt",
50+
# Toolchain infra that affects EVERY test's generation/execution -> run all.
51+
"toolchain/mfc/test/case.py", # TestCase: how a case runs
52+
"toolchain/mfc/test/test.py", # the test runner
53+
"toolchain/mfc/test/coverage.py", # the selector itself
54+
"toolchain/mfc/test/coverage_build.py", # the map collector
55+
]
56+
)
4357
ALWAYS_RUN_ALL_PREFIXES = (
4458
"src/common/include/", # GPU/Fypp macro & include files (CPU map can't line-attribute)
4559
"toolchain/cmake/", # build system
4660
"toolchain/mfc/params/", # parameter codegen -> emits Fortran broadly
4761
"toolchain/bootstrap/", # build/run scripts
62+
"toolchain/mfc/run/", # .inp generation / case dicts -> affects every test's input
4863
)
4964

5065

@@ -102,8 +117,11 @@ def select_tests(cases, coverage_map, changed_files):
102117
return list(cases), [], "rung3: hand-written .f90/.f changed"
103118

104119
changed_fpp = {f for f in changed_files if f.endswith(".fpp")}
105-
if not changed_fpp:
106-
return [], list(cases), "rung7: no Fortran source changed"
120+
# Skip-all only when nothing test-relevant changed. If cases.py changed (no .fpp), fall
121+
# through to per-test: new/modified tests have a fresh param_hash absent from the map and
122+
# run via rung 5; unchanged tests have no .fpp overlap and are skipped.
123+
if not changed_fpp and CASES_PY not in changed_files:
124+
return [], list(cases), "rung7: no Fortran or test-definition change"
107125

108126
# Rung 4: a changed .fpp that no test covers -> run all (GPU-only blind spot).
109127
covered = _covered_fpp(coverage_map)

toolchain/mfc/test/test_coverage_unit.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,27 @@ def fail_git(cmd, **kw):
279279
with patch("subprocess.run", fail_git):
280280
assert get_changed_files("/r", "master", explicit="") is None
281281
assert get_changed_files("/r", "master", explicit=" , ") is None
282+
283+
284+
def test_run_and_test_infra_force_all():
285+
assert is_always_run_all({"toolchain/mfc/run/input.py"})
286+
assert is_always_run_all({"toolchain/mfc/test/case.py"})
287+
assert is_always_run_all({"toolchain/mfc/test/test.py"})
288+
289+
290+
def test_cases_py_is_not_always_run():
291+
assert not is_always_run_all({"toolchain/mfc/test/cases.py"})
292+
293+
294+
def test_cases_py_change_runs_new_tests_not_skipall():
295+
# cases.py-only change must run the NEW/modified tests (rung 5), not skip everything.
296+
cases = _cases("mapped", "newtest") # "newtest" absent from map
297+
run, skip, _ = select_tests(cases, {"mapped": ["src/simulation/m_rhs.fpp"]}, {"toolchain/mfc/test/cases.py"})
298+
assert [c.coverage_key() for c in run] == ["newtest"]
299+
assert [c.coverage_key() for c in skip] == ["mapped"]
300+
301+
302+
def test_docs_only_still_skips_all():
303+
cases = _cases("a")
304+
run, skip, reason = select_tests(cases, {"a": ["src/x.fpp"]}, {"README.md"})
305+
assert run == [] and len(skip) == 1 and "rung7" in reason

0 commit comments

Comments
 (0)