Re #3637 Show Disabled Tests in testing output
Showing disabled tests is implemented by a new member function on the TestEventListener interface (which is responsible for printing testing output). The new function is called OnTestSkipped and it is invoked when a disabled test is encountered. The PrettyUnitTestResultPrinter has the canonical implementation of this new function. The BriefUnitTestResultPrinter and the EmptyTestEventListener get a nullary implementation. The JsonUnitTestResultPrinter and XmlUnitTestResultPrinter inherit that trivial implementation from the EmptyTestEventListener.
This commit is contained in:
parent
16f637fbf4
commit
3c958ac47c
@ -1123,6 +1123,9 @@ class TestEventListener {
|
||||
// Fired before the test starts.
|
||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||
|
||||
// Fired when skipping a test
|
||||
virtual void OnTestSkipped(const TestInfo& test_info) = 0;
|
||||
|
||||
// Fired after a failed assertion or a SUCCEED() invocation.
|
||||
// If you want to throw an exception from this function to skip to the next
|
||||
// TEST, it must be AssertionException defined above, or inherited from it.
|
||||
@ -1172,6 +1175,7 @@ class EmptyTestEventListener : public TestEventListener {
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestSkipped(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
|
||||
|
@ -2855,20 +2855,21 @@ void UnitTestImpl::RegisterParameterizedTests() {
|
||||
// Creates the test object, runs it, records its result, and then
|
||||
// deletes it.
|
||||
void TestInfo::Run() {
|
||||
if (!should_run_) return;
|
||||
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
|
||||
if (!should_run_) {
|
||||
if (is_disabled_)
|
||||
repeater->OnTestSkipped(*this);
|
||||
return;
|
||||
}
|
||||
|
||||
// Tells UnitTest where to store test result.
|
||||
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
|
||||
impl->set_current_test_info(this);
|
||||
|
||||
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
|
||||
|
||||
// Notifies the unit test event listeners that a test is about to start.
|
||||
repeater->OnTestStart(*this);
|
||||
|
||||
result_.set_start_timestamp(internal::GetTimeInMillis());
|
||||
internal::Timer timer;
|
||||
|
||||
impl->os_stack_trace_getter()->UponLeavingGTest();
|
||||
|
||||
// Creates the test object.
|
||||
@ -3396,6 +3397,7 @@ class PrettyUnitTestResultPrinter : public TestEventListener {
|
||||
#endif // OnTestCaseStart
|
||||
|
||||
void OnTestStart(const TestInfo& test_info) override;
|
||||
void OnTestSkipped(const TestInfo& test_info) override;
|
||||
|
||||
void OnTestPartResult(const TestPartResult& result) override;
|
||||
void OnTestEnd(const TestInfo& test_info) override;
|
||||
@ -3495,6 +3497,13 @@ void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void PrettyUnitTestResultPrinter::OnTestSkipped(const TestInfo& test_info) {
|
||||
ColoredPrintf(GTestColor::kYellow, "[ DISABLED ] ");
|
||||
PrintTestName(test_info.test_suite_name(), test_info.name());
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// Called after an assertion failure.
|
||||
void PrettyUnitTestResultPrinter::OnTestPartResult(
|
||||
const TestPartResult& result) {
|
||||
@ -3697,6 +3706,7 @@ class BriefUnitTestResultPrinter : public TestEventListener {
|
||||
#endif // OnTestCaseStart
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {}
|
||||
void OnTestSkipped(const TestInfo& /*test_info*/) override {}
|
||||
|
||||
void OnTestPartResult(const TestPartResult& result) override;
|
||||
void OnTestEnd(const TestInfo& test_info) override;
|
||||
@ -3803,6 +3813,7 @@ class TestEventRepeater : public TestEventListener {
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestSuiteStart(const TestSuite& parameter) override;
|
||||
void OnTestStart(const TestInfo& test_info) override;
|
||||
void OnTestSkipped(const TestInfo& test_info) override;
|
||||
void OnTestPartResult(const TestPartResult& result) override;
|
||||
void OnTestEnd(const TestInfo& test_info) override;
|
||||
// Legacy API is deprecated but still available
|
||||
@ -3873,6 +3884,7 @@ GTEST_REPEATER_METHOD_(OnTestCaseStart, TestSuite)
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
GTEST_REPEATER_METHOD_(OnTestSuiteStart, TestSuite)
|
||||
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
|
||||
GTEST_REPEATER_METHOD_(OnTestSkipped, TestInfo)
|
||||
GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
|
||||
GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
|
||||
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
|
||||
|
Loading…
Reference in New Issue
Block a user