Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] Fix skipping reports #3559

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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