Commit 3aa6061a by Alex Titov Committed by Copybara-Service

Remove the side effects between tests in vlog_is_on_test.cc

The original version of the tests did not reset the VLOG levels between tests, which could lead to false positives. This CL fixes the issue by resetting the VLOG levels to their default values before each test.

PiperOrigin-RevId: 675711787
Change-Id: Id311ba0c00a9e929afcddc7346882487fd64ea16
parent abc9b916
......@@ -44,7 +44,23 @@ absl::optional<int> MinLogLevel() {
#endif
}
TEST(VLogIsOn, GlobalWorksWithoutMaxVerbosityAndMinLogLevel) {
// This fixture is used to reset the VLOG levels to their default values before
// each test.
class VLogIsOnTest : public ::testing::Test {
protected:
void SetUp() override { ResetVLogLevels(); }
private:
// Resets the VLOG levels to their default values.
// It is supposed to be called in the SetUp() method of the test fixture to
// eliminate any side effects from other tests.
static void ResetVLogLevels() {
absl::log_internal::UpdateVModule("");
absl::SetGlobalVLogLevel(0);
}
};
TEST_F(VLogIsOnTest, GlobalWorksWithoutMaxVerbosityAndMinLogLevel) {
if (MaxLogVerbosity().has_value() || MinLogLevel().has_value()) {
GTEST_SKIP();
}
......@@ -59,7 +75,7 @@ TEST(VLogIsOn, GlobalWorksWithoutMaxVerbosityAndMinLogLevel) {
VLOG(4) << "spam";
}
TEST(VLogIsOn, FileWorksWithoutMaxVerbosityAndMinLogLevel) {
TEST_F(VLogIsOnTest, FileWorksWithoutMaxVerbosityAndMinLogLevel) {
if (MaxLogVerbosity().has_value() || MinLogLevel().has_value()) {
GTEST_SKIP();
}
......@@ -74,7 +90,7 @@ TEST(VLogIsOn, FileWorksWithoutMaxVerbosityAndMinLogLevel) {
VLOG(4) << "spam";
}
TEST(VLogIsOn, PatternWorksWithoutMaxVerbosityAndMinLogLevel) {
TEST_F(VLogIsOnTest, PatternWorksWithoutMaxVerbosityAndMinLogLevel) {
if (MaxLogVerbosity().has_value() || MinLogLevel().has_value()) {
GTEST_SKIP();
}
......@@ -89,7 +105,7 @@ TEST(VLogIsOn, PatternWorksWithoutMaxVerbosityAndMinLogLevel) {
VLOG(4) << "spam";
}
TEST(VLogIsOn, GlobalDoesNotFilterBelowMaxVerbosity) {
TEST_F(VLogIsOnTest, GlobalDoesNotFilterBelowMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() < 2) {
GTEST_SKIP();
}
......@@ -104,7 +120,7 @@ TEST(VLogIsOn, GlobalDoesNotFilterBelowMaxVerbosity) {
VLOG(2) << "asdf";
}
TEST(VLogIsOn, FileDoesNotFilterBelowMaxVerbosity) {
TEST_F(VLogIsOnTest, FileDoesNotFilterBelowMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() < 2) {
GTEST_SKIP();
}
......@@ -119,7 +135,7 @@ TEST(VLogIsOn, FileDoesNotFilterBelowMaxVerbosity) {
VLOG(2) << "asdf";
}
TEST(VLogIsOn, PatternDoesNotFilterBelowMaxVerbosity) {
TEST_F(VLogIsOnTest, PatternDoesNotFilterBelowMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() < 2) {
GTEST_SKIP();
}
......@@ -134,7 +150,7 @@ TEST(VLogIsOn, PatternDoesNotFilterBelowMaxVerbosity) {
VLOG(2) << "asdf";
}
TEST(VLogIsOn, GlobalFiltersAboveMaxVerbosity) {
TEST_F(VLogIsOnTest, GlobalFiltersAboveMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() >= 4) {
GTEST_SKIP();
}
......@@ -147,7 +163,7 @@ TEST(VLogIsOn, GlobalFiltersAboveMaxVerbosity) {
VLOG(4) << "dfgh";
}
TEST(VLogIsOn, FileFiltersAboveMaxVerbosity) {
TEST_F(VLogIsOnTest, FileFiltersAboveMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() >= 4) {
GTEST_SKIP();
}
......@@ -160,7 +176,7 @@ TEST(VLogIsOn, FileFiltersAboveMaxVerbosity) {
VLOG(4) << "dfgh";
}
TEST(VLogIsOn, PatternFiltersAboveMaxVerbosity) {
TEST_F(VLogIsOnTest, PatternFiltersAboveMaxVerbosity) {
if (!MaxLogVerbosity().has_value() || *MaxLogVerbosity() >= 4) {
GTEST_SKIP();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment