diff options
author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2018-08-30 02:57:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 02:57:12 (GMT) |
commit | b8e2562086ef326a4a88089f85b29ce7b6f9464b (patch) | |
tree | fe224846be47cb3240729c7b967a11d211ce707c /googletest/test | |
parent | 3dbba3b072b1e67c5dc6793741da4b5408f8a552 (diff) | |
parent | 9ad739833e16daa0f2909da7daee19a9dd608f29 (diff) | |
download | googletest-b8e2562086ef326a4a88089f85b29ce7b6f9464b.zip googletest-b8e2562086ef326a4a88089f85b29ce7b6f9464b.tar.gz googletest-b8e2562086ef326a4a88089f85b29ce7b6f9464b.tar.bz2 |
Merge pull request #1790 from google/9A681768AABE08D1EFA5CA77528236A4
Googletest export
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/googletest-output-test-golden-lin.txt | 60 | ||||
-rw-r--r-- | googletest/test/googletest-output-test_.cc | 46 | ||||
-rw-r--r-- | googletest/test/gtest-typed-test_test.cc | 82 |
3 files changed, 182 insertions, 6 deletions
diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index b0c5189..7711cdc 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 68 tests from 30 test cases. +[0;32m[==========] [mRunning 76 tests from 34 test cases. [0;32m[----------] [mGlobal test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -606,6 +606,24 @@ Expected failure Stack trace: (omitted) [0;31m[ FAILED ] [mTypedTest/0.Failure, where TypeParam = int +[0;32m[----------] [m2 tests from TypedTestWithNames/char_0, where TypeParam = char +[0;32m[ RUN ] [mTypedTestWithNames/char_0.Success +[0;32m[ OK ] [mTypedTestWithNames/char_0.Success +[0;32m[ RUN ] [mTypedTestWithNames/char_0.Failure +googletest-output-test_.cc:#: Failure +Failed +Stack trace: (omitted) + +[0;31m[ FAILED ] [mTypedTestWithNames/char_0.Failure, where TypeParam = char +[0;32m[----------] [m2 tests from TypedTestWithNames/int_1, where TypeParam = int +[0;32m[ RUN ] [mTypedTestWithNames/int_1.Success +[0;32m[ OK ] [mTypedTestWithNames/int_1.Success +[0;32m[ RUN ] [mTypedTestWithNames/int_1.Failure +googletest-output-test_.cc:#: Failure +Failed +Stack trace: (omitted) + +[0;31m[ FAILED ] [mTypedTestWithNames/int_1.Failure, where TypeParam = int [0;32m[----------] [m2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char [0;32m[ RUN ] [mUnsigned/TypedTestP/0.Success [0;32m[ OK ] [mUnsigned/TypedTestP/0.Success @@ -634,6 +652,34 @@ Expected failure Stack trace: (omitted) [0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned int +[0;32m[----------] [m2 tests from UnsignedCustomName/TypedTestP/unsigned_char_0, where TypeParam = unsigned char +[0;32m[ RUN ] [mUnsignedCustomName/TypedTestP/unsigned_char_0.Success +[0;32m[ OK ] [mUnsignedCustomName/TypedTestP/unsigned_char_0.Success +[0;32m[ RUN ] [mUnsignedCustomName/TypedTestP/unsigned_char_0.Failure +googletest-output-test_.cc:#: Failure +Expected equality of these values: + 1U + Which is: 1 + TypeParam() + Which is: '\0' +Expected failure +Stack trace: (omitted) + +[0;31m[ FAILED ] [mUnsignedCustomName/TypedTestP/unsigned_char_0.Failure, where TypeParam = unsigned char +[0;32m[----------] [m2 tests from UnsignedCustomName/TypedTestP/unsigned_int_1, where TypeParam = unsigned int +[0;32m[ RUN ] [mUnsignedCustomName/TypedTestP/unsigned_int_1.Success +[0;32m[ OK ] [mUnsignedCustomName/TypedTestP/unsigned_int_1.Success +[0;32m[ RUN ] [mUnsignedCustomName/TypedTestP/unsigned_int_1.Failure +googletest-output-test_.cc:#: Failure +Expected equality of these values: + 1U + Which is: 1 + TypeParam() + Which is: 0 +Expected failure +Stack trace: (omitted) + +[0;31m[ FAILED ] [mUnsignedCustomName/TypedTestP/unsigned_int_1.Failure, where TypeParam = unsigned int [0;32m[----------] [m4 tests from ExpectFailureTest [0;32m[ RUN ] [mExpectFailureTest.ExpectFatalFailure (expecting 1 failure) @@ -860,9 +906,9 @@ Failed Expected fatal failure. Stack trace: (omitted) -[0;32m[==========] [m68 tests from 30 test cases ran. -[0;32m[ PASSED ] [m22 tests. -[0;31m[ FAILED ] [m46 tests, listed below: +[0;32m[==========] [m76 tests from 34 test cases ran. +[0;32m[ PASSED ] [m26 tests. +[0;31m[ FAILED ] [m50 tests, listed below: [0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands [0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings [0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine @@ -898,8 +944,12 @@ Stack trace: (omitted) [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenStatementReturns [0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenStatementThrows [0;31m[ FAILED ] [mTypedTest/0.Failure, where TypeParam = int +[0;31m[ FAILED ] [mTypedTestWithNames/char_0.Failure, where TypeParam = char +[0;31m[ FAILED ] [mTypedTestWithNames/int_1.Failure, where TypeParam = int [0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure, where TypeParam = unsigned char [0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned int +[0;31m[ FAILED ] [mUnsignedCustomName/TypedTestP/unsigned_char_0.Failure, where TypeParam = unsigned char +[0;31m[ FAILED ] [mUnsignedCustomName/TypedTestP/unsigned_int_1.Failure, where TypeParam = unsigned int [0;31m[ FAILED ] [mExpectFailureTest.ExpectFatalFailure [0;31m[ FAILED ] [mExpectFailureTest.ExpectNonFatalFailure [0;31m[ FAILED ] [mExpectFailureTest.ExpectFatalFailureOnAllThreads @@ -910,7 +960,7 @@ Stack trace: (omitted) [0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a" -46 FAILED TESTS +50 FAILED TESTS [0;33m YOU HAVE 1 DISABLED TEST [mNote: Google Test filter = FatalFailureTest.*:LoggingTest.* diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 3860cf4..180630e 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -39,6 +39,10 @@ #include <stdlib.h> +#if _MSC_VER + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */) +#endif // . _MSC_VER + #if GTEST_IS_THREADSAFE using testing::ScopedFakeTestPartResultReporter; using testing::TestPartResultArray; @@ -801,6 +805,28 @@ TYPED_TEST(TypedTest, Failure) { EXPECT_EQ(1, TypeParam()) << "Expected failure"; } +typedef testing::Types<char, int> TypesForTestWithNames; + +template <typename T> +class TypedTestWithNames : public testing::Test {}; + +class TypedTestNames { + public: + template <typename T> + static std::string GetName(int i) { + if (testing::internal::IsSame<T, char>::value) + return std::string("char_") + ::testing::PrintToString(i); + if (testing::internal::IsSame<T, int>::value) + return std::string("int_") + ::testing::PrintToString(i); + } +}; + +TYPED_TEST_CASE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames); + +TYPED_TEST(TypedTestWithNames, Success) {} + +TYPED_TEST(TypedTestWithNames, Failure) { FAIL(); } + #endif // GTEST_HAS_TYPED_TEST // This #ifdef block tests the output of type-parameterized tests. @@ -825,6 +851,22 @@ REGISTER_TYPED_TEST_CASE_P(TypedTestP, Success, Failure); typedef testing::Types<unsigned char, unsigned int> UnsignedTypes; INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes); +class TypedTestPNames { + public: + template <typename T> + static std::string GetName(int i) { + if (testing::internal::IsSame<T, unsigned char>::value) { + return std::string("unsigned_char_") + ::testing::PrintToString(i); + } + if (testing::internal::IsSame<T, unsigned int>::value) { + return std::string("unsigned_int_") + ::testing::PrintToString(i); + } + } +}; + +INSTANTIATE_TYPED_TEST_CASE_P(UnsignedCustomName, TypedTestP, UnsignedTypes, + TypedTestPNames); + #endif // GTEST_HAS_TYPED_TEST_P #if GTEST_HAS_DEATH_TEST @@ -1060,6 +1102,8 @@ int main(int argc, char **argv) { // are registered, and torn down in the reverse order. testing::AddGlobalTestEnvironment(new FooEnvironment); testing::AddGlobalTestEnvironment(new BarEnvironment); - +#if _MSC_VER + GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127 +#endif // . _MSC_VER return RunAllTests(); } diff --git a/googletest/test/gtest-typed-test_test.cc b/googletest/test/gtest-typed-test_test.cc index eddb52b..c38bb94 100644 --- a/googletest/test/gtest-typed-test_test.cc +++ b/googletest/test/gtest-typed-test_test.cc @@ -35,6 +35,10 @@ #include "gtest/gtest.h" +#if _MSC_VER +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */) +#endif // _MSC_VER + using testing::Test; // Used for testing that SetUpTestCase()/TearDownTestCase(), fixture @@ -165,6 +169,40 @@ TYPED_TEST(NumericTest, DefaultIsZero) { } // namespace library1 +// Tests that custom names work. +template <typename T> +class TypedTestWithNames : public Test {}; + +class TypedTestNames { + public: + template <typename T> + static std::string GetName(int i) { + if (testing::internal::IsSame<T, char>::value) { + return std::string("char_") + ::testing::PrintToString(i); + } + if (testing::internal::IsSame<T, int>::value) { + return std::string("int_") + ::testing::PrintToString(i); + } + } +}; + +TYPED_TEST_CASE(TypedTestWithNames, TwoTypes, TypedTestNames); + +TYPED_TEST(TypedTestWithNames, TestCaseName) { + if (testing::internal::IsSame<TypeParam, char>::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "TypedTestWithNames/char_0"); + } + if (testing::internal::IsSame<TypeParam, int>::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "TypedTestWithNames/int_1"); + } +} + #endif // GTEST_HAS_TYPED_TEST // This #ifdef block tests type-parameterized tests. @@ -265,6 +303,46 @@ REGISTER_TYPED_TEST_CASE_P(DerivedTest, typedef Types<short, long> MyTwoTypes; INSTANTIATE_TYPED_TEST_CASE_P(My, DerivedTest, MyTwoTypes); +// Tests that custom names work with type parametrized tests. We reuse the +// TwoTypes from above here. +template <typename T> +class TypeParametrizedTestWithNames : public Test {}; + +TYPED_TEST_CASE_P(TypeParametrizedTestWithNames); + +TYPED_TEST_P(TypeParametrizedTestWithNames, TestCaseName) { + if (testing::internal::IsSame<TypeParam, char>::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "CustomName/TypeParametrizedTestWithNames/p_char_0"); + } + if (testing::internal::IsSame<TypeParam, int>::value) { + EXPECT_STREQ(::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_case_name(), + "CustomName/TypeParametrizedTestWithNames/p_int_1"); + } +} + +REGISTER_TYPED_TEST_CASE_P(TypeParametrizedTestWithNames, TestCaseName); + +class TypeParametrizedTestNames { + public: + template <typename T> + static std::string GetName(int i) { + if (testing::internal::IsSame<T, char>::value) { + return std::string("p_char_") + ::testing::PrintToString(i); + } + if (testing::internal::IsSame<T, int>::value) { + return std::string("p_int_") + ::testing::PrintToString(i); + } + } +}; + +INSTANTIATE_TYPED_TEST_CASE_P(CustomName, TypeParametrizedTestWithNames, + TwoTypes, TypeParametrizedTestNames); + // Tests that multiple TYPED_TEST_CASE_P's can be defined in the same // translation unit. @@ -376,4 +454,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, TrimmedTest, TrimTypes); // must be defined). This dummy test keeps gtest_main linked in. TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {} +#if _MSC_VER +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127 +#endif // _MSC_VER + #endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P) |