-
Notifications
You must be signed in to change notification settings - Fork 4
Add skip test #195
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
Merged
Merged
Add skip test #195
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,83 @@ | ||
| # Copyright 2023 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # cc_binary for simple C++ tests | ||
| load( | ||
| "@rules_cc//cc:defs.bzl", | ||
| "cc_library", | ||
| ) | ||
| load( | ||
| "//src:codechecker.bzl", | ||
| "codechecker_test", | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "simple_target", | ||
| srcs = [ | ||
| "main.cc", | ||
| "skip.cc", | ||
| "skip.h", | ||
| "skip2.cc", | ||
| "skip2.h", | ||
| ], | ||
| tags = ["manual"], | ||
| ) | ||
|
|
||
| # The monolithic rule uses codechecker's built in skipfile | ||
| # We expect that to be correct, further testing of it is unnecessary | ||
| codechecker_test( | ||
| name = "codechecker_skipfile", | ||
| skip = [ | ||
| "-*test/unit/skip/skip*", | ||
| ], | ||
| targets = [ | ||
| "simple_target", | ||
| ], | ||
| ) | ||
|
|
||
| codechecker_test( | ||
| name = "per_file_skipfile_exact_file_path", | ||
| per_file = True, | ||
| skip = [ | ||
| "-*test/unit/skip/skip.cc", | ||
| ], | ||
| tags = ["manual"], | ||
| targets = [ | ||
| "simple_target", | ||
| ], | ||
| ) | ||
|
|
||
| codechecker_test( | ||
| name = "per_file_skipfile_folder_skip_path", | ||
| per_file = True, | ||
| skip = [ | ||
| "-*test/*/skip.cc", | ||
| ], | ||
| tags = ["manual"], | ||
| targets = [ | ||
| "simple_target", | ||
| ], | ||
| ) | ||
|
|
||
| codechecker_test( | ||
| name = "per_file_skipfile_both_files", | ||
| per_file = True, | ||
| skip = [ | ||
| "-*test/unit/skip/skip*", | ||
| ], | ||
| tags = ["manual"], | ||
| targets = [ | ||
| "simple_target", | ||
| ], | ||
| ) |
This file contains hidden or 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,13 @@ | ||
| # Copyright 2023 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * Copyright 2023 Ericsson AB | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "skip.h" | ||
| #include "skip2.h" | ||
|
|
||
| int main(){ | ||
| skip_function(); | ||
| skip2_function(nullptr); | ||
| return 0; | ||
| } |
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * Copyright 2023 Ericsson AB | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "skip.h" | ||
|
|
||
| // cause a division by zero error | ||
| int skip_function() { | ||
| int zero = 0; | ||
| return 0 / zero; | ||
| } |
This file contains hidden or 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,22 @@ | ||
| /* | ||
| * Copyright 2023 Ericsson AB | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef SKIP_FUNCTION_H | ||
| #define SKIP_FUNCTION_H | ||
|
|
||
| int skip_function(); | ||
|
|
||
| #endif // SKIP_FUNCTION_H |
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2023 Ericsson AB | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <stdlib.h> | ||
| #include "skip2.h" | ||
|
|
||
| // cause a warning | ||
| int skip2_function(int* a) { | ||
| if(a == nullptr){ | ||
|
|
||
| } | ||
| int thing = *a; | ||
| return 0; | ||
| } |
This file contains hidden or 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,22 @@ | ||
| /* | ||
| * Copyright 2023 Ericsson AB | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef SKIP2_FUNCTION_H | ||
| #define SKIP2_FUNCTION_H | ||
|
|
||
| int skip2_function(int* a); | ||
|
|
||
| #endif // SKIP2_FUNCTION_H |
This file contains hidden or 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,108 @@ | ||
| # Copyright 2023 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Test the skip option for codechecker rules. | ||
| """ | ||
| import os | ||
| import unittest | ||
| from common.base import TestBase | ||
|
|
||
|
|
||
| class TestSkip(TestBase): | ||
| """Tests involving the skip argument of codechecker rules""" | ||
|
|
||
| # Set working directory | ||
| __test_path__ = os.path.dirname(os.path.abspath(__file__)) | ||
| BAZEL_BIN_DIR = os.path.join( | ||
| "../../..", "bazel-bin", "test", "unit", "skip" | ||
| ) | ||
| BAZEL_TESTLOGS_DIR = os.path.join( | ||
| "../../..", "bazel-testlogs", "test", "unit", "skip" | ||
| ) | ||
|
|
||
| def test_codechecker_skipfile(self): | ||
| """ | ||
| Test: bazel test //test/unit/skip:codechecker_skipfile | ||
| """ | ||
| ret, _, stderr = self.run_command( | ||
| "bazel test //test/unit/skip:codechecker_skipfile" | ||
| ) | ||
| self.assertEqual(ret, 0, stderr) | ||
|
|
||
| def test_per_file_skipfile_full_path(self): | ||
| """ | ||
| Test: bazel test //test/unit/skip:per_file_skipfile_exact_file_path | ||
| """ | ||
| ret, _, stderr = self.run_command( | ||
| "bazel test //test/unit/skip:per_file_skipfile_exact_file_path" | ||
| ) | ||
| self.assertEqual(ret, 3, stderr) | ||
| log_file = ( | ||
| f"{self.BAZEL_TESTLOGS_DIR}/" | ||
| "per_file_skipfile_exact_file_path/test.log" | ||
| ) | ||
| # FIXME: change to assertFalse, this file should be skipped | ||
| self.assertTrue( | ||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc") | ||
| ) | ||
| self.assertTrue( | ||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc") | ||
| ) | ||
|
|
||
| def test_per_file_skipfile_folder_skip_path(self): | ||
| """ | ||
| Test: bazel test //test/unit/skip:per_file_skipfile_folder_skip_path | ||
| """ | ||
| ret, _, stderr = self.run_command( | ||
| "bazel test //test/unit/skip:per_file_skipfile_folder_skip_path" | ||
| ) | ||
| self.assertEqual(ret, 3, stderr) | ||
| log_file = ( | ||
| f"{self.BAZEL_TESTLOGS_DIR}/" | ||
| "per_file_skipfile_folder_skip_path/test.log" | ||
| ) | ||
| # FIXME: change to assertFalse, this file should be skipped | ||
| self.assertTrue( | ||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc") | ||
| ) | ||
| # This is correct. | ||
| self.assertTrue( | ||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc") | ||
| ) | ||
|
|
||
| def test_per_file_skipfile_both_files(self): | ||
| """ | ||
| Test: bazel test //test/unit/skip:per_file_skipfile_both_files | ||
| """ | ||
| ret, _, stderr = self.run_command( | ||
| "bazel test //test/unit/skip:per_file_skipfile_both_files" | ||
| ) | ||
| # FIXME: The return code here should be 0, both files should be skipped | ||
| self.assertEqual(ret, 3, stderr) | ||
| log_file = ( | ||
| f"{self.BAZEL_TESTLOGS_DIR}/per_file_skipfile_both_files/test.log" | ||
| ) | ||
| # FIXME: Change to assertFalse after fix, should have been skipped. | ||
| self.assertTrue( | ||
|
furtib marked this conversation as resolved.
|
||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip.cc") | ||
| ) | ||
| # FIXME: Change to assertFalse after fix, should have been skipped. | ||
| self.assertTrue( | ||
|
furtib marked this conversation as resolved.
|
||
| self.contains_regex_in_file(log_file, r"defect\(s\) in skip2.cc") | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(buffer=True) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.