|
1 | 1 | import tempfile |
| 2 | +import types as _types |
2 | 3 | from pathlib import Path |
| 4 | +from unittest.mock import patch |
3 | 5 |
|
4 | | -from mfc.test.coverage import is_always_run_all, load_map, param_hash, save_map, select_tests |
| 6 | +from mfc.test.coverage import get_changed_files, is_always_run_all, load_map, param_hash, save_map, select_tests |
5 | 7 |
|
6 | 8 |
|
7 | 9 | def test_param_hash_is_order_independent(): |
@@ -134,3 +136,35 @@ def test_case_coverage_key_ignores_trace(): |
134 | 136 | a = TestCase("1D -> Foo", {"m": 100}) |
135 | 137 | b = TestCase("totally -> different -> trace", {"m": 100}) |
136 | 138 | assert a.coverage_key() == b.coverage_key() |
| 139 | + |
| 140 | + |
| 141 | +def test_changed_files_prefers_explicit_list(): |
| 142 | + files = get_changed_files("/repo", "master", explicit="src/a.fpp\nsrc/b.fpp\n") |
| 143 | + assert files == {"src/a.fpp", "src/b.fpp"} |
| 144 | + |
| 145 | + |
| 146 | +def test_changed_files_deepens_then_recovers(): |
| 147 | + state = {"deepened": False} |
| 148 | + |
| 149 | + def fake_run(cmd, **kw): |
| 150 | + sub = cmd[1] if len(cmd) > 1 else "" |
| 151 | + if sub == "fetch": |
| 152 | + state["deepened"] = True |
| 153 | + return _types.SimpleNamespace(returncode=0, stdout="", stderr="") |
| 154 | + if sub == "merge-base": |
| 155 | + return _types.SimpleNamespace(returncode=0 if state["deepened"] else 1, stdout="base\n", stderr="") |
| 156 | + if sub == "diff": |
| 157 | + return _types.SimpleNamespace(returncode=0, stdout="src/x.fpp\n", stderr="") |
| 158 | + return _types.SimpleNamespace(returncode=0, stdout="", stderr="") |
| 159 | + |
| 160 | + with patch("subprocess.run", fake_run): |
| 161 | + assert get_changed_files("/repo", "master") == {"src/x.fpp"} |
| 162 | + |
| 163 | + |
| 164 | +def test_changed_files_returns_none_when_unrecoverable(): |
| 165 | + def fake_run(cmd, **kw): |
| 166 | + rc = 1 if (len(cmd) > 1 and cmd[1] == "merge-base") else 0 |
| 167 | + return _types.SimpleNamespace(returncode=rc, stdout="", stderr="boom") |
| 168 | + |
| 169 | + with patch("subprocess.run", fake_run): |
| 170 | + assert get_changed_files("/repo", "master") is None |
0 commit comments