|
1 | 1 | # python -m pytest gitlab_code_quality_test.py |
2 | 2 |
|
3 | 3 | import json |
| 4 | +import os |
4 | 5 |
|
5 | 6 | from testutils import cppcheck |
6 | 7 |
|
@@ -45,3 +46,46 @@ def test_gitlab_code_quality_output_file(tmp_path): |
45 | 46 | findings = json.loads((tmp_path / "report.json").read_text()) |
46 | 47 | assert len(findings) == 1 |
47 | 48 | assert findings[0]["check_name"] == "zerodiv" |
| 49 | + |
| 50 | + |
| 51 | +def test_gitlab_code_quality_absolute_path_warning(tmp_path): |
| 52 | + test_file = tmp_path / "test.cpp" |
| 53 | + test_file.write_text(TEST_CODE) |
| 54 | + |
| 55 | + exitcode, stdout, stderr = cppcheck( |
| 56 | + ["--output-format=gitlab-codequality", "--enable=warning", str(test_file)]) |
| 57 | + |
| 58 | + assert exitcode == 0 |
| 59 | + assert "GitLab Code Quality requires repository-relative paths" in stdout |
| 60 | + findings = json.loads(stderr) |
| 61 | + assert len(findings) == 1 |
| 62 | + assert os.path.isabs(findings[0]["location"]["path"]) |
| 63 | + |
| 64 | + |
| 65 | +def test_gitlab_code_quality_absolute_path_warning_with_relative_paths(tmp_path): |
| 66 | + test_file = tmp_path / "test.cpp" |
| 67 | + test_file.write_text(TEST_CODE) |
| 68 | + |
| 69 | + exitcode, stdout, stderr = cppcheck( |
| 70 | + ["--output-format=gitlab-codequality", "--enable=warning", "--relative-paths", str(test_file)]) |
| 71 | + |
| 72 | + assert exitcode == 0 |
| 73 | + assert "GitLab Code Quality requires repository-relative paths" in stdout |
| 74 | + findings = json.loads(stderr) |
| 75 | + assert len(findings) == 1 |
| 76 | + assert os.path.isabs(findings[0]["location"]["path"]) |
| 77 | + |
| 78 | + |
| 79 | +def test_gitlab_code_quality_relative_paths(tmp_path): |
| 80 | + test_file = tmp_path / "test.cpp" |
| 81 | + test_file.write_text(TEST_CODE) |
| 82 | + |
| 83 | + exitcode, stdout, stderr = cppcheck( |
| 84 | + ["--output-format=gitlab-codequality", "--enable=warning", |
| 85 | + "--relative-paths=" + str(tmp_path), str(test_file)]) |
| 86 | + |
| 87 | + assert exitcode == 0 |
| 88 | + assert "GitLab Code Quality requires repository-relative paths" not in stdout |
| 89 | + findings = json.loads(stderr) |
| 90 | + assert len(findings) == 1 |
| 91 | + assert findings[0]["location"]["path"] == "test.cpp" |
0 commit comments