Implements printing parameters of failed parameterized tests (issue 71).
This commit is contained in:
@@ -792,19 +792,50 @@ INSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
|
||||
// sequence element used to instantiate the test.
|
||||
class NamingTest : public TestWithParam<int> {};
|
||||
|
||||
TEST_P(NamingTest, TestsAreNamedAppropriately) {
|
||||
TEST_P(NamingTest, TestsAreNamedAndCommentedCorrectly) {
|
||||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name());
|
||||
|
||||
Message msg;
|
||||
msg << "TestsAreNamedAppropriately/" << GetParam();
|
||||
EXPECT_STREQ(msg.GetString().c_str(), test_info->name());
|
||||
Message index_stream;
|
||||
index_stream << "TestsAreNamedAndCommentedCorrectly/" << GetParam();
|
||||
EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name());
|
||||
|
||||
const ::std::string comment =
|
||||
"GetParam() = " + ::testing::PrintToString(GetParam());
|
||||
EXPECT_EQ(comment, test_info->comment());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
|
||||
|
||||
// Class that cannot be streamed into an ostream. It needs to be copyable
|
||||
// (and, in case of MSVC, also assignable) in order to be a test parameter
|
||||
// type. Its default copy constructor and assignment operator do exactly
|
||||
// what we need.
|
||||
class Unstreamable {
|
||||
public:
|
||||
explicit Unstreamable(int value) : value_(value) {}
|
||||
|
||||
private:
|
||||
int value_;
|
||||
};
|
||||
|
||||
class CommentTest : public TestWithParam<Unstreamable> {};
|
||||
|
||||
TEST_P(CommentTest, TestsWithUnstreamableParamsCommentedCorrectly) {
|
||||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
const ::std::string comment =
|
||||
"GetParam() = " + ::testing::PrintToString(GetParam());
|
||||
EXPECT_EQ(comment, test_info->comment());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationWithComments,
|
||||
CommentTest,
|
||||
Values(Unstreamable(1)));
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
TEST(CompileTest, CombineIsDefinedOnlyWhenGtestHasParamTestIsDefined) {
|
||||
|
||||
@@ -240,7 +240,7 @@ SUPPORTS_STACK_TRACES = False
|
||||
|
||||
CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and
|
||||
SUPPORTS_TYPED_TESTS and
|
||||
SUPPORTS_THREADS)
|
||||
(SUPPORTS_THREADS or IS_WINDOWS))
|
||||
|
||||
|
||||
class GTestOutputTest(gtest_test_utils.TestCase):
|
||||
|
||||
@@ -87,6 +87,20 @@ TEST(PassingTest, PassingTest1) {
|
||||
TEST(PassingTest, PassingTest2) {
|
||||
}
|
||||
|
||||
// Tests that parameters of failing parameterized tests are printed in the
|
||||
// failing test summary.
|
||||
class FailingParamTest : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(FailingParamTest, Fails) {
|
||||
EXPECT_EQ(1, GetParam());
|
||||
}
|
||||
|
||||
// This generates a test which will fail. Google Test is expected to print
|
||||
// its parameter when it outputs the list of all failed tests.
|
||||
INSTANTIATE_TEST_CASE_P(PrintingFailingParams,
|
||||
FailingParamTest,
|
||||
testing::Values(2));
|
||||
|
||||
// Tests catching a fatal failure in a subroutine.
|
||||
TEST(FatalFailureTest, FatalFailureInSubroutine) {
|
||||
printf("(expecting a failure that x should be 1)\n");
|
||||
|
||||
@@ -7,7 +7,7 @@ Expected: true
|
||||
gtest_output_test_.cc:#: Failure
|
||||
Value of: 3
|
||||
Expected: 2
|
||||
[0;32m[==========] [mRunning 60 tests from 25 test cases.
|
||||
[0;32m[==========] [mRunning 61 tests from 26 test cases.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@@ -411,7 +411,7 @@ Value of: TypeParam()
|
||||
Actual: 0
|
||||
Expected: 1
|
||||
Expected failure
|
||||
[0;31m[ FAILED ] [mTypedTest/0.Failure
|
||||
[0;31m[ FAILED ] [mTypedTest/0.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
|
||||
@@ -422,7 +422,7 @@ Value of: TypeParam()
|
||||
Expected: 1U
|
||||
Which is: 1
|
||||
Expected failure
|
||||
[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure
|
||||
[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
|
||||
[0;32m[----------] [m2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int
|
||||
[0;32m[ RUN ] [mUnsigned/TypedTestP/1.Success
|
||||
[0;32m[ OK ] [mUnsigned/TypedTestP/1.Success
|
||||
@@ -433,7 +433,7 @@ Value of: TypeParam()
|
||||
Expected: 1U
|
||||
Which is: 1
|
||||
Expected failure
|
||||
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure
|
||||
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
|
||||
[0;32m[----------] [m4 tests from ExpectFailureTest
|
||||
[0;32m[ RUN ] [mExpectFailureTest.ExpectFatalFailure
|
||||
(expecting 1 failure)
|
||||
@@ -564,6 +564,13 @@ gtest_output_test_.cc:#: Failure
|
||||
Failed
|
||||
Expected non-fatal failure.
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;32m[----------] [m1 test from PrintingFailingParams/FailingParamTest
|
||||
[0;32m[ RUN ] [mPrintingFailingParams/FailingParamTest.Fails/0
|
||||
gtest_output_test_.cc:#: Failure
|
||||
Value of: GetParam()
|
||||
Actual: 2
|
||||
Expected: 1
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;32m[----------] [mGlobal test environment tear-down
|
||||
BarEnvironment::TearDown() called.
|
||||
gtest_output_test_.cc:#: Failure
|
||||
@@ -573,9 +580,9 @@ FooEnvironment::TearDown() called.
|
||||
gtest_output_test_.cc:#: Failure
|
||||
Failed
|
||||
Expected fatal failure.
|
||||
[0;32m[==========] [m60 tests from 25 test cases ran.
|
||||
[0;32m[==========] [m61 tests from 26 test cases ran.
|
||||
[0;32m[ PASSED ] [m21 tests.
|
||||
[0;31m[ FAILED ] [m39 tests, listed below:
|
||||
[0;31m[ FAILED ] [m40 tests, listed below:
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInNestedSubroutine
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.NonfatalFailureInSubroutine
|
||||
@@ -615,8 +622,9 @@ Expected fatal failure.
|
||||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectFatalFailure
|
||||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectNonFatalFailure
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
|
||||
39 FAILED TESTS
|
||||
40 FAILED TESTS
|
||||
[0;33m YOU HAVE 1 DISABLED TEST
|
||||
|
||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
|
||||
@@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false
|
||||
Expected: true
|
||||
gtest_output_test_.cc:#: error: Value of: 3
|
||||
Expected: 2
|
||||
[==========] Running 61 tests from 27 test cases.
|
||||
[==========] Running 62 tests from 28 test cases.
|
||||
[----------] Global test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@@ -369,7 +369,7 @@ gtest_output_test_.cc:#: error: Value of: TypeParam()
|
||||
Actual: 0
|
||||
Expected: 1
|
||||
Expected failure
|
||||
[ FAILED ] TypedTest/0.Failure
|
||||
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
|
||||
[----------] 2 tests from Unsigned/TypedTestP/0, where TypeParam = unsigned char
|
||||
[ RUN ] Unsigned/TypedTestP/0.Success
|
||||
[ OK ] Unsigned/TypedTestP/0.Success
|
||||
@@ -379,7 +379,7 @@ gtest_output_test_.cc:#: error: Value of: TypeParam()
|
||||
Expected: 1U
|
||||
Which is: 1
|
||||
Expected failure
|
||||
[ FAILED ] Unsigned/TypedTestP/0.Failure
|
||||
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
|
||||
[----------] 2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned int
|
||||
[ RUN ] Unsigned/TypedTestP/1.Success
|
||||
[ OK ] Unsigned/TypedTestP/1.Success
|
||||
@@ -389,7 +389,7 @@ gtest_output_test_.cc:#: error: Value of: TypeParam()
|
||||
Expected: 1U
|
||||
Which is: 1
|
||||
Expected failure
|
||||
[ FAILED ] Unsigned/TypedTestP/1.Failure
|
||||
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
|
||||
[----------] 4 tests from ExpectFailureTest
|
||||
[ RUN ] ExpectFailureTest.ExpectFatalFailure
|
||||
(expecting 1 failure)
|
||||
@@ -479,6 +479,12 @@ Failed
|
||||
Expected non-fatal failure.
|
||||
|
||||
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
|
||||
[----------] 1 test from PrintingFailingParams/FailingParamTest
|
||||
[ RUN ] PrintingFailingParams/FailingParamTest.Fails/0
|
||||
gtest_output_test_.cc:#: error: Value of: GetParam()
|
||||
Actual: 2
|
||||
Expected: 1
|
||||
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[----------] Global test environment tear-down
|
||||
BarEnvironment::TearDown() called.
|
||||
gtest_output_test_.cc:#: error: Failed
|
||||
@@ -486,9 +492,9 @@ Expected non-fatal failure.
|
||||
FooEnvironment::TearDown() called.
|
||||
gtest_output_test_.cc:#: error: Failed
|
||||
Expected fatal failure.
|
||||
[==========] 61 tests from 27 test cases ran.
|
||||
[==========] 62 tests from 28 test cases ran.
|
||||
[ PASSED ] 21 tests.
|
||||
[ FAILED ] 40 tests, listed below:
|
||||
[ FAILED ] 41 tests, listed below:
|
||||
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
|
||||
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
|
||||
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
|
||||
@@ -529,8 +535,9 @@ Expected fatal failure.
|
||||
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
|
||||
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
|
||||
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
|
||||
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
|
||||
40 FAILED TESTS
|
||||
41 FAILED TESTS
|
||||
YOU HAVE 1 DISABLED TEST
|
||||
|
||||
Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
|
||||
Reference in New Issue
Block a user