Skip to content

Commit

Permalink
[clang-tidy][NFC] Improve naming convention in google-readability-avo…
Browse files Browse the repository at this point in the history
…id-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
  • Loading branch information
carlosgalvezp committed Mar 24, 2023
1 parent d30bc9e commit f957b8f
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public PPCallbacks {
if (!isGoogletestTestMacro(MacroName) || !Args ||
Args->getNumMacroArguments() < 2)
return;
const Token *TestCaseNameToken = Args->getUnexpArgument(0);
const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
const Token *TestNameToken = Args->getUnexpArgument(1);
if (!TestCaseNameToken || !TestNameToken)
if (!TestSuiteNameToken || !TestNameToken)
return;
std::string TestCaseNameMaybeDisabled = PP->getSpelling(*TestCaseNameToken);
StringRef TestCaseName = TestCaseNameMaybeDisabled;
TestCaseName.consume_front(KDisabledTestPrefix);
if (TestCaseName.contains('_'))
Check->diag(TestCaseNameToken->getLocation(),
"avoid using \"_\" in test case name \"%0\" according to "
std::string TestSuiteNameMaybeDisabled =
PP->getSpelling(*TestSuiteNameToken);
StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
TestSuiteName.consume_front(KDisabledTestPrefix);
if (TestSuiteName.contains('_'))
Check->diag(TestSuiteNameToken->getLocation(),
"avoid using \"_\" in test suite name \"%0\" according to "
"Googletest FAQ")
<< TestCaseName;
<< TestSuiteName;

std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
StringRef TestName = TestNameMaybeDisabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
google-readability-avoid-underscore-in-googletest-name
======================================================

Checks whether there are underscores in googletest test and test case names in
test macros:
Checks whether there are underscores in googletest test suite names and test
names in test macros:

- ``TEST``
- ``TEST_F``
Expand All @@ -18,17 +18,17 @@ For example:

.. code-block:: c++

TEST(TestCaseName, Illegal_TestName) {}
TEST(Illegal_TestCaseName, TestName) {}
TEST(TestSuiteName, Illegal_TestName) {}
TEST(Illegal_TestSuiteName, TestName) {}

would trigger the check. `Underscores are not allowed`_ in test names nor test
case names.
would trigger the check. `Underscores are not allowed`_ in test suite name nor
test names.

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

This check does not propose any fixes.

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

0 comments on commit f957b8f

Please sign in to comment.