|
1 | 1 | import tempfile |
2 | 2 | from pathlib import Path |
3 | 3 |
|
4 | | -from mfc.test.coverage import is_always_run_all, load_map, param_hash, save_map |
| 4 | +from mfc.test.coverage import is_always_run_all, load_map, param_hash, save_map, select_tests |
5 | 5 |
|
6 | 6 |
|
7 | 7 | def test_param_hash_is_order_independent(): |
@@ -67,3 +67,55 @@ def test_ordinary_common_module_does_not_force_all(): |
67 | 67 |
|
68 | 68 | def test_ordinary_sim_module_does_not_force_all(): |
69 | 69 | assert not is_always_run_all({"src/simulation/m_rhs.fpp"}) |
| 70 | + |
| 71 | + |
| 72 | +class _Case: |
| 73 | + def __init__(self, ph, params=None): |
| 74 | + self._ph = ph |
| 75 | + self.params = params or {} |
| 76 | + |
| 77 | + def coverage_key(self): |
| 78 | + return self._ph |
| 79 | + |
| 80 | + |
| 81 | +def _cases(*phs): |
| 82 | + return [_Case(p) for p in phs] |
| 83 | + |
| 84 | + |
| 85 | +def test_rung1_no_changed_files_runs_all(): |
| 86 | + cases = _cases("a", "b") |
| 87 | + run, skip, reason = select_tests(cases, {"a": ["src/x.fpp"]}, None) |
| 88 | + assert len(run) == 2 and skip == [] and reason.startswith("rung1") |
| 89 | + |
| 90 | + |
| 91 | +def test_rung2_always_run_all(): |
| 92 | + cases = _cases("a", "b") |
| 93 | + run, skip, reason = select_tests(cases, {"a": [], "b": []}, {"CMakeLists.txt"}) |
| 94 | + assert len(run) == 2 and reason.startswith("rung2") |
| 95 | + |
| 96 | + |
| 97 | +def test_rung3_f90_change_runs_all(): |
| 98 | + cases = _cases("a") |
| 99 | + run, skip, reason = select_tests(cases, {"a": []}, {"src/common/m_precision_select.f90"}) |
| 100 | + assert len(run) == 1 and reason.startswith("rung3") |
| 101 | + |
| 102 | + |
| 103 | +def test_rung4_changed_fpp_with_zero_coverage_runs_all(): |
| 104 | + cases = _cases("a") |
| 105 | + # m_gpu_only.fpp is covered by no test in the map |
| 106 | + run, skip, reason = select_tests(cases, {"a": ["src/simulation/m_rhs.fpp"]}, {"src/simulation/m_gpu_only.fpp"}) |
| 107 | + assert len(run) == 1 and reason.startswith("rung4") |
| 108 | + |
| 109 | + |
| 110 | +def test_rung5_unmapped_test_is_included(): |
| 111 | + cases = _cases("a", "new") # 'new' not in map |
| 112 | + run, skip, _ = select_tests(cases, {"a": ["src/simulation/m_rhs.fpp"]}, {"src/simulation/m_rhs.fpp"}) |
| 113 | + assert {c.coverage_key() for c in run} == {"a", "new"} |
| 114 | + |
| 115 | + |
| 116 | +def test_rung6_and_7_overlap_selects_subset(): |
| 117 | + cases = _cases("hit", "miss") |
| 118 | + cov = {"hit": ["src/simulation/m_bubbles_EE.fpp"], "miss": ["src/simulation/m_rhs.fpp"]} |
| 119 | + run, skip, _ = select_tests(cases, cov, {"src/simulation/m_bubbles_EE.fpp"}) |
| 120 | + assert [c.coverage_key() for c in run] == ["hit"] |
| 121 | + assert [c.coverage_key() for c in skip] == ["miss"] |
0 commit comments