Skip to content

Commit

Permalink
[cli] Fix skipping reports
Browse files Browse the repository at this point in the history
If a skip file was given to the `CodeChecker parse` command and one of
the mentioned file from the bug path was on the skip list we skipped that
report.

Example:
`main.cpp`:
```cpp
\#include "lib.h"

int main() {
  return foo(0);
}
```

`lib.h`:
```
double foo(int param) {
  return 1 / param;
}

```

`skip file content`:
```txt
+*/lib.h
-*
```

In this case if we analyzed this project and run on of the following
command, it returned with no results:
- `CodeChecker parse ./reports --skip skipfile.txt`
- `CodeChecker parse ./reports --file "*/lib.h"`

With this patch we will skip a report only if the last bug step is on the
skip list.
  • Loading branch information
csordasmarton committed Dec 20, 2021
1 parent ed16b5d commit aaa1fe6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 23 additions & 2 deletions analyzer/tests/functional/skip/test_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
of skipped reports from the report files.
"""


import json
import os
import plistlib
import subprocess
Expand All @@ -38,7 +38,7 @@ def setUp(self):
self.report_dir = os.path.join(self.test_workspace, "reports")
self.test_dir = os.path.join(os.path.dirname(__file__), 'test_files')

def __test_skip(self):
def test_skip(self):
"""Analyze a project with a skip file."""
test_dir = os.path.join(self.test_dir, "simple")
build_json = os.path.join(self.test_workspace, "build.json")
Expand Down Expand Up @@ -174,3 +174,24 @@ def test_analyze_only_header(self):
for f in report_dir_files]))
self.assertTrue(any(["b.cpp" in f
for f in report_dir_files]))

# Get reports only from the header file.
cmd = [
self._codechecker_cmd, "parse", self.report_dir,
"--file", "*/lib.h",
"--export", "json"]

process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=test_dir,
encoding="utf-8",
errors="ignore")
out, err = process.communicate()

errcode = process.returncode
self.assertEqual(errcode, 2)

data = json.loads(out)
self.assertTrue(len(data['reports']))
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,10 @@ def review_status(self) -> str:

def skip(self, skip_handler: Optional[SkipListHandler]) -> bool:
""" True if the report should be skipped. """
if skip_handler:
for file_path in self.original_files:
if skip_handler(file_path):
return True
if not skip_handler:
return False

return False
return skip_handler(self.file.original_path)

def to_json(self) -> Dict:
""" Creates a JSON dictionary. """
Expand Down

0 comments on commit aaa1fe6

Please sign in to comment.