Skip to content

Commit f957b8f

Browse files
committed
[clang-tidy][NFC] Improve naming convention in google-readability-avoid-underscore-in-googletest-name
According to the Google docs, the convention is TEST(TestSuiteName, TestName). Apply that convention to the source code, test and documentation of the check. Differential Revision: https://reviews.llvm.org/D146713
1 parent d30bc9e commit f957b8f

File tree

3 files changed

+133
-132
lines changed

3 files changed

+133
-132
lines changed

clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
4747
if (!isGoogletestTestMacro(MacroName) || !Args ||
4848
Args->getNumMacroArguments() < 2)
4949
return;
50-
const Token *TestCaseNameToken = Args->getUnexpArgument(0);
50+
const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
5151
const Token *TestNameToken = Args->getUnexpArgument(1);
52-
if (!TestCaseNameToken || !TestNameToken)
52+
if (!TestSuiteNameToken || !TestNameToken)
5353
return;
54-
std::string TestCaseNameMaybeDisabled = PP->getSpelling(*TestCaseNameToken);
55-
StringRef TestCaseName = TestCaseNameMaybeDisabled;
56-
TestCaseName.consume_front(KDisabledTestPrefix);
57-
if (TestCaseName.contains('_'))
58-
Check->diag(TestCaseNameToken->getLocation(),
59-
"avoid using \"_\" in test case name \"%0\" according to "
54+
std::string TestSuiteNameMaybeDisabled =
55+
PP->getSpelling(*TestSuiteNameToken);
56+
StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
57+
TestSuiteName.consume_front(KDisabledTestPrefix);
58+
if (TestSuiteName.contains('_'))
59+
Check->diag(TestSuiteNameToken->getLocation(),
60+
"avoid using \"_\" in test suite name \"%0\" according to "
6061
"Googletest FAQ")
61-
<< TestCaseName;
62+
<< TestSuiteName;
6263

6364
std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
6465
StringRef TestName = TestNameMaybeDisabled;

clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
google-readability-avoid-underscore-in-googletest-name
44
======================================================
55

6-
Checks whether there are underscores in googletest test and test case names in
7-
test macros:
6+
Checks whether there are underscores in googletest test suite names and test
7+
names in test macros:
88

99
- ``TEST``
1010
- ``TEST_F``
@@ -18,17 +18,17 @@ For example:
1818

1919
.. code-block:: c++
2020

21-
TEST(TestCaseName, Illegal_TestName) {}
22-
TEST(Illegal_TestCaseName, TestName) {}
21+
TEST(TestSuiteName, Illegal_TestName) {}
22+
TEST(Illegal_TestSuiteName, TestName) {}
2323

24-
would trigger the check. `Underscores are not allowed`_ in test names nor test
25-
case names.
24+
would trigger the check. `Underscores are not allowed`_ in test suite name nor
25+
test names.
2626

27-
The ``DISABLED_`` prefix, which may be used to `disable individual tests`_, is
28-
ignored when checking test names, but the rest of the rest of the test name is
29-
still checked.
27+
The ``DISABLED_`` prefix, which may be used to
28+
`disable test suites and individual tests`_, is removed from the test suite name
29+
and test name before checking for underscores.
3030

3131
This check does not propose any fixes.
3232

3333
.. _Underscores are not allowed: https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
34-
.. _disable individual tests: https://google.github.io/googletest/advanced.html#temporarily-disabling-tests
34+
.. _disable test suites and individual tests: https://google.github.io/googletest/advanced.html#temporarily-disabling-tests

0 commit comments

Comments
 (0)