Skip to content

Commit

Permalink
Allow clients to un-suppress output from gUnit EXPECT_EXIT tests.
Browse files Browse the repository at this point in the history
This is useful for running individual tests in a separate process, which is
useful for testing e.g. flag changes which have a process-global effect.

PiperOrigin-RevId: 540580573
Change-Id: I18a5d24d79425a9d595be3369efc44e2f655f6f8
  • Loading branch information
Abseil Team authored and copybara-github committed Jun 15, 2023
1 parent 4c7aee8 commit 18fa6a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion googletest/include/gtest/gtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ class GTEST_API_ TestEventListeners {
return default_xml_generator_;
}

// Controls whether events will be forwarded by the repeater to the
// listeners in the list.
void SuppressEventForwarding(bool);

private:
friend class TestSuite;
friend class TestInfo;
Expand Down Expand Up @@ -1084,7 +1088,6 @@ class GTEST_API_ TestEventListeners {
// Controls whether events will be forwarded by the repeater to the
// listeners in the list.
bool EventForwardingEnabled() const;
void SuppressEventForwarding();

// The actual list of listeners.
internal::TestEventRepeater* repeater_;
Expand Down
2 changes: 1 addition & 1 deletion googletest/src/gtest-death-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
LogToStderr();
// Event forwarding to the listeners of event listener API mush be shut
// down in death test subprocesses.
GetUnitTestImpl()->listeners()->SuppressEventForwarding();
GetUnitTestImpl()->listeners()->SuppressEventForwarding(true);
g_in_fast_death_test_child = true;
return EXECUTE_TEST;
} else {
Expand Down
6 changes: 3 additions & 3 deletions googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5156,8 +5156,8 @@ bool TestEventListeners::EventForwardingEnabled() const {
return repeater_->forwarding_enabled();
}

void TestEventListeners::SuppressEventForwarding() {
repeater_->set_forwarding_enabled(false);
void TestEventListeners::SuppressEventForwarding(bool suppress) {
repeater_->set_forwarding_enabled(!suppress);
}

// class UnitTest
Expand Down Expand Up @@ -5635,7 +5635,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
// subprocess. Must not be called before InitGoogleTest.
void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
if (internal_run_death_test_flag_ != nullptr)
listeners()->SuppressEventForwarding();
listeners()->SuppressEventForwarding(true);
}
#endif // GTEST_HAS_DEATH_TEST

Expand Down
2 changes: 1 addition & 1 deletion googletest/test/gtest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class TestEventListenersAccessor {
}

static void SuppressEventForwarding(TestEventListeners* listeners) {
listeners->SuppressEventForwarding();
listeners->SuppressEventForwarding(true);
}
};

Expand Down

0 comments on commit 18fa6a4

Please sign in to comment.