|
4 | 4 | import subprocess |
5 | 5 | import sys |
6 | 6 |
|
| 7 | +from cpp_linter_hooks import util |
7 | 8 | from cpp_linter_hooks.util import ( |
8 | 9 | get_version_from_dependency, |
9 | 10 | _resolve_version, |
@@ -278,3 +279,42 @@ def test_resolve_install_with_none_default_version(): |
278 | 279 |
|
279 | 280 | # Should fallback to hardcoded version when DEFAULT is None |
280 | 281 | mock_install.assert_called_once_with("clang-format", None) |
| 282 | + |
| 283 | + |
| 284 | +@pytest.mark.benchmark |
| 285 | +def test_main_success(monkeypatch): |
| 286 | + # Patch _resolve_install to simulate success |
| 287 | + monkeypatch.setattr( |
| 288 | + "cpp_linter_hooks.util._resolve_install", |
| 289 | + lambda tool, version: "/usr/bin/clang-format", |
| 290 | + ) |
| 291 | + monkeypatch.setattr( |
| 292 | + sys, "argv", ["util.py", "--tool", "clang-format", "--version", "15.0.7"] |
| 293 | + ) |
| 294 | + exit_code = util.main() |
| 295 | + assert exit_code == 0 |
| 296 | + |
| 297 | + |
| 298 | +@pytest.mark.benchmark |
| 299 | +def test_main_failure(monkeypatch): |
| 300 | + # Patch _resolve_install to simulate failure |
| 301 | + monkeypatch.setattr( |
| 302 | + "cpp_linter_hooks.util._resolve_install", lambda tool, version: None |
| 303 | + ) |
| 304 | + monkeypatch.setattr( |
| 305 | + sys, "argv", ["util.py", "--tool", "clang-format", "--version", "99.99.99"] |
| 306 | + ) |
| 307 | + exit_code = util.main() |
| 308 | + assert exit_code == 1 |
| 309 | + |
| 310 | + |
| 311 | +@pytest.mark.benchmark |
| 312 | +def test_main_default_tool(monkeypatch): |
| 313 | + # Patch _resolve_install to simulate success for default tool |
| 314 | + monkeypatch.setattr( |
| 315 | + "cpp_linter_hooks.util._resolve_install", |
| 316 | + lambda tool, version: "/usr/bin/clang-format", |
| 317 | + ) |
| 318 | + monkeypatch.setattr(sys, "argv", ["util.py"]) |
| 319 | + exit_code = util.main() |
| 320 | + assert exit_code == 0 |
0 commit comments