diff options
author | Abseil Team <absl-team@google.com> | 2019-12-11 03:43:25 (GMT) |
---|---|---|
committer | Matt Calabrese <calabrese@x.team> | 2019-12-13 17:57:44 (GMT) |
commit | d442089d53cecbba59b2d8f35d06eac01f1e46da (patch) | |
tree | 801a0c8322372642cdb5a88647e621c209f61738 /googletest/test | |
parent | 88ba008c234a1d4e54c62dfc71b4060696a86f36 (diff) | |
download | googletest-d442089d53cecbba59b2d8f35d06eac01f1e46da.zip googletest-d442089d53cecbba59b2d8f35d06eac01f1e46da.tar.gz googletest-d442089d53cecbba59b2d8f35d06eac01f1e46da.tar.bz2 |
Googletest export
Detect when C++ parametric tests (TEST_P) are not instantiated.
When an un-instantiated TEST_P is found, a new test will be inserted that will emit a warning message.
This can be made to error with minor code edits.
In the future, that is intended to be the default.
PiperOrigin-RevId: 284901666
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/googletest-output-test-golden-lin.txt | 12 | ||||
-rw-r--r-- | googletest/test/googletest-output-test_.cc | 7 | ||||
-rw-r--r-- | googletest/test/googletest-param-test-test.cc | 6 |
3 files changed, 22 insertions, 3 deletions
diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 270b15a..27f9d48 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[0;32m[==========] [mRunning 84 tests from 39 test suites. +[0;32m[==========] [mRunning 85 tests from 40 test suites. [0;32m[----------] [mGlobal test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -979,6 +979,12 @@ Expected failure Stack trace: (omitted) [0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a" +[0;32m[----------] [m1 test from GoogleTestVerification +[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest> +Paramaterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing. + +Ideally, TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.) +[0;32m[ OK ] [mGoogleTestVerification.UninstantiatedParamaterizedTestSuite<DetectNotInstantiatedTest> [0;32m[----------] [mGlobal test environment tear-down BarEnvironment::TearDown() called. googletest-output-test_.cc:#: Failure @@ -992,8 +998,8 @@ Failed Expected fatal failure. Stack trace: (omitted) -[0;32m[==========] [m84 tests from 39 test suites ran. -[0;32m[ PASSED ] [m30 tests. +[0;32m[==========] [m85 tests from 40 test suites ran. +[0;32m[ PASSED ] [m31 tests. [0;31m[ FAILED ] [m54 tests, listed below: [0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands [0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index f724cca..fe0d83f 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -782,6 +782,13 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings, testing::Values(std::string("a")), ParamNameFunc); +// fails under kErrorOnUninstantiatedParameterizedTest=true +class DetectNotInstantiatedTest : public testing::TestWithParam<int> {}; +TEST_P(DetectNotInstantiatedTest, Used) { } + +// This would make the test failure from the above go away. +// INSTANTIATE_TEST_SUITE_P(Fix, DetectNotInstantiatedTest, testing::Values(1)); + // This #ifdef block tests the output of typed tests. #if GTEST_HAS_TYPED_TEST diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 2740aaa..85c76c3 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -1068,6 +1068,12 @@ TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); } INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest, ::testing::Values(ENUM1, ENUM2, 0)); +namespace works_here { +// Never used not instantiated, this should work. +class NotUsedTest : public testing::TestWithParam<int> {}; + +} // namespace works_here + int main(int argc, char **argv) { // Used in TestGenerationTest test suite. AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); |