1 // RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -I%S/Inputs
2 // RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -I%S/Inputs/gtest/nosuite
3
4 #include "gtest/gtest.h"
5
6 // When including a version of googletest without the replacement names, this
7 // check should not produce any diagnostics. The following dummy fix is present
8 // because `check_clang_tidy.py` requires at least one warning, fix or note.
Dummy()9 void Dummy() {}
10 // CHECK-FIXES-NOSUITE: void Dummy() {}
11
12 // ----------------------------------------------------------------------------
13 // Macros
14
15 TYPED_TEST_CASE(FooTest, FooTypes);
16 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: Google Test APIs named with 'case' are deprecated; use equivalent APIs named with 'suite'
17 // CHECK-FIXES: TYPED_TEST_SUITE(FooTest, FooTypes);
18 TYPED_TEST_CASE_P(FooTest);
19 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: Google Test APIs named with 'case'
20 // CHECK-FIXES: TYPED_TEST_SUITE_P(FooTest);
21 REGISTER_TYPED_TEST_CASE_P(FooTest, FooTestName);
22 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: Google Test APIs named with 'case'
23 // CHECK-FIXES: REGISTER_TYPED_TEST_SUITE_P(FooTest, FooTestName);
24 INSTANTIATE_TYPED_TEST_CASE_P(FooPrefix, FooTest, FooTypes);
25 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: Google Test APIs named with 'case'
26 // CHECK-FIXES: INSTANTIATE_TYPED_TEST_SUITE_P(FooPrefix, FooTest, FooTypes);
27
28 #ifdef TYPED_TEST_CASE
29 // CHECK-MESSAGES: [[@LINE-1]]:2: warning: Google Test APIs named with 'case'
30 #undef TYPED_TEST_CASE
31 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
32 #define TYPED_TEST_CASE(CaseName, Types, ...)
33 #endif
34
35 #ifdef TYPED_TEST_CASE_P
36 // CHECK-MESSAGES: [[@LINE-1]]:2: warning: Google Test APIs named with 'case'
37 #undef TYPED_TEST_CASE_P
38 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
39 #define TYPED_TEST_CASE_P(SuiteName)
40 #endif
41
42 #ifdef REGISTER_TYPED_TEST_CASE_P
43 // CHECK-MESSAGES: [[@LINE-1]]:2: warning: Google Test APIs named with 'case'
44 #undef REGISTER_TYPED_TEST_CASE_P
45 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
46 #define REGISTER_TYPED_TEST_CASE_P(SuiteName, ...)
47 #endif
48
49 #ifdef INSTANTIATE_TYPED_TEST_CASE_P
50 // CHECK-MESSAGES: [[@LINE-1]]:2: warning: Google Test APIs named with 'case'
51 #undef INSTANTIATE_TYPED_TEST_CASE_P
52 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
53 #define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, SuiteName, Types, ...)
54 #endif
55
56 TYPED_TEST_CASE(FooTest, FooTypes);
57 TYPED_TEST_CASE_P(FooTest);
58 REGISTER_TYPED_TEST_CASE_P(FooTest, FooTestName);
59 INSTANTIATE_TYPED_TEST_CASE_P(FooPrefix, FooTest, FooTypes);
60
61 // ----------------------------------------------------------------------------
62 // testing::Test
63
64 class FooTest : public testing::Test {
65 public:
66 static void SetUpTestCase();
67 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
68 // CHECK-FIXES: static void SetUpTestSuite();
69 static void TearDownTestCase();
70 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
71 // CHECK-FIXES: static void TearDownTestSuite();
72 };
73
SetUpTestCase()74 void FooTest::SetUpTestCase() {}
75 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
76 // CHECK-FIXES: void FooTest::SetUpTestSuite() {}
77
TearDownTestCase()78 void FooTest::TearDownTestCase() {}
79 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
80 // CHECK-FIXES: void FooTest::TearDownTestSuite() {}
81
82 template <typename T> class FooTypedTest : public testing::Test {
83 public:
84 static void SetUpTestCase();
85 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
86 // CHECK-FIXES: static void SetUpTestSuite();
87 static void TearDownTestCase();
88 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
89 // CHECK-FIXES: static void TearDownTestSuite();
90 };
91
SetUpTestCase()92 template <typename T> void FooTypedTest<T>::SetUpTestCase() {}
93 // CHECK-MESSAGES: [[@LINE-1]]:45: warning: Google Test APIs named with 'case'
94 // CHECK-FIXES: void FooTypedTest<T>::SetUpTestSuite() {}
95
TearDownTestCase()96 template <typename T> void FooTypedTest<T>::TearDownTestCase() {}
97 // CHECK-MESSAGES: [[@LINE-1]]:45: warning: Google Test APIs named with 'case'
98 // CHECK-FIXES: void FooTypedTest<T>::TearDownTestSuite() {}
99
100 class BarTest : public testing::Test {
101 public:
102 using Test::SetUpTestCase;
103 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
104 // CHECK-FIXES: using Test::SetUpTestSuite;
105 using Test::TearDownTestCase;
106 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
107 // CHECK-FIXES: using Test::TearDownTestSuite;
108 };
109
110 class BarTest2 : public FooTest {
111 public:
112 using FooTest::SetUpTestCase;
113 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
114 // CHECK-FIXES: using FooTest::SetUpTestSuite;
115 using FooTest::TearDownTestCase;
116 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
117 // CHECK-FIXES: using FooTest::TearDownTestSuite;
118 };
119
120 // If a derived type already has the replacements, we only provide a warning
121 // since renaming or deleting the old declarations may not be safe.
122 class BarTest3 : public testing::Test {
123 public:
SetUpTestCase()124 static void SetUpTestCase() {}
125 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
SetUpTestSuite()126 static void SetUpTestSuite() {}
127
TearDownTestCase()128 static void TearDownTestCase() {}
129 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
TearDownTestSuite()130 static void TearDownTestSuite() {}
131 };
132
133 namespace nesting_ns {
134 namespace testing {
135
136 class Test {
137 public:
138 static void SetUpTestCase();
139 static void TearDownTestCase();
140 };
141
142 } // namespace testing
143
Test()144 void Test() {
145 testing::Test::SetUpTestCase();
146 testing::Test::TearDownTestCase();
147 }
148
149 } // namespace nesting_ns
150
151 template <typename T>
testInstantiationOnlyWarns()152 void testInstantiationOnlyWarns() {
153 T::SetUpTestCase();
154 // CHECK-MESSAGES: [[@LINE-1]]:6: warning: Google Test APIs named with 'case'
155 T::TearDownTestCase();
156 // CHECK-MESSAGES: [[@LINE-1]]:6: warning: Google Test APIs named with 'case'
157 }
158
159 #define SET_UP_TEST_CASE_MACRO_REPLACE SetUpTestCase
160 #define TEST_SET_UP_TEST_CASE_MACRO_WARN_ONLY ::testing::Test::SetUpTestCase
161
setUpTearDownCallAndReference()162 void setUpTearDownCallAndReference() {
163 testing::Test::SetUpTestCase();
164 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
165 // CHECK-FIXES: testing::Test::SetUpTestSuite();
166 FooTest::SetUpTestCase();
167 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
168 // CHECK-FIXES: FooTest::SetUpTestSuite();
169
170 testing::Test::TearDownTestCase();
171 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
172 // CHECK-FIXES: testing::Test::TearDownTestSuite();
173 FooTest::TearDownTestCase();
174 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
175 // CHECK-FIXES: FooTest::TearDownTestSuite();
176
177 auto F = &testing::Test::SetUpTestCase;
178 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
179 // CHECK-FIXES: auto F = &testing::Test::SetUpTestSuite;
180 F = &testing::Test::TearDownTestCase;
181 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
182 // CHECK-FIXES: F = &testing::Test::TearDownTestSuite;
183 F = &FooTest::SetUpTestCase;
184 // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Google Test APIs named with 'case'
185 // CHECK-FIXES: F = &FooTest::SetUpTestSuite;
186 F = &FooTest::TearDownTestCase;
187 // CHECK-MESSAGES: [[@LINE-1]]:17: warning: Google Test APIs named with 'case'
188 // CHECK-FIXES: F = &FooTest::TearDownTestSuite;
189
190 using MyTest = testing::Test;
191 MyTest::SetUpTestCase();
192 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
193 // CHECK-FIXES: MyTest::SetUpTestSuite();
194 MyTest::TearDownTestCase();
195 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
196 // CHECK-FIXES: MyTest::TearDownTestSuite();
197
198 BarTest3::SetUpTestCase();
199 // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Google Test APIs named with 'case'
200 // CHECK-FIXES: BarTest3::SetUpTestSuite();
201 BarTest3::TearDownTestCase();
202 // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Google Test APIs named with 'case'
203 // CHECK-FIXES: BarTest3::TearDownTestSuite();
204
205 testInstantiationOnlyWarns<testing::Test>();
206
207 testing::Test::SET_UP_TEST_CASE_MACRO_REPLACE();
208 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
209 // CHECK-FIXES: testing::Test::SetUpTestSuite();
210 TEST_SET_UP_TEST_CASE_MACRO_WARN_ONLY();
211 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
212 }
213
214 // ----------------------------------------------------------------------------
215 // testing::TestInfo
216
217 class FooTestInfo : public testing::TestInfo {
218 public:
219 const char *test_case_name() const;
220 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
221 // CHECK-FIXES: const char *test_suite_name() const;
222 };
223
test_case_name() const224 const char *FooTestInfo::test_case_name() const {}
225 // CHECK-MESSAGES: [[@LINE-1]]:26: warning: Google Test APIs named with 'case'
226 // CHECK-FIXES: const char *FooTestInfo::test_suite_name() const {}
227
228 class BarTestInfo : public testing::TestInfo {
229 public:
230 using TestInfo::test_case_name;
231 // CHECK-MESSAGES: [[@LINE-1]]:19: warning: Google Test APIs named with 'case'
232 // CHECK-FIXES: using TestInfo::test_suite_name;
233 };
234
235 class BarTestInfo2 : public FooTestInfo {
236 public:
237 using FooTestInfo::test_case_name;
238 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
239 // CHECK-FIXES: using FooTestInfo::test_suite_name;
240 };
241
242 class BarTestInfo3 : public testing::TestInfo {
243 public:
244 const char* test_case_name() const;
245 // CHECK-MESSAGES: [[@LINE-1]]:15: warning: Google Test APIs named with 'case'
246 const char* test_suite_name() const;
247 };
248
249 namespace nesting_ns {
250 namespace testing {
251
252 class TestInfo {
253 public:
254 const char *test_case_name() const;
255 };
256
257 } // namespace testing
258
FuncInfo()259 void FuncInfo() {
260 testing::TestInfo t;
261 (void)t.test_case_name();
262 }
263
264 } // namespace nesting_ns
265
266 template <typename T>
testInfoInstantiationOnlyWarns()267 void testInfoInstantiationOnlyWarns() {
268 T t;
269 (void)t.test_case_name();
270 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
271 }
272
273 #define TEST_CASE_NAME_MACRO_REPLACE test_case_name
274 #define TEST_CASE_NAME_MACRO_WARN_ONLY testing::TestInfo().test_case_name
275
testInfoCallAndReference()276 void testInfoCallAndReference() {
277 (void)testing::TestInfo().test_case_name();
278 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
279 // CHECK-FIXES: (void)testing::TestInfo().test_suite_name();
280 (void)FooTestInfo().test_case_name();
281 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
282 // CHECK-FIXES: (void)FooTestInfo().test_suite_name();
283 auto F1 = &testing::TestInfo::test_case_name;
284 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
285 // CHECK-FIXES: auto F1 = &testing::TestInfo::test_suite_name;
286 auto F2 = &FooTestInfo::test_case_name;
287 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
288 // CHECK-FIXES: auto F2 = &FooTestInfo::test_suite_name;
289 using MyTestInfo = testing::TestInfo;
290 (void)MyTestInfo().test_case_name();
291 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
292 // CHECK-FIXES: (void)MyTestInfo().test_suite_name();
293 (void)BarTestInfo3().test_case_name();
294 // CHECK-MESSAGES: [[@LINE-1]]:24: warning: Google Test APIs named with 'case'
295 // CHECK-FIXES: (void)BarTestInfo3().test_suite_name();
296
297 testInfoInstantiationOnlyWarns<testing::TestInfo>();
298
299 (void)testing::TestInfo().TEST_CASE_NAME_MACRO_REPLACE();
300 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
301 // CHECK-FIXES: (void)testing::TestInfo().test_suite_name();
302 (void)TEST_CASE_NAME_MACRO_WARN_ONLY();
303 // CHECK-MESSAGES: [[@LINE-1]]:9: warning: Google Test APIs named with 'case'
304 }
305
306 // ----------------------------------------------------------------------------
307 // testing::TestEventListener
308
309 class FooTestEventListener : public testing::TestEventListener {
310 public:
311 void OnTestCaseStart(const testing::TestCase &) override;
312 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
313 // CHECK-MESSAGES: [[@LINE-2]]:39: warning: Google Test APIs named with 'case'
314 // CHECK-FIXES: void OnTestSuiteStart(const testing::TestSuite &) override;
315 void OnTestCaseEnd(const testing::TestCase &) override;
316 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
317 // CHECK-MESSAGES: [[@LINE-2]]:37: warning: Google Test APIs named with 'case'
318 // CHECK-FIXES: void OnTestSuiteEnd(const testing::TestSuite &) override;
319 };
320
OnTestCaseStart(const testing::TestCase &)321 void FooTestEventListener::OnTestCaseStart(const testing::TestCase &) {}
322 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
323 // CHECK-MESSAGES: [[@LINE-2]]:59: warning: Google Test APIs named with 'case'
324 // CHECK-FIXES: void FooTestEventListener::OnTestSuiteStart(const testing::TestSuite &) {}
325
OnTestCaseEnd(const testing::TestCase &)326 void FooTestEventListener::OnTestCaseEnd(const testing::TestCase &) {}
327 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
328 // CHECK-MESSAGES: [[@LINE-2]]:57: warning: Google Test APIs named with 'case'
329 // CHECK-FIXES: void FooTestEventListener::OnTestSuiteEnd(const testing::TestSuite &) {}
330
331 class BarTestEventListener : public testing::TestEventListener {
332 public:
333 using TestEventListener::OnTestCaseStart;
334 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
335 // CHECK-FIXES: using TestEventListener::OnTestSuiteStart;
336 using TestEventListener::OnTestCaseEnd;
337 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
338 // CHECK-FIXES: using TestEventListener::OnTestSuiteEnd;
339 };
340
341 class BarTestEventListener2 : public BarTestEventListener {
342 public:
343 using BarTestEventListener::OnTestCaseStart;
344 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: Google Test APIs named with 'case'
345 // CHECK-FIXES: using BarTestEventListener::OnTestSuiteStart;
346 using BarTestEventListener::OnTestCaseEnd;
347 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: Google Test APIs named with 'case'
348 // CHECK-FIXES: using BarTestEventListener::OnTestSuiteEnd;
349 };
350
351 #ifndef NOSUITE
352
353 class BarTestEventListener3 : public testing::TestEventListener {
354 public:
355 void OnTestCaseStart(const testing::TestSuite &) override;
356 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
357 void OnTestSuiteStart(const testing::TestSuite &) override;
358
359 void OnTestCaseEnd(const testing::TestSuite &) override;
360 // CHECK-MESSAGES: [[@LINE-1]]:8: warning: Google Test APIs named with 'case'
361 void OnTestSuiteEnd(const testing::TestSuite &) override;
362 };
363
364 #endif
365
366 namespace nesting_ns {
367 namespace testing {
368
369 class TestEventListener {
370 public:
371 virtual void OnTestCaseStart(const ::testing::TestCase &);
372 // CHECK-MESSAGES: [[@LINE-1]]:49: warning: Google Test APIs named with 'case'
373 // CHECK-FIXES: virtual void OnTestCaseStart(const ::testing::TestSuite &);
374 virtual void OnTestCaseEnd(const ::testing::TestCase &);
375 // CHECK-MESSAGES: [[@LINE-1]]:47: warning: Google Test APIs named with 'case'
376 // CHECK-FIXES: virtual void OnTestCaseEnd(const ::testing::TestSuite &);
377 };
378
379 } // namespace testing
380
FuncTestEventListener(::testing::TestCase & Case)381 void FuncTestEventListener(::testing::TestCase &Case) {
382 // CHECK-MESSAGES: [[@LINE-1]]:39: warning: Google Test APIs named with 'case'
383 // CHECK-FIXES: void FuncTestEventListener(::testing::TestSuite &Case) {
384 testing::TestEventListener().OnTestCaseStart(Case);
385 testing::TestEventListener().OnTestCaseEnd(Case);
386 }
387
388 } // namespace nesting_ns
389
390 #ifndef NOSUITE
391
392 template <typename T>
testEventListenerInstantiationOnlyWarns()393 void testEventListenerInstantiationOnlyWarns() {
394 T().OnTestCaseStart(testing::TestSuite());
395 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
396 T().OnTestCaseEnd(testing::TestSuite());
397 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
398 }
399
400 #endif
401
402 #define ON_TEST_CASE_START_MACRO_REPLACE OnTestCaseStart
403 #define ON_TEST_CASE_START_MACRO_WARN_ONLY \
404 testing::TestEventListener().OnTestCaseStart
405
406 #define ON_TEST_CASE_END_MACRO_REPLACE OnTestCaseEnd
407 #define ON_TEST_CASE_END_MACRO_WARN_ONLY \
408 testing::TestEventListener().OnTestCaseEnd
409
testEventListenerCallAndReference(testing::TestCase & Case)410 void testEventListenerCallAndReference(testing::TestCase &Case) {
411 // CHECK-MESSAGES: [[@LINE-1]]:49: warning: Google Test APIs named with 'case'
412 // CHECK-FIXES: void testEventListenerCallAndReference(testing::TestSuite &Case) {
413 testing::TestEventListener().OnTestCaseStart(Case);
414 // CHECK-MESSAGES: [[@LINE-1]]:32: warning: Google Test APIs named with 'case'
415 // CHECK-FIXES: testing::TestEventListener().OnTestSuiteStart(Case);
416 testing::TestEventListener().OnTestCaseEnd(Case);
417 // CHECK-MESSAGES: [[@LINE-1]]:32: warning: Google Test APIs named with 'case'
418 // CHECK-FIXES: testing::TestEventListener().OnTestSuiteEnd(Case);
419
420 FooTestEventListener().OnTestCaseStart(Case);
421 // CHECK-MESSAGES: [[@LINE-1]]:26: warning: Google Test APIs named with 'case'
422 // CHECK-FIXES: FooTestEventListener().OnTestSuiteStart(Case);
423 FooTestEventListener().OnTestCaseEnd(Case);
424 // CHECK-MESSAGES: [[@LINE-1]]:26: warning: Google Test APIs named with 'case'
425 // CHECK-FIXES: FooTestEventListener().OnTestSuiteEnd(Case);
426
427 auto F1 = &testing::TestEventListener::OnTestCaseStart;
428 // CHECK-MESSAGES: [[@LINE-1]]:42: warning: Google Test APIs named with 'case'
429 // CHECK-FIXES: auto F1 = &testing::TestEventListener::OnTestSuiteStart;
430 F1 = &testing::TestEventListener::OnTestCaseEnd;
431 // CHECK-MESSAGES: [[@LINE-1]]:37: warning: Google Test APIs named with 'case'
432 // CHECK-FIXES: F1 = &testing::TestEventListener::OnTestSuiteEnd;
433
434 auto F2 = &FooTestEventListener::OnTestCaseStart;
435 // CHECK-MESSAGES: [[@LINE-1]]:36: warning: Google Test APIs named with 'case'
436 // CHECK-FIXES: auto F2 = &FooTestEventListener::OnTestSuiteStart;
437 F2 = &FooTestEventListener::OnTestCaseEnd;
438 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: Google Test APIs named with 'case'
439 // CHECK-FIXES: F2 = &FooTestEventListener::OnTestSuiteEnd;
440
441 #ifndef NOSUITE
442
443 BarTestEventListener3().OnTestCaseStart(Case);
444 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
445 // CHECK-FIXES: BarTestEventListener3().OnTestSuiteStart(Case);
446 BarTestEventListener3().OnTestCaseEnd(Case);
447 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
448 // CHECK-FIXES: BarTestEventListener3().OnTestSuiteEnd(Case);
449
450 testEventListenerInstantiationOnlyWarns<testing::TestEventListener>();
451
452 #endif
453
454 testing::TestEventListener().ON_TEST_CASE_START_MACRO_REPLACE(Case);
455 // CHECK-MESSAGES: [[@LINE-1]]:32: warning: Google Test APIs named with 'case'
456 // CHECK-FIXES: testing::TestEventListener().OnTestSuiteStart(Case);
457 ON_TEST_CASE_START_MACRO_WARN_ONLY(Case);
458 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
459
460 testing::TestEventListener().ON_TEST_CASE_END_MACRO_REPLACE(Case);
461 // CHECK-MESSAGES: [[@LINE-1]]:32: warning: Google Test APIs named with 'case'
462 // CHECK-FIXES: testing::TestEventListener().OnTestSuiteEnd(Case);
463 ON_TEST_CASE_END_MACRO_WARN_ONLY(Case);
464 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
465 }
466
467 // ----------------------------------------------------------------------------
468 // testing::UnitTest
469
470 class FooUnitTest : public testing::UnitTest {
471 public:
472 testing::TestCase *current_test_case() const;
473 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
474 // CHECK-MESSAGES: [[@LINE-2]]:22: warning: Google Test APIs named with 'case'
475 // CHECK-FIXES: testing::TestSuite *current_test_suite() const;
476 int successful_test_case_count() const;
477 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
478 // CHECK-FIXES: int successful_test_suite_count() const;
479 int failed_test_case_count() const;
480 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
481 // CHECK-FIXES: int failed_test_suite_count() const;
482 int total_test_case_count() const;
483 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
484 // CHECK-FIXES: int total_test_suite_count() const;
485 int test_case_to_run_count() const;
486 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
487 // CHECK-FIXES: int test_suite_to_run_count() const;
488 const testing::TestCase *GetTestCase(int) const;
489 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
490 // CHECK-MESSAGES: [[@LINE-2]]:28: warning: Google Test APIs named with 'case'
491 // CHECK-FIXES: const testing::TestSuite *GetTestSuite(int) const;
492 };
493
current_test_case() const494 testing::TestCase *FooUnitTest::current_test_case() const {}
495 // CHECK-MESSAGES: [[@LINE-1]]:10: warning: Google Test APIs named with 'case'
496 // CHECK-MESSAGES: [[@LINE-2]]:33: warning: Google Test APIs named with 'case'
497 // CHECK-FIXES: testing::TestSuite *FooUnitTest::current_test_suite() const {}
successful_test_case_count() const498 int FooUnitTest::successful_test_case_count() const {}
499 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
500 // CHECK-FIXES: int FooUnitTest::successful_test_suite_count() const {}
failed_test_case_count() const501 int FooUnitTest::failed_test_case_count() const {}
502 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
503 // CHECK-FIXES: int FooUnitTest::failed_test_suite_count() const {}
total_test_case_count() const504 int FooUnitTest::total_test_case_count() const {}
505 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
506 // CHECK-FIXES: int FooUnitTest::total_test_suite_count() const {}
test_case_to_run_count() const507 int FooUnitTest::test_case_to_run_count() const {}
508 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
509 // CHECK-FIXES: int FooUnitTest::test_suite_to_run_count() const {}
GetTestCase(int) const510 const testing::TestCase *FooUnitTest::GetTestCase(int) const {}
511 // CHECK-MESSAGES: [[@LINE-1]]:16: warning: Google Test APIs named with 'case'
512 // CHECK-MESSAGES: [[@LINE-2]]:39: warning: Google Test APIs named with 'case'
513 // CHECK-FIXES: const testing::TestSuite *FooUnitTest::GetTestSuite(int) const {}
514
515 // Type derived from testing::TestCase
516 class BarUnitTest : public testing::UnitTest {
517 public:
518 using testing::UnitTest::current_test_case;
519 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
520 // CHECK-FIXES: using testing::UnitTest::current_test_suite;
521 using testing::UnitTest::successful_test_case_count;
522 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
523 // CHECK-FIXES: using testing::UnitTest::successful_test_suite_count;
524 using testing::UnitTest::failed_test_case_count;
525 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
526 // CHECK-FIXES: using testing::UnitTest::failed_test_suite_count;
527 using testing::UnitTest::total_test_case_count;
528 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
529 // CHECK-FIXES: using testing::UnitTest::total_test_suite_count;
530 using testing::UnitTest::test_case_to_run_count;
531 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
532 // CHECK-FIXES: using testing::UnitTest::test_suite_to_run_count;
533 using testing::UnitTest::GetTestCase;
534 // CHECK-MESSAGES: [[@LINE-1]]:28: warning: Google Test APIs named with 'case'
535 // CHECK-FIXES: using testing::UnitTest::GetTestSuite;
536 };
537
538 class BarUnitTest2 : public BarUnitTest {
539 using BarUnitTest::current_test_case;
540 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
541 // CHECK-FIXES: using BarUnitTest::current_test_suite;
542 using BarUnitTest::successful_test_case_count;
543 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
544 // CHECK-FIXES: using BarUnitTest::successful_test_suite_count;
545 using BarUnitTest::failed_test_case_count;
546 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
547 // CHECK-FIXES: using BarUnitTest::failed_test_suite_count;
548 using BarUnitTest::total_test_case_count;
549 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
550 // CHECK-FIXES: using BarUnitTest::total_test_suite_count;
551 using BarUnitTest::test_case_to_run_count;
552 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
553 // CHECK-FIXES: using BarUnitTest::test_suite_to_run_count;
554 using BarUnitTest::GetTestCase;
555 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
556 // CHECK-FIXES: using BarUnitTest::GetTestSuite;
557 };
558
559 #ifndef NOSUITE
560
561 class BarUnitTest3 : public testing::UnitTest {
562 testing::TestSuite *current_test_case() const;
563 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
564 int successful_test_case_count() const;
565 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
566 int failed_test_case_count() const;
567 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
568 int total_test_case_count() const;
569 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
570 int test_case_to_run_count() const;
571 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
572 const testing::TestSuite *GetTestCase(int) const;
573 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
574
575 testing::TestSuite *current_test_suite() const;
576 int successful_test_suite_count() const;
577 int failed_test_suite_count() const;
578 int total_test_suite_count() const;
579 int test_suite_to_run_count() const;
580 const testing::TestSuite *GetTestSuite(int) const;
581 };
582
583 #endif
584
585 namespace nesting_ns {
586 namespace testing {
587
588 class TestSuite;
589
590 class UnitTest {
591 public:
592 TestSuite *current_test_case() const;
593 int successful_test_case_count() const;
594 int failed_test_case_count() const;
595 int total_test_case_count() const;
596 int test_case_to_run_count() const;
597 const TestSuite *GetTestCase(int) const;
598 };
599
600 } // namespace testing
601
FuncUnitTest()602 void FuncUnitTest() {
603 testing::UnitTest t;
604 (void)t.current_test_case();
605 (void)t.successful_test_case_count();
606 (void)t.failed_test_case_count();
607 (void)t.total_test_case_count();
608 (void)t.test_case_to_run_count();
609 (void)t.GetTestCase(0);
610 }
611
612 } // namespace nesting_ns
613
614 template <typename T>
unitTestInstantiationOnlyWarns()615 void unitTestInstantiationOnlyWarns() {
616 T t;
617 (void)t.current_test_case();
618 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
619 (void)t.successful_test_case_count();
620 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
621 (void)t.failed_test_case_count();
622 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
623 (void)t.total_test_case_count();
624 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
625 (void)t.test_case_to_run_count();
626 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
627 (void)t.GetTestCase(0);
628 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
629 }
630
631 #define UNIT_TEST_NAME_MACRO_REPLACE1 current_test_case
632 #define UNIT_TEST_NAME_MACRO_REPLACE2 successful_test_case_count
633 #define UNIT_TEST_NAME_MACRO_REPLACE3 failed_test_case_count
634 #define UNIT_TEST_NAME_MACRO_REPLACE4 total_test_case_count
635 #define UNIT_TEST_NAME_MACRO_REPLACE5 test_case_to_run_count
636 #define UNIT_TEST_NAME_MACRO_REPLACE6 GetTestCase
637 #define UNIT_TEST_NAME_MACRO_WARN_ONLY1 testing::UnitTest().current_test_case
638 #define UNIT_TEST_NAME_MACRO_WARN_ONLY2 \
639 testing::UnitTest().successful_test_case_count
640 #define UNIT_TEST_NAME_MACRO_WARN_ONLY3 \
641 testing::UnitTest().failed_test_case_count
642 #define UNIT_TEST_NAME_MACRO_WARN_ONLY4 \
643 testing::UnitTest().total_test_case_count
644 #define UNIT_TEST_NAME_MACRO_WARN_ONLY5 \
645 testing::UnitTest().test_case_to_run_count
646 #define UNIT_TEST_NAME_MACRO_WARN_ONLY6 testing::UnitTest().GetTestCase
647
unitTestCallAndReference()648 void unitTestCallAndReference() {
649 (void)testing::UnitTest().current_test_case();
650 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
651 // CHECK-FIXES: (void)testing::UnitTest().current_test_suite();
652 (void)testing::UnitTest().successful_test_case_count();
653 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
654 // CHECK-FIXES: (void)testing::UnitTest().successful_test_suite_count();
655 (void)testing::UnitTest().failed_test_case_count();
656 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
657 // CHECK-FIXES: (void)testing::UnitTest().failed_test_suite_count();
658 (void)testing::UnitTest().total_test_case_count();
659 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
660 // CHECK-FIXES: (void)testing::UnitTest().total_test_suite_count();
661 (void)testing::UnitTest().test_case_to_run_count();
662 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
663 // CHECK-FIXES: (void)testing::UnitTest().test_suite_to_run_count();
664 (void)testing::UnitTest().GetTestCase(0);
665 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
666 // CHECK-FIXES: (void)testing::UnitTest().GetTestSuite(0);
667
668 (void)FooUnitTest().current_test_case();
669 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
670 // CHECK-FIXES: (void)FooUnitTest().current_test_suite();
671 (void)FooUnitTest().successful_test_case_count();
672 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
673 // CHECK-FIXES: (void)FooUnitTest().successful_test_suite_count();
674 (void)FooUnitTest().failed_test_case_count();
675 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
676 // CHECK-FIXES: (void)FooUnitTest().failed_test_suite_count();
677 (void)FooUnitTest().total_test_case_count();
678 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
679 // CHECK-FIXES: (void)FooUnitTest().total_test_suite_count();
680 (void)FooUnitTest().test_case_to_run_count();
681 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
682 // CHECK-FIXES: (void)FooUnitTest().test_suite_to_run_count();
683 (void)FooUnitTest().GetTestCase(0);
684 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
685 // CHECK-FIXES: (void)FooUnitTest().GetTestSuite(0);
686
687 auto U1 = &testing::UnitTest::current_test_case;
688 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
689 // CHECK-FIXES: auto U1 = &testing::UnitTest::current_test_suite;
690 auto U2 = &testing::UnitTest::successful_test_case_count;
691 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
692 // CHECK-FIXES: auto U2 = &testing::UnitTest::successful_test_suite_count;
693 auto U3 = &testing::UnitTest::failed_test_case_count;
694 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
695 // CHECK-FIXES: auto U3 = &testing::UnitTest::failed_test_suite_count;
696 auto U4 = &testing::UnitTest::total_test_case_count;
697 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
698 // CHECK-FIXES: auto U4 = &testing::UnitTest::total_test_suite_count;
699 auto U5 = &testing::UnitTest::test_case_to_run_count;
700 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
701 // CHECK-FIXES: auto U5 = &testing::UnitTest::test_suite_to_run_count;
702 auto U6 = &testing::UnitTest::GetTestCase;
703 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
704 // CHECK-FIXES: auto U6 = &testing::UnitTest::GetTestSuite;
705
706 auto F1 = &FooUnitTest::current_test_case;
707 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
708 // CHECK-FIXES: auto F1 = &FooUnitTest::current_test_suite;
709 auto F2 = &FooUnitTest::successful_test_case_count;
710 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
711 // CHECK-FIXES: auto F2 = &FooUnitTest::successful_test_suite_count;
712 auto F3 = &FooUnitTest::failed_test_case_count;
713 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
714 // CHECK-FIXES: auto F3 = &FooUnitTest::failed_test_suite_count;
715 auto F4 = &FooUnitTest::total_test_case_count;
716 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
717 // CHECK-FIXES: auto F4 = &FooUnitTest::total_test_suite_count;
718 auto F5 = &FooUnitTest::test_case_to_run_count;
719 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
720 // CHECK-FIXES: auto F5 = &FooUnitTest::test_suite_to_run_count;
721 auto F6 = &FooUnitTest::GetTestCase;
722 // CHECK-MESSAGES: [[@LINE-1]]:27: warning: Google Test APIs named with 'case'
723 // CHECK-FIXES: auto F6 = &FooUnitTest::GetTestSuite;
724
725 using MyUnitTest = testing::UnitTest;
726 (void)MyUnitTest().current_test_case();
727 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
728 // CHECK-FIXES: (void)MyUnitTest().current_test_suite();
729 (void)MyUnitTest().successful_test_case_count();
730 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
731 // CHECK-FIXES: (void)MyUnitTest().successful_test_suite_count();
732 (void)MyUnitTest().failed_test_case_count();
733 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
734 // CHECK-FIXES: (void)MyUnitTest().failed_test_suite_count();
735 (void)MyUnitTest().total_test_case_count();
736 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
737 // CHECK-FIXES: (void)MyUnitTest().total_test_suite_count();
738 (void)MyUnitTest().test_case_to_run_count();
739 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
740 // CHECK-FIXES: (void)MyUnitTest().test_suite_to_run_count();
741 (void)MyUnitTest().GetTestCase(0);
742 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
743 // CHECK-FIXES: (void)MyUnitTest().GetTestSuite(0);
744
745 unitTestInstantiationOnlyWarns<testing::UnitTest>();
746
747 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE1();
748 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
749 // CHECK-FIXES: (void)testing::UnitTest().current_test_suite();
750 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE2();
751 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
752 // CHECK-FIXES: (void)testing::UnitTest().successful_test_suite_count();
753 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE3();
754 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
755 // CHECK-FIXES: (void)testing::UnitTest().failed_test_suite_count();
756 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE4();
757 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
758 // CHECK-FIXES: (void)testing::UnitTest().total_test_suite_count();
759 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE5();
760 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
761 // CHECK-FIXES: (void)testing::UnitTest().test_suite_to_run_count();
762 (void)testing::UnitTest().UNIT_TEST_NAME_MACRO_REPLACE6(0);
763 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
764 // CHECK-FIXES: (void)testing::UnitTest().GetTestSuite(0);
765
766 UNIT_TEST_NAME_MACRO_WARN_ONLY1();
767 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
768 UNIT_TEST_NAME_MACRO_WARN_ONLY2();
769 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
770 UNIT_TEST_NAME_MACRO_WARN_ONLY3();
771 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
772 UNIT_TEST_NAME_MACRO_WARN_ONLY4();
773 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
774 UNIT_TEST_NAME_MACRO_WARN_ONLY5();
775 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
776 UNIT_TEST_NAME_MACRO_WARN_ONLY6(0);
777 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
778 }
779
780 // ----------------------------------------------------------------------------
781 // testing::TestCase
782
783 template <typename T>
TestCaseInTemplate()784 void TestCaseInTemplate() {
785 T t;
786
787 testing::TestCase Case;
788 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
789 // CHECK-FIXES: testing::TestSuite Case;
790 }
791
792 #define TEST_CASE_CAN_FIX TestCase
793 #define TEST_CASE_WARN_ONLY testing::TestCase
794
testCaseUses(const testing::TestCase & Case)795 const testing::TestCase *testCaseUses(const testing::TestCase &Case) {
796 // CHECK-MESSAGES: [[@LINE-1]]:16: warning: Google Test APIs named with 'case'
797 // CHECK-MESSAGES: [[@LINE-2]]:54: warning: Google Test APIs named with 'case'
798 // CHECK-FIXES: const testing::TestSuite *testCaseUses(const testing::TestSuite &Case) {
799
800 // No change for implicit declarations:
801 auto Lambda = [&Case]() {};
802
803 TestCaseInTemplate<testing::TestCase>();
804 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: Google Test APIs named with 'case'
805 // CHECK-FIXES: TestCaseInTemplate<testing::TestSuite>();
806
807 testing::TEST_CASE_CAN_FIX C1;
808 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
809 // CHECK-FIXES: testing::TestSuite C1;
810 TEST_CASE_WARN_ONLY C2;
811 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
812
813 (void)new testing::TestCase();
814 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
815 // CHECK-FIXES: (void)new testing::TestSuite();
816 const testing::TestCase *Result = &Case;
817 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
818 // CHECK-FIXES: const testing::TestSuite *Result = &Case;
819 return Result;
820 }
821
822 struct TestCaseHolder {
823 testing::TestCase Case;
824 // CHECK-MESSAGES: [[@LINE-1]]:12: warning: Google Test APIs named with 'case'
825 // CHECK-FIXES: testing::TestSuite Case;
826 };
827
828 class MyTest : public testing::TestCase {};
829 // CHECK-MESSAGES: [[@LINE-1]]:32: warning: Google Test APIs named with 'case'
830 // CHECK-FIXES: class MyTest : public testing::TestSuite {};
831
832 template <typename T = testing::TestCase>
833 // CHECK-MESSAGES: [[@LINE-1]]:33: warning: Google Test APIs named with 'case'
834 // CHECK-FIXES: template <typename T = testing::TestSuite>
835 class TestTypeHolder {};
836
837 template <>
838 class TestTypeHolder<testing::TestCase> {};
839 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: Google Test APIs named with 'case'
840 // CHECK-FIXES: class TestTypeHolder<testing::TestSuite> {};
841
842 namespace shadow_using_ns {
843
844 using testing::TestCase;
845 // CHECK-MESSAGES: [[@LINE-1]]:16: warning: Google Test APIs named with 'case'
846 // CHECK-FIXES: using testing::TestSuite;
847
testCaseUses(const TestCase & Case)848 const TestCase *testCaseUses(const TestCase &Case) {
849 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: Google Test APIs named with 'case'
850 // CHECK-MESSAGES: [[@LINE-2]]:36: warning: Google Test APIs named with 'case'
851 // CHECK-FIXES: const TestSuite *testCaseUses(const TestSuite &Case) {
852
853 // No change for implicit declarations:
854 auto Lambda = [&Case]() {};
855
856 (void)new TestCase();
857 // CHECK-MESSAGES: [[@LINE-1]]:13: warning: Google Test APIs named with 'case'
858 // CHECK-FIXES: (void)new TestSuite();
859 const TestCase *Result = &Case;
860 // CHECK-MESSAGES: [[@LINE-1]]:9: warning: Google Test APIs named with 'case'
861 // CHECK-FIXES: const TestSuite *Result = &Case;
862 return Result;
863 }
864
865 struct TestCaseHolder {
866 TestCase Case;
867 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: Google Test APIs named with 'case'
868 // CHECK-FIXES: TestSuite Case;
869 };
870
871 class MyTest : public TestCase {};
872 // CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case'
873 // CHECK-FIXES: class MyTest : public TestSuite {};
874
875 template <typename T = TestCase>
876 // CHECK-MESSAGES: [[@LINE-1]]:24: warning: Google Test APIs named with 'case'
877 // CHECK-FIXES: template <typename T = TestSuite>
878 class TestTypeHolder {};
879
880 template <>
881 class TestTypeHolder<TestCase> {};
882 // CHECK-MESSAGES: [[@LINE-1]]:22: warning: Google Test APIs named with 'case'
883 // CHECK-FIXES: class TestTypeHolder<TestSuite> {};
884
885 } // namespace shadow_using_ns
886
shadowTestCaseUses(const shadow_using_ns::TestCase & Case)887 const shadow_using_ns::TestCase *shadowTestCaseUses(
888 const shadow_using_ns::TestCase &Case) {
889 // CHECK-MESSAGES: [[@LINE-2]]:24: warning: Google Test APIs named with 'case'
890 // CHECK-MESSAGES: [[@LINE-2]]:28: warning: Google Test APIs named with 'case'
891 // CHECK-FIXES: const shadow_using_ns::TestSuite *shadowTestCaseUses(
892 // CHECK-FIXES: const shadow_using_ns::TestSuite &Case) {
893
894 // No match for implicit declarations, as in the lambda capture:
895 auto Lambda = [&Case]() {};
896
897 (void)new shadow_using_ns::TestCase();
898 // CHECK-MESSAGES: [[@LINE-1]]:30: warning: Google Test APIs named with 'case'
899 // CHECK-FIXES: (void)new shadow_using_ns::TestSuite();
900 const shadow_using_ns::TestCase *Result = &Case;
901 // CHECK-MESSAGES: [[@LINE-1]]:26: warning: Google Test APIs named with 'case'
902 // CHECK-FIXES: const shadow_using_ns::TestSuite *Result = &Case;
903 return Result;
904 }
905
906 struct ShadowTestCaseHolder {
907 shadow_using_ns::TestCase Case;
908 // CHECK-MESSAGES: [[@LINE-1]]:20: warning: Google Test APIs named with 'case'
909 // CHECK-FIXES: shadow_using_ns::TestSuite Case;
910 };
911
912 class ShadowMyTest : public shadow_using_ns::TestCase {};
913 // CHECK-MESSAGES: [[@LINE-1]]:46: warning: Google Test APIs named with 'case'
914 // CHECK-FIXES: class ShadowMyTest : public shadow_using_ns::TestSuite {};
915
916 template <typename T = shadow_using_ns::TestCase>
917 // CHECK-MESSAGES: [[@LINE-1]]:41: warning: Google Test APIs named with 'case'
918 // CHECK-FIXES: template <typename T = shadow_using_ns::TestSuite>
919 class ShadowTestTypeHolder {};
920
921 template <>
922 class ShadowTestTypeHolder<shadow_using_ns::TestCase> {};
923 // CHECK-MESSAGES: [[@LINE-1]]:45: warning: Google Test APIs named with 'case'
924 // CHECK-FIXES: class ShadowTestTypeHolder<shadow_using_ns::TestSuite> {};
925
926 namespace typedef_ns {
927
928 typedef testing::TestCase MyTestCase;
929 // CHECK-MESSAGES: [[@LINE-1]]:18: warning: Google Test APIs named with 'case'
930 // CHECK-FIXES: typedef testing::TestSuite MyTestCase;
931
testCaseUses(const MyTestCase & Case)932 const MyTestCase *testCaseUses(const MyTestCase &Case) {
933 auto Lambda = [&Case]() {};
934 (void)new MyTestCase();
935 const MyTestCase *Result = &Case;
936 return Result;
937 }
938
939 struct TestCaseHolder {
940 MyTestCase Case;
941 };
942
943 class MyTest : public MyTestCase {};
944
945 template <typename T = MyTestCase>
946 class TestTypeHolder {};
947
948 template <>
949 class TestTypeHolder<MyTestCase> {};
950
951 } // namespace typedef_ns
952
typedefTestCaseUses(const typedef_ns::MyTestCase & Case)953 const typedef_ns::MyTestCase *typedefTestCaseUses(
954 const typedef_ns::MyTestCase &Case) {
955 auto Lambda = [&Case]() {};
956 (void)new typedef_ns::MyTestCase();
957 const typedef_ns::MyTestCase *Result = &Case;
958 return Result;
959 }
960
961 struct TypedefTestCaseHolder {
962 typedef_ns::MyTestCase Case;
963 };
964
965 class TypedefMyTest : public typedef_ns::MyTestCase {};
966 template <typename T = typedef_ns::MyTestCase> class TypedefTestTypeHolder {};
967 template <> class TypedefTestTypeHolder<typedef_ns::MyTestCase> {};
968
969 namespace alias_ns {
970
971 using MyTestCase = testing::TestCase;
972 // CHECK-MESSAGES: [[@LINE-1]]:29: warning: Google Test APIs named with 'case'
973 // CHECK-FIXES: using MyTestCase = testing::TestSuite;
974
testCaseUses(const MyTestCase & Case)975 const MyTestCase *testCaseUses(const MyTestCase &Case) {
976 auto Lambda = [&Case]() {};
977 (void)new MyTestCase();
978 const MyTestCase *Result = &Case;
979 return Result;
980 }
981
982 struct TestCaseHolder {
983 MyTestCase Case;
984 };
985
986 class MyTest : public MyTestCase {};
987 template <typename T = MyTestCase> class TestTypeHolder {};
988 template <> class TestTypeHolder<MyTestCase> {};
989
990 } // namespace alias_ns
991
aliasTestCaseUses(const alias_ns::MyTestCase & Case)992 const alias_ns::MyTestCase *aliasTestCaseUses(
993 const alias_ns::MyTestCase &Case) {
994 auto Lambda = [&Case]() {};
995 (void)new alias_ns::MyTestCase();
996 const alias_ns::MyTestCase *Result = &Case;
997 return Result;
998 }
999
1000 struct AliasTestCaseHolder {
1001 alias_ns::MyTestCase Case;
1002 };
1003
1004 class AliasMyTest : public alias_ns::MyTestCase {};
1005 template <typename T = alias_ns::MyTestCase> class AliasTestTypeHolder {};
1006 template <> class AliasTestTypeHolder<alias_ns::MyTestCase> {};
1007
1008 template <typename T>
templateFunction(const T & t)1009 void templateFunction(const T& t) {
1010 (void)t.current_test_case();
1011 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: Google Test APIs named with 'case'
1012 }
1013
instantiateTemplateFunction(const testing::UnitTest & Test)1014 void instantiateTemplateFunction(const testing::UnitTest &Test) {
1015 templateFunction(Test);
1016 }
1017