-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunused_forward_declaration_rule_test.py
202 lines (181 loc) · 6.43 KB
/
unused_forward_declaration_rule_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import test_support
import unittest
class UnusedForwardDeclarationRuleTest(test_support.TestBase):
def setUp(self):
self.set_default_rules_selection(['UnusedForwardDeclarationRule'])
self.set_default_error_id('unused forward declaration')
self.set_default_error_severity('information')
def test_class_defined(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo {};'
],
expected_errors = [])
def test_class_declared_and_defined(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'class Foo {};'
],
expected_errors = [])
def test_class_declared_and_referenced(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'void FooFunc(Foo&);'
],
expected_errors = [])
def test_class_declared_but_not_referenced(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'class Bar;',
'void BarFunc(Bar&);'
],
expected_errors = [
{
'msg': "Unused forward declaration of class 'Foo'",
'line': '1'
}
])
def test_class_declaration_repeated(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'class Foo;',
'void FooFunc(Foo&);'
],
expected_errors = [
{
'msg': "Repeated forward declaration of class 'Foo'",
'line': '2'
}
])
def test_class_referenced_as_pointer(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'void FooFunc(Foo*);'
],
expected_errors = [])
def test_class_referenced_as_return_type(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'Foo FooFunc();'
],
expected_errors = [])
def test_class_referenced_as_template_argument(self):
self.assert_colobot_lint_result(
source_file_lines = [
'template<typename T> class ClassTemplate { void Foo(T); };',
'class Foo;',
'void FooFunc(ClassTemplate<Foo>);'
],
expected_errors = [])
def test_class_referenced_as_subtemplate_argument(self):
self.assert_colobot_lint_result(
source_file_lines = [
'template<typename T> class ClassTemplate { void Foo(T); };',
'class Foo;',
'void FooFunc(ClassTemplate<ClassTemplate<Foo>>);'
],
expected_errors = [])
def test_enum_defined(self):
self.assert_colobot_lint_result(
source_file_lines = [
'enum class Foo : int {};'
],
expected_errors = [])
def test_enum_declared_and_defined(self):
self.assert_colobot_lint_result(
source_file_lines = [
'enum class Foo;',
'enum class Foo : int {};'
],
expected_errors = [])
def test_enum_declared_but_not_referenced(self):
self.assert_colobot_lint_result(
source_file_lines = [
'enum class Foo : int;'
],
expected_errors = [
{
'msg': "Unused forward declaration of enum class 'Foo'",
'line': '1'
}
])
def test_enum_declared_and_referenced(self):
self.assert_colobot_lint_result(
source_file_lines = [
'enum class Foo : int;',
'void FooFunc(Foo);',
'enum class Bar : int {};',
'void BarFunc(Bar);'
],
expected_errors = [])
def test_class_declaration_repeated_after_definition(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo { };',
'class Foo;'
],
expected_errors = [
{
'msg': "Redundant forward declaration after definition of class 'Foo'",
'line': '2'
}
])
def test_ignore_friend_class_declaration(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo { friend class Bar; };'
],
expected_errors = [])
def test_class_declared_and_referenced_as_a_pointer(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'void FooFunc(Foo*);'
],
expected_errors = [])
def test_class_declared_and_referenced_in_a_template_argument(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'template<typename T> class TemplateClass {};',
'void FooFunc(TemplateClass<Foo>&);'
],
expected_errors = [])
def test_class_declared_and_referenced_as_a_pointer_field(self):
self.assert_colobot_lint_result(
source_file_lines = [
'class Foo;',
'struct Bar',
'{',
' Foo* foo;',
'};'
],
expected_errors = [])
def test_report_correct_location_with_declaration_in_header(self):
self.assert_colobot_lint_result_with_custom_files(
source_files_data = {
'src.cpp': [
'#include "foo.h"',
'',
'class Foo;'
],
'foo.h': [
'class Foo;'
]
},
compilation_database_files = ['src.cpp'],
target_files = ['src.cpp'],
additional_compile_flags = ['-I$TEMP_DIR'],
additional_options = ['-project-local-include-path', '$TEMP_DIR'],
expected_errors = [
{
'msg': "Unused forward declaration of class 'Foo'",
'line': '3'
}
])