summaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorGennadiy Civil <gennadiycivil@users.noreply.github.com>2018-08-30 02:57:12 (GMT)
committerGitHub <noreply@github.com>2018-08-30 02:57:12 (GMT)
commitb8e2562086ef326a4a88089f85b29ce7b6f9464b (patch)
treefe224846be47cb3240729c7b967a11d211ce707c /googletest/test
parent3dbba3b072b1e67c5dc6793741da4b5408f8a552 (diff)
parent9ad739833e16daa0f2909da7daee19a9dd608f29 (diff)
downloadgoogletest-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.txt60
-rw-r--r--googletest/test/googletest-output-test_.cc46
-rw-r--r--googletest/test/gtest-typed-test_test.cc82
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)
-[==========] Running 68 tests from 30 test cases.
+[==========] Running 76 tests from 34 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
@@ -606,6 +606,24 @@ Expected failure
Stack trace: (omitted)
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
+[----------] 2 tests from TypedTestWithNames/char_0, where TypeParam = char
+[ RUN ] TypedTestWithNames/char_0.Success
+[ OK ] TypedTestWithNames/char_0.Success
+[ RUN ] TypedTestWithNames/char_0.Failure
+googletest-output-test_.cc:#: Failure
+Failed
+Stack trace: (omitted)
+
+[ FAILED ] TypedTestWithNames/char_0.Failure, where TypeParam = char
+[----------] 2 tests from TypedTestWithNames/int_1, where TypeParam = int
+[ RUN ] TypedTestWithNames/int_1.Success
+[ OK ] TypedTestWithNames/int_1.Success
+[ RUN ] TypedTestWithNames/int_1.Failure
+googletest-output-test_.cc:#: Failure
+Failed
+Stack trace: (omitted)
+
+[ FAILED ] TypedTestWithNames/int_1.Failure, where TypeParam = int
[----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char
[ RUN ] Unsigned/TypedTestP/0.Success
[ OK ] Unsigned/TypedTestP/0.Success
@@ -634,6 +652,34 @@ Expected failure
Stack trace: (omitted)
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
+[----------] 2 tests from UnsignedCustomName/TypedTestP/unsigned_char_0, where TypeParam = unsigned char
+[ RUN ] UnsignedCustomName/TypedTestP/unsigned_char_0.Success
+[ OK ] UnsignedCustomName/TypedTestP/unsigned_char_0.Success
+[ RUN ] UnsignedCustomName/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)
+
+[ FAILED ] UnsignedCustomName/TypedTestP/unsigned_char_0.Failure, where TypeParam = unsigned char
+[----------] 2 tests from UnsignedCustomName/TypedTestP/unsigned_int_1, where TypeParam = unsigned int
+[ RUN ] UnsignedCustomName/TypedTestP/unsigned_int_1.Success
+[ OK ] UnsignedCustomName/TypedTestP/unsigned_int_1.Success
+[ RUN ] UnsignedCustomName/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)
+
+[ FAILED ] UnsignedCustomName/TypedTestP/unsigned_int_1.Failure, where TypeParam = unsigned int
[----------] 4 tests from ExpectFailureTest
[ RUN ] ExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
@@ -860,9 +906,9 @@ Failed
Expected fatal failure.
Stack trace: (omitted)
-[==========] 68 tests from 30 test cases ran.
-[ PASSED ] 22 tests.
-[ FAILED ] 46 tests, listed below:
+[==========] 76 tests from 34 test cases ran.
+[ PASSED ] 26 tests.
+[ FAILED ] 50 tests, listed below:
[ FAILED ] NonfatalFailureTest.EscapesStringOperands
[ FAILED ] NonfatalFailureTest.DiffForLongStrings
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
@@ -898,8 +944,12 @@ Stack trace: (omitted)
[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns
[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementThrows
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
+[ FAILED ] TypedTestWithNames/char_0.Failure, where TypeParam = char
+[ FAILED ] TypedTestWithNames/int_1.Failure, where TypeParam = int
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
+[ FAILED ] UnsignedCustomName/TypedTestP/unsigned_char_0.Failure, where TypeParam = unsigned char
+[ FAILED ] UnsignedCustomName/TypedTestP/unsigned_int_1.Failure, where TypeParam = unsigned int
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
@@ -910,7 +960,7 @@ Stack trace: (omitted)
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
-46 FAILED TESTS
+50 FAILED TESTS
 YOU HAVE 1 DISABLED TEST
Note: 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)