-
Notifications
You must be signed in to change notification settings - Fork 384
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
[cmd] Parse command exits with error in case of duplicated suppress c… #3253
Merged
csordasmarton
merged 7 commits into
Ericsson:master
from
zomen2:fix_doubled_report_error
Jul 6, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47f060d
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 d007ab0
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 936f773
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 b09023e
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 41c3ad9
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 b800992
Modify suppress language parser to give back all comments fo further …
zomen2 5e67efb
[cmd] Parse command exits with error in case of duplicated suppress c…
zomen2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*duplicated_suppress.cpp | ||
-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
0c07579523063acece2d7aebd4357cac||suppress_export.cpp||foo1 simple||false_positive | ||
58b0efedaf67e081290e27c6caabce3f||suppress_export.cpp||foo2 simple||false_positive | ||
0b4a424e23295c1f133bf643006a8c1e||suppress_export.cpp||foo2 simple||false_positive | ||
4c3ca4953cad12c05eebfe6a71833880||suppress_export.cpp||foo3 simple||intentional | ||
d1551d7a120c30fadec6ac2e416705f5||suppress_export.cpp||foo3 simple||intentional | ||
26806cbc2fd851b977e4915eba75289e||suppress_export.cpp||foo4 simple||confirmed | ||
b14c948e6ae8e27e3a33b0ca898e98f1||suppress_export.cpp||foo4 simple||confirmed | ||
e5f1b57c0f5d41e95b1eb5bf2032aada||suppress_export.cpp||substring of the checker name||confirmed |
2 changes: 2 additions & 0 deletions
2
analyzer/tests/functional/suppress/suppress_already_confirmed.skip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*suppress_already_confirmed.cpp | ||
-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*suppress_duplicated_by_all.cpp | ||
-* |
2 changes: 2 additions & 0 deletions
2
analyzer/tests/functional/suppress/suppress_by_all_in_two_lines.skip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*suppress_duplicated_in_two_lines.cpp | ||
-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*suppress_export.cpp | ||
-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+*suppress_without_bug.cpp | ||
-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
""" | ||
Test source-code level suppression data writing to suppress file. | ||
""" | ||
|
||
|
||
import os | ||
import inspect | ||
import unittest | ||
|
||
from libtest import env, codechecker | ||
|
||
|
||
class TestSuppress(unittest.TestCase): | ||
""" | ||
Test source-code level suppression data writing to suppress file. | ||
""" | ||
|
||
def setUp(self): | ||
self._test_workspace = os.environ['TEST_WORKSPACE'] | ||
|
||
self._testproject_data = env.setup_test_proj_cfg(self._test_workspace) | ||
self.assertIsNotNone(self._testproject_data) | ||
|
||
self._test_project_path = self._testproject_data['project_path'] | ||
self._test_directory = os.path.dirname(os.path.abspath(inspect.getfile( | ||
inspect.currentframe()))) | ||
|
||
def test_source_suppress_export(self): | ||
""" | ||
Test exporting a source suppress comment automatically to file. | ||
""" | ||
|
||
generated_file = os.path.join(self._test_workspace, | ||
"generated.suppress") | ||
skip_file = os.path.join(self._test_directory, "suppress_export.skip") | ||
|
||
extract_cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--suppress", generated_file, | ||
"--export-source-suppress", "--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
extract_cmd, self._test_project_path, | ||
env.test_env(self._test_directory)) | ||
self.assertEqual(ret, 2, "Failed to generate suppress file.") | ||
|
||
with open(generated_file, 'r', | ||
encoding='utf-8', errors='ignore') as generated: | ||
expected_file = os.path.join(self._test_directory, | ||
"suppress.expected") | ||
with open(expected_file, 'r', encoding='utf-8', | ||
errors='ignore') as expected: | ||
generated_content = generated.read() | ||
expected_content = expected.read() | ||
print("generated") | ||
print(generated_content) | ||
print("expected") | ||
print(expected_content) | ||
|
||
diff = set(expected_content).symmetric_difference( | ||
generated_content) | ||
print("difference") | ||
{print(elem) for elem in diff} | ||
self.assertEqual(len(diff), | ||
0, | ||
"The generated suppress file does not " | ||
"look like what was expected") | ||
|
||
def test_doubled_suppress(self): | ||
""" | ||
Test to catch repeated suppress comments with same bug. | ||
""" | ||
|
||
skip_file = os.path.join(self._test_directory, | ||
"duplicated_suppress.skip") | ||
|
||
cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
cmd, self._test_project_path, | ||
env.test_env(self._test_workspace)) | ||
self.assertEqual(ret, 1, "Repeated suppress comment not recognized.") | ||
|
||
def test_doubled_suppress_by_all(self): | ||
""" | ||
Test to catch multiple suppress comments in a line when "all" | ||
is one of them. | ||
""" | ||
|
||
skip_file = os.path.join(self._test_directory, "suppress_by_all.skip") | ||
|
||
cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
cmd, self._test_project_path, | ||
env.test_env(self._test_workspace)) | ||
self.assertEqual(ret, 1, "Already covered suppress comment not " | ||
"recognized.") | ||
|
||
def test_doubled_suppress_by_all_in_two_lines(self): | ||
""" | ||
Test to catch unnecessary suppress comment that was covered by a | ||
suppress all comment in the previous line. | ||
""" | ||
|
||
skip_file = os.path.join(self._test_directory, | ||
"suppress_by_all_in_two_lines.skip") | ||
|
||
cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
cmd, self._test_project_path, | ||
env.test_env(self._test_workspace)) | ||
self.assertEqual(ret, 1, "Already covered suppress comment not " | ||
"recognized.") | ||
|
||
def test_confirmed_already_suppressed(self): | ||
""" | ||
Test to catch unnecessary confirmed comment that was covered by a | ||
suppress all comment in the previous line. | ||
""" | ||
|
||
skip_file = os.path.join(self._test_directory, | ||
"suppress_already_confirmed.skip") | ||
|
||
cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
cmd, self._test_project_path, | ||
env.test_env(self._test_workspace)) | ||
self.assertEqual(ret, 1, "Already suppressed comment must not be " | ||
"confirmed.") | ||
|
||
def test_suppress_with_no_bug_is_ok(self): | ||
""" | ||
Test that the suppress comment that suppresses non existent bug does | ||
not cause fail. | ||
""" | ||
|
||
skip_file = os.path.join(self._test_directory, | ||
"suppress_without_bug.skip") | ||
|
||
cmd = [env.codechecker_cmd(), 'parse', | ||
os.path.join(self._test_workspace, "reports"), | ||
"--ignore", skip_file] | ||
|
||
_, _, ret = codechecker.call_command( | ||
cmd, self._test_project_path, | ||
env.test_env(self._test_workspace)) | ||
self.assertEqual(ret, 0, "Suppress without existent bug causes error.") |
88 changes: 0 additions & 88 deletions
88
analyzer/tests/functional/suppress/test_suppress_export.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
all: | ||
$(CXX) suppress.cpp | ||
$(CXX) suppress_export.cpp duplicated_suppress.cpp \ | ||
suppress_duplicated_by_all.cpp suppress_duplicated_in_two_lines.cpp \ | ||
suppress_already_confirmed.cpp suppress_without_bug.cpp | ||
|
||
clean: | ||
rm a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
int duplicatedSuppress(); | ||
|
||
int duplicatedSuppress() | ||
{ | ||
// codechecker_suppress [bugprone-sizeof-expression] Same suppress comment twice. | ||
// codechecker_suppress [core.DivideZero] Unmatching suppress comment. | ||
// codechecker_suppress [bugprone-sizeof-expression] Same suppress comment twice. | ||
return sizeof(42); | ||
} |
6 changes: 6 additions & 0 deletions
6
analyzer/tests/projects/suppress/suppress_already_confirmed.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
void suppressAlreadyDoneWithAnotherSuppressionType() | ||
{ | ||
// codechecker_suppress [clang-diagnostic-unused-value, bugprone-sizeof-expression] Suppress two bugs in the next C/C++ statement | ||
// codechecker_confirmed [bugprone-sizeof-expression] Already suppressed by the previous comment above | ||
sizeof(48); | ||
} |
5 changes: 5 additions & 0 deletions
5
analyzer/tests/projects/suppress/suppress_duplicated_by_all.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
void suppressDuplicatedByAll() | ||
{ | ||
// codechecker_suppress [all, bugprone-sizeof-expression] Comment already have included "all". The "bugprone sizeof expression" is an unnecessary duplication. | ||
sizeof(45); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is hardly connected to source file: https://github.com/zomen2/codechecker/blob/fix_doubled_report_error/analyzer/tests/projects/suppress/suppress_export.cpp
If we change the source file we need to change this file too. So it would be better to move this file back to the original location beside the source file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this moment the test source does not allow this. A large refactor should be performed on function test code before your suggestion can be done.