|
| 1 | +# Copyright 2023 Ericsson AB |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +""" |
| 16 | +Tests involving config files |
| 17 | +""" |
| 18 | +import os |
| 19 | +import unittest |
| 20 | +from typing import final |
| 21 | +from common.base import TestBase |
| 22 | + |
| 23 | + |
| 24 | +class TestConfig(TestBase): |
| 25 | + """Test whether config files are getting passed to CodeChecker correctly""" |
| 26 | + |
| 27 | + # Set working directory |
| 28 | + __test_path__ = os.path.dirname(os.path.abspath(__file__)) |
| 29 | + BAZEL_BIN_DIR = os.path.join( |
| 30 | + "../../..", "bazel-bin", "test", "unit", "config" |
| 31 | + ) |
| 32 | + BAZEL_TESTLOGS_DIR = os.path.join( |
| 33 | + "../../..", "bazel-testlogs", "test", "unit", "config" |
| 34 | + ) |
| 35 | + |
| 36 | + def test_codechecker_json(self): |
| 37 | + """Test: bazel build //test/unit/config:codechecker_json""" |
| 38 | + ret, _, _ = self.run_command( |
| 39 | + "bazel build //test/unit/config:codechecker_json" |
| 40 | + ) |
| 41 | + self.assertEqual(ret, 0) |
| 42 | + copied_config = os.path.join( |
| 43 | + self.BAZEL_BIN_DIR, # type: ignore |
| 44 | + "codechecker_json", |
| 45 | + "config.json" |
| 46 | + ) |
| 47 | + self.assertTrue(os.path.exists(copied_config)) |
| 48 | + |
| 49 | + def test_codechecker_yaml(self): |
| 50 | + """Test: bazel build //test/unit/config:codechecker_yaml""" |
| 51 | + ret, _, _ = self.run_command( |
| 52 | + "bazel build //test/unit/config:codechecker_yaml" |
| 53 | + ) |
| 54 | + self.assertEqual(ret, 0) |
| 55 | + copied_config = os.path.join( |
| 56 | + self.BAZEL_BIN_DIR, # type: ignore |
| 57 | + "codechecker_yaml", |
| 58 | + "config.yaml" |
| 59 | + ) |
| 60 | + self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True |
| 61 | + # Before the patch config.yaml won't be generated |
| 62 | + |
| 63 | + def test_codechecker_test_json(self): |
| 64 | + """Test: bazel test //test/unit/config:codechecker_test_json""" |
| 65 | + ret, _, _ = self.run_command( |
| 66 | + "bazel test //test/unit/config:codechecker_test_json" |
| 67 | + ) |
| 68 | + # Should not find the division by zero bug |
| 69 | + self.assertEqual(ret, 0) |
| 70 | + copied_config = os.path.join( |
| 71 | + self.BAZEL_BIN_DIR, # type: ignore |
| 72 | + "codechecker_test_json", |
| 73 | + "config.json" |
| 74 | + ) |
| 75 | + # After the fix the file name will change |
| 76 | + # from codechecker_config.json to config.json |
| 77 | + self.assertTrue(os.path.exists(copied_config)) |
| 78 | + |
| 79 | + def test_codechecker_test_yaml(self): |
| 80 | + """Test: bazel test //test/unit/config:codechecker_test_yaml""" |
| 81 | + ret, _, _ = self.run_command( |
| 82 | + "bazel test //test/unit/config:codechecker_test_yaml" |
| 83 | + ) |
| 84 | + # Should not find the division by zero bug |
| 85 | + self.assertEqual(ret, 3) # TODO: Set to 0, |
| 86 | + # based on the config file won't find the division by zero bug |
| 87 | + copied_config = os.path.join( |
| 88 | + self.BAZEL_BIN_DIR, # type: ignore |
| 89 | + "codechecker_test_yaml", |
| 90 | + "config.yaml" |
| 91 | + ) |
| 92 | + self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True |
| 93 | + # Before the patch config.yaml won't be generated |
| 94 | + |
| 95 | + def test_per_file_test_json(self): |
| 96 | + """Test: bazel test //test/unit/config:per_file_test_json""" |
| 97 | + ret, _, _ = self.run_command( |
| 98 | + "bazel test //test/unit/config:per_file_test_json" |
| 99 | + ) |
| 100 | + # Should not find the division by zero bug |
| 101 | + self.assertEqual(ret, 3) # TODO: Change to 0 |
| 102 | + # since CodeChecker won't find the division by zero bug |
| 103 | + copied_config = os.path.join( |
| 104 | + self.BAZEL_BIN_DIR, # type: ignore |
| 105 | + "per_file_test_json", |
| 106 | + "config.json" |
| 107 | + ) |
| 108 | + self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True |
| 109 | + # Before the patch config files aren't supported in per_file |
| 110 | + |
| 111 | + def test_per_file_test_yaml(self): |
| 112 | + """Test: bazel test //test/unit/config:per_file_test_yaml""" |
| 113 | + ret, _, _ = self.run_command( |
| 114 | + "bazel test //test/unit/config:per_file_test_yaml" |
| 115 | + ) |
| 116 | + # Should not find the division by zero bug |
| 117 | + self.assertEqual(ret, 3) # TODO: Change to 0 |
| 118 | + # since CodeChecker won't find the division by zero bug |
| 119 | + copied_config = os.path.join( |
| 120 | + self.BAZEL_BIN_DIR, # type: ignore |
| 121 | + "per_file_test_yaml", |
| 122 | + "config.yaml" |
| 123 | + ) |
| 124 | + self.assertFalse(os.path.exists(copied_config)) # TODO: Set to True |
| 125 | + # Before the patch config files aren't supported in per_file |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == "__main__": |
| 129 | + unittest.main(buffer=True) |
0 commit comments