diff options
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/googletest-death-test-test.cc | 54 | ||||
-rw-r--r-- | googletest/test/googletest-death-test_ex_test.cc | 6 | ||||
-rw-r--r-- | googletest/test/googletest-env-var-test_.cc | 26 | ||||
-rw-r--r-- | googletest/test/googletest-listener-test.cc | 2 | ||||
-rw-r--r-- | googletest/test/googletest-options-test.cc | 24 | ||||
-rw-r--r-- | googletest/test/googletest-output-test_.cc | 4 | ||||
-rw-r--r-- | googletest/test/gtest_environment_test.cc | 6 | ||||
-rw-r--r-- | googletest/test/gtest_repeat_test.cc | 30 | ||||
-rw-r--r-- | googletest/test/gtest_throw_on_failure_ex_test.cc | 2 | ||||
-rw-r--r-- | googletest/test/gtest_unittest.cc | 271 |
10 files changed, 194 insertions, 231 deletions
diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index c0b3d1f..e7e0cd7 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -370,14 +370,14 @@ TEST_F(TestForDeathTest, SwitchStatement) { // Tests that a static member function can be used in a "fast" style // death test. TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); ASSERT_DEATH(StaticMemberFunction(), "death.*StaticMember"); } // Tests that a method of the test fixture can be used in a "fast" // style death test. TEST_F(TestForDeathTest, MemberFunctionFastStyle) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); should_die_ = true; EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction"); } @@ -387,7 +387,7 @@ void ChangeToRootDir() { posix::ChDir(GTEST_PATH_SEP_); } // Tests that death tests work even if the current directory has been // changed. TEST_F(TestForDeathTest, FastDeathTestInChangedDir) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); ChangeToRootDir(); EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); @@ -432,7 +432,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) { // Tests that death tests work when SIGPROF handler and timer are set. TEST_F(TestForDeathTest, FastSigprofActionSet) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); SetSigprofActionAndTimer(); EXPECT_DEATH(_exit(1), ""); struct sigaction old_signal_action; @@ -441,7 +441,7 @@ TEST_F(TestForDeathTest, FastSigprofActionSet) { } TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); SetSigprofActionAndTimer(); EXPECT_DEATH(_exit(1), ""); struct sigaction old_signal_action; @@ -453,25 +453,25 @@ TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) { // Repeats a representative sample of death tests in the "threadsafe" style: TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); ASSERT_DEATH(StaticMemberFunction(), "death.*StaticMember"); } TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); should_die_ = true; EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction"); } TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); for (int i = 0; i < 3; ++i) EXPECT_EXIT(_exit(i), testing::ExitedWithCode(i), "") << ": i = " << i; } TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); ChangeToRootDir(); EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); @@ -481,9 +481,9 @@ TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) { } TEST_F(TestForDeathTest, MixedStyles) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); EXPECT_DEATH(_exit(1), ""); - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_DEATH(_exit(1), ""); } @@ -496,8 +496,8 @@ void SetPthreadFlag() { } TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) { - if (!testing::GTEST_FLAG(death_test_use_fork)) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + if (!GTEST_FLAG_GET(death_test_use_fork)) { + GTEST_FLAG_SET(death_test_style, "threadsafe"); pthread_flag = false; ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr)); ASSERT_DEATH(_exit(1), ""); @@ -740,10 +740,12 @@ TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { "any pop-up dialogs.\n"); fflush(stdout); - EXPECT_DEATH({ - testing::GTEST_FLAG(catch_exceptions) = false; - abort(); - }, ""); + EXPECT_DEATH( + { + GTEST_FLAG_SET(catch_exceptions, false); + abort(); + }, + ""); } # endif // GTEST_OS_WINDOWS @@ -874,19 +876,19 @@ TEST_F(TestForDeathTest, ExitMacros) { } TEST_F(TestForDeathTest, ExitMacrosUsingFork) { - testing::GTEST_FLAG(death_test_use_fork) = true; + GTEST_FLAG_SET(death_test_use_fork, true); TestExitMacros(); } TEST_F(TestForDeathTest, InvalidStyle) { - testing::GTEST_FLAG(death_test_style) = "rococo"; + GTEST_FLAG_SET(death_test_style, "rococo"); EXPECT_NONFATAL_FAILURE({ // NOLINT EXPECT_DEATH(_exit(0), "") << "This failure is expected."; }, "This failure is expected."); } TEST_F(TestForDeathTest, DeathTestFailedOutput) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_NONFATAL_FAILURE( EXPECT_DEATH(DieWithMessage("death\n"), "expected message"), @@ -895,7 +897,7 @@ TEST_F(TestForDeathTest, DeathTestFailedOutput) { } TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_NONFATAL_FAILURE( EXPECT_DEATH({ fprintf(stderr, "returning\n"); @@ -908,7 +910,7 @@ TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) { } TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_NONFATAL_FAILURE( EXPECT_EXIT(DieWithMessage("exiting with rc 1\n"), testing::ExitedWithCode(3), @@ -920,7 +922,7 @@ TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) { } TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_NONFATAL_FAILURE( EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"), "line 1\nxyz\nline 3\n"), @@ -931,7 +933,7 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) { } TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_DEATH(DieWithMessage("line 1\nline 2\nline 3\n"), "line 1\nline 2\nline 3\n"); } @@ -1358,7 +1360,7 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) { } TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) { - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_FALSE(InDeathTestChild()); EXPECT_DEATH({ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside"); @@ -1368,7 +1370,7 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) { } TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) { - testing::GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); EXPECT_FALSE(InDeathTestChild()); EXPECT_DEATH({ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside"); diff --git a/googletest/test/googletest-death-test_ex_test.cc b/googletest/test/googletest-death-test_ex_test.cc index 7219680..bbacc8a 100644 --- a/googletest/test/googletest-death-test_ex_test.cc +++ b/googletest/test/googletest-death-test_ex_test.cc @@ -53,7 +53,7 @@ TEST(CxxExceptionDeathTest, ExceptionIsFailure) { } catch (...) { // NOLINT FAIL() << "An exception escaped a death test macro invocation " << "with catch_exceptions " - << (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); + << (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled"); } } @@ -79,7 +79,7 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { EXPECT_DEATH(RaiseException(42, 0x0, 0, NULL), "") << "with catch_exceptions " - << (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); + << (GTEST_FLAG_GET(catch_exceptions) ? "enabled" : "disabled"); } # endif @@ -87,6 +87,6 @@ TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); - testing::GTEST_FLAG(catch_exceptions) = GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0; + GTEST_FLAG_SET(catch_exceptions, GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0); return RUN_ALL_TESTS(); } diff --git a/googletest/test/googletest-env-var-test_.cc b/googletest/test/googletest-env-var-test_.cc index 52f9586..0ff0152 100644 --- a/googletest/test/googletest-env-var-test_.cc +++ b/googletest/test/googletest-env-var-test_.cc @@ -48,67 +48,67 @@ TEST(GTestEnvVarTest, Dummy) { void PrintFlag(const char* flag) { if (strcmp(flag, "break_on_failure") == 0) { - cout << GTEST_FLAG(break_on_failure); + cout << GTEST_FLAG_GET(break_on_failure); return; } if (strcmp(flag, "catch_exceptions") == 0) { - cout << GTEST_FLAG(catch_exceptions); + cout << GTEST_FLAG_GET(catch_exceptions); return; } if (strcmp(flag, "color") == 0) { - cout << GTEST_FLAG(color); + cout << GTEST_FLAG_GET(color); return; } if (strcmp(flag, "death_test_style") == 0) { - cout << GTEST_FLAG(death_test_style); + cout << GTEST_FLAG_GET(death_test_style); return; } if (strcmp(flag, "death_test_use_fork") == 0) { - cout << GTEST_FLAG(death_test_use_fork); + cout << GTEST_FLAG_GET(death_test_use_fork); return; } if (strcmp(flag, "fail_fast") == 0) { - cout << GTEST_FLAG(fail_fast); + cout << GTEST_FLAG_GET(fail_fast); return; } if (strcmp(flag, "filter") == 0) { - cout << GTEST_FLAG(filter); + cout << GTEST_FLAG_GET(filter); return; } if (strcmp(flag, "output") == 0) { - cout << GTEST_FLAG(output); + cout << GTEST_FLAG_GET(output); return; } if (strcmp(flag, "brief") == 0) { - cout << GTEST_FLAG(brief); + cout << GTEST_FLAG_GET(brief); return; } if (strcmp(flag, "print_time") == 0) { - cout << GTEST_FLAG(print_time); + cout << GTEST_FLAG_GET(print_time); return; } if (strcmp(flag, "repeat") == 0) { - cout << GTEST_FLAG(repeat); + cout << GTEST_FLAG_GET(repeat); return; } if (strcmp(flag, "stack_trace_depth") == 0) { - cout << GTEST_FLAG(stack_trace_depth); + cout << GTEST_FLAG_GET(stack_trace_depth); return; } if (strcmp(flag, "throw_on_failure") == 0) { - cout << GTEST_FLAG(throw_on_failure); + cout << GTEST_FLAG_GET(throw_on_failure); return; } diff --git a/googletest/test/googletest-listener-test.cc b/googletest/test/googletest-listener-test.cc index 10457af..9d6c9ca 100644 --- a/googletest/test/googletest-listener-test.cc +++ b/googletest/test/googletest-listener-test.cc @@ -284,7 +284,7 @@ int main(int argc, char **argv) { GTEST_CHECK_(events.size() == 0) << "AddGlobalTestEnvironment should not generate any events itself."; - ::testing::GTEST_FLAG(repeat) = 2; + GTEST_FLAG_SET(repeat, 2); int ret_val = RUN_ALL_TESTS(); #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ diff --git a/googletest/test/googletest-options-test.cc b/googletest/test/googletest-options-test.cc index 11fb1f2..cd386ff 100644 --- a/googletest/test/googletest-options-test.cc +++ b/googletest/test/googletest-options-test.cc @@ -61,29 +61,29 @@ FilePath GetAbsolutePathOf(const FilePath& relative_path) { // Testing UnitTestOptions::GetOutputFormat/GetOutputFile. TEST(XmlOutputTest, GetOutputFormatDefault) { - GTEST_FLAG(output) = ""; + GTEST_FLAG_SET(output, ""); EXPECT_STREQ("", UnitTestOptions::GetOutputFormat().c_str()); } TEST(XmlOutputTest, GetOutputFormat) { - GTEST_FLAG(output) = "xml:filename"; + GTEST_FLAG_SET(output, "xml:filename"); EXPECT_STREQ("xml", UnitTestOptions::GetOutputFormat().c_str()); } TEST(XmlOutputTest, GetOutputFileDefault) { - GTEST_FLAG(output) = ""; + GTEST_FLAG_SET(output, ""); EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(), UnitTestOptions::GetAbsolutePathToOutputFile()); } TEST(XmlOutputTest, GetOutputFileSingleFile) { - GTEST_FLAG(output) = "xml:filename.abc"; + GTEST_FLAG_SET(output, "xml:filename.abc"); EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(), UnitTestOptions::GetAbsolutePathToOutputFile()); } TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { - GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_; + GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_); const std::string expected_output_file = GetAbsolutePathOf( FilePath(std::string("path") + GTEST_PATH_SEP_ + @@ -144,28 +144,28 @@ class XmlOutputChangeDirTest : public Test { }; TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) { - GTEST_FLAG(output) = ""; + GTEST_FLAG_SET(output, ""); EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_, FilePath("test_detail.xml")).string(), UnitTestOptions::GetAbsolutePathToOutputFile()); } TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) { - GTEST_FLAG(output) = "xml"; + GTEST_FLAG_SET(output, "xml"); EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_, FilePath("test_detail.xml")).string(), UnitTestOptions::GetAbsolutePathToOutputFile()); } TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) { - GTEST_FLAG(output) = "xml:filename.abc"; + GTEST_FLAG_SET(output, "xml:filename.abc"); EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_, FilePath("filename.abc")).string(), UnitTestOptions::GetAbsolutePathToOutputFile()); } TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { - GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_; + GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_); const std::string expected_output_file = FilePath::ConcatPaths( original_working_dir_, @@ -182,11 +182,11 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) { #if GTEST_OS_WINDOWS - GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc"; + GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc"); EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(), UnitTestOptions::GetAbsolutePathToOutputFile()); #else - GTEST_FLAG(output) ="xml:/tmp/filename.abc"; + GTEST_FLAG_SET(output, "xml:/tmp/filename.abc"); EXPECT_EQ(FilePath("/tmp/filename.abc").string(), UnitTestOptions::GetAbsolutePathToOutputFile()); #endif @@ -199,7 +199,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) { const std::string path = "/tmp/"; #endif - GTEST_FLAG(output) = "xml:" + path; + GTEST_FLAG_SET(output, "xml:" + path); const std::string expected_output_file = path + GetCurrentExecutableName().string() + ".xml"; const std::string& output_file = diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index 074f64e..9e5465c 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -1066,7 +1066,7 @@ class BarEnvironment : public testing::Environment { // of them are intended to fail), and then compare the test results // with the "golden" file. int main(int argc, char **argv) { - testing::GTEST_FLAG(print_time) = false; + GTEST_FLAG_SET(print_time, false); // We just run the tests, knowing some of them are intended to fail. // We will use a separate Python script to compare the output of @@ -1081,7 +1081,7 @@ int main(int argc, char **argv) { std::string("internal_skip_environment_and_ad_hoc_tests")) > 0; #if GTEST_HAS_DEATH_TEST - if (testing::internal::GTEST_FLAG(internal_run_death_test) != "") { + if (GTEST_FLAG_GET(internal_run_death_test) != "") { // Skip the usual output capturing if we're running as the child // process of an threadsafe-style death test. # if GTEST_OS_WINDOWS diff --git a/googletest/test/gtest_environment_test.cc b/googletest/test/gtest_environment_test.cc index 064bfc5..c7facf5 100644 --- a/googletest/test/gtest_environment_test.cc +++ b/googletest/test/gtest_environment_test.cc @@ -35,10 +35,6 @@ #include "gtest/gtest.h" #include "src/gtest-internal-inl.h" -namespace testing { -GTEST_DECLARE_string_(filter); -} - namespace { enum FailureType { @@ -174,7 +170,7 @@ int main(int argc, char **argv) { // Verifies that RUN_ALL_TESTS() doesn't do global set-up or // tear-down when there is no test to run. - testing::GTEST_FLAG(filter) = "-*"; + GTEST_FLAG_SET(filter, "-*"); Check(RunAllTests(env, NO_FAILURE) == 0, "RUN_ALL_TESTS() should return zero, as there is no test to run."); Check(!env->set_up_was_run(), diff --git a/googletest/test/gtest_repeat_test.cc b/googletest/test/gtest_repeat_test.cc index 7da4a15..c7af3ef 100644 --- a/googletest/test/gtest_repeat_test.cc +++ b/googletest/test/gtest_repeat_test.cc @@ -35,18 +35,6 @@ #include "gtest/gtest.h" #include "src/gtest-internal-inl.h" -namespace testing { - -GTEST_DECLARE_string_(death_test_style); -GTEST_DECLARE_string_(filter); -GTEST_DECLARE_int32_(repeat); - -} // namespace testing - -using testing::GTEST_FLAG(death_test_style); -using testing::GTEST_FLAG(filter); -using testing::GTEST_FLAG(repeat); - namespace { // We need this when we are testing Google Test itself and therefore @@ -103,10 +91,10 @@ int g_death_test_count = 0; TEST(BarDeathTest, ThreadSafeAndFast) { g_death_test_count++; - GTEST_FLAG(death_test_style) = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); - GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); } @@ -153,7 +141,7 @@ void TestRepeatUnspecified() { // Tests the behavior of Google Test when --gtest_repeat has the given value. void TestRepeat(int repeat) { - GTEST_FLAG(repeat) = repeat; + GTEST_FLAG_SET(repeat, repeat); ResetCounts(); GTEST_CHECK_INT_EQ_(repeat > 0 ? 1 : 0, RUN_ALL_TESTS()); @@ -163,8 +151,8 @@ void TestRepeat(int repeat) { // Tests using --gtest_repeat when --gtest_filter specifies an empty // set of tests. void TestRepeatWithEmptyFilter(int repeat) { - GTEST_FLAG(repeat) = repeat; - GTEST_FLAG(filter) = "None"; + GTEST_FLAG_SET(repeat, repeat); + GTEST_FLAG_SET(filter, "None"); ResetCounts(); GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS()); @@ -174,8 +162,8 @@ void TestRepeatWithEmptyFilter(int repeat) { // Tests using --gtest_repeat when --gtest_filter specifies a set of // successful tests. void TestRepeatWithFilterForSuccessfulTests(int repeat) { - GTEST_FLAG(repeat) = repeat; - GTEST_FLAG(filter) = "*-*ShouldFail"; + GTEST_FLAG_SET(repeat, repeat); + GTEST_FLAG_SET(filter, "*-*ShouldFail"); ResetCounts(); GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS()); @@ -190,8 +178,8 @@ void TestRepeatWithFilterForSuccessfulTests(int repeat) { // Tests using --gtest_repeat when --gtest_filter specifies a set of // failed tests. void TestRepeatWithFilterForFailedTests(int repeat) { - GTEST_FLAG(repeat) = repeat; - GTEST_FLAG(filter) = "*ShouldFail"; + GTEST_FLAG_SET(repeat, repeat); + GTEST_FLAG_SET(filter, "*ShouldFail"); ResetCounts(); GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS()); diff --git a/googletest/test/gtest_throw_on_failure_ex_test.cc b/googletest/test/gtest_throw_on_failure_ex_test.cc index 1d95adb..aeead13 100644 --- a/googletest/test/gtest_throw_on_failure_ex_test.cc +++ b/googletest/test/gtest_throw_on_failure_ex_test.cc @@ -50,7 +50,7 @@ void Fail(const char* msg) { // Tests that an assertion failure throws a subclass of // std::runtime_error. void TestFailureThrowsRuntimeError() { - testing::GTEST_FLAG(throw_on_failure) = true; + GTEST_FLAG_SET(throw_on_failure, true); // A successful assertion shouldn't throw. try { diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 402bb6d..3f2f082 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -37,23 +37,19 @@ // code once "gtest.h" has been #included. // Do not move it after other gtest #includes. TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { - bool dummy = testing::GTEST_FLAG(also_run_disabled_tests) || - testing::GTEST_FLAG(break_on_failure) || - testing::GTEST_FLAG(catch_exceptions) || - testing::GTEST_FLAG(color) != "unknown" || - testing::GTEST_FLAG(fail_fast) || - testing::GTEST_FLAG(filter) != "unknown" || - testing::GTEST_FLAG(list_tests) || - testing::GTEST_FLAG(output) != "unknown" || - testing::GTEST_FLAG(brief) || testing::GTEST_FLAG(print_time) || - testing::GTEST_FLAG(random_seed) || - testing::GTEST_FLAG(repeat) > 0 || - testing::GTEST_FLAG(recreate_environments_when_repeating) || - testing::GTEST_FLAG(show_internal_stack_frames) || - testing::GTEST_FLAG(shuffle) || - testing::GTEST_FLAG(stack_trace_depth) > 0 || - testing::GTEST_FLAG(stream_result_to) != "unknown" || - testing::GTEST_FLAG(throw_on_failure); + bool dummy = + GTEST_FLAG_GET(also_run_disabled_tests) || + GTEST_FLAG_GET(break_on_failure) || GTEST_FLAG_GET(catch_exceptions) || + GTEST_FLAG_GET(color) != "unknown" || GTEST_FLAG_GET(fail_fast) || + GTEST_FLAG_GET(filter) != "unknown" || GTEST_FLAG_GET(list_tests) || + GTEST_FLAG_GET(output) != "unknown" || GTEST_FLAG_GET(brief) || + GTEST_FLAG_GET(print_time) || GTEST_FLAG_GET(random_seed) || + GTEST_FLAG_GET(repeat) > 0 || + GTEST_FLAG_GET(recreate_environments_when_repeating) || + GTEST_FLAG_GET(show_internal_stack_frames) || GTEST_FLAG_GET(shuffle) || + GTEST_FLAG_GET(stack_trace_depth) > 0 || + GTEST_FLAG_GET(stream_result_to) != "unknown" || + GTEST_FLAG_GET(throw_on_failure); EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused. } @@ -200,25 +196,6 @@ using testing::DoubleLE; using testing::EmptyTestEventListener; using testing::Environment; using testing::FloatLE; -using testing::GTEST_FLAG(also_run_disabled_tests); -using testing::GTEST_FLAG(break_on_failure); -using testing::GTEST_FLAG(catch_exceptions); -using testing::GTEST_FLAG(color); -using testing::GTEST_FLAG(death_test_use_fork); -using testing::GTEST_FLAG(fail_fast); -using testing::GTEST_FLAG(filter); -using testing::GTEST_FLAG(list_tests); -using testing::GTEST_FLAG(output); -using testing::GTEST_FLAG(brief); -using testing::GTEST_FLAG(print_time); -using testing::GTEST_FLAG(random_seed); -using testing::GTEST_FLAG(repeat); -using testing::GTEST_FLAG(recreate_environments_when_repeating); -using testing::GTEST_FLAG(show_internal_stack_frames); -using testing::GTEST_FLAG(shuffle); -using testing::GTEST_FLAG(stack_trace_depth); -using testing::GTEST_FLAG(stream_result_to); -using testing::GTEST_FLAG(throw_on_failure); using testing::IsNotSubstring; using testing::IsSubstring; using testing::kMaxStackTraceDepth; @@ -267,7 +244,7 @@ using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::NativeArray; using testing::internal::OsStackTraceGetter; using testing::internal::OsStackTraceGetterInterface; -using testing::internal::ParseInt32Flag; +using testing::internal::ParseFlag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; using testing::internal::ShouldRunTestOnShard; @@ -1599,24 +1576,24 @@ class GTestFlagSaverTest : public Test { static void SetUpTestSuite() { saver_ = new GTestFlagSaver; - GTEST_FLAG(also_run_disabled_tests) = false; - GTEST_FLAG(break_on_failure) = false; - GTEST_FLAG(catch_exceptions) = false; - GTEST_FLAG(death_test_use_fork) = false; - GTEST_FLAG(color) = "auto"; - GTEST_FLAG(fail_fast) = false; - GTEST_FLAG(filter) = ""; - GTEST_FLAG(list_tests) = false; - GTEST_FLAG(output) = ""; - GTEST_FLAG(brief) = false; - GTEST_FLAG(print_time) = true; - GTEST_FLAG(random_seed) = 0; - GTEST_FLAG(repeat) = 1; - GTEST_FLAG(recreate_environments_when_repeating) = true; - GTEST_FLAG(shuffle) = false; - GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth; - GTEST_FLAG(stream_result_to) = ""; - GTEST_FLAG(throw_on_failure) = false; + GTEST_FLAG_SET(also_run_disabled_tests, false); + GTEST_FLAG_SET(break_on_failure, false); + GTEST_FLAG_SET(catch_exceptions, false); + GTEST_FLAG_SET(death_test_use_fork, false); + GTEST_FLAG_SET(color, "auto"); + GTEST_FLAG_SET(fail_fast, false); + GTEST_FLAG_SET(filter, ""); + GTEST_FLAG_SET(list_tests, false); + GTEST_FLAG_SET(output, ""); + GTEST_FLAG_SET(brief, false); + GTEST_FLAG_SET(print_time, true); + GTEST_FLAG_SET(random_seed, 0); + GTEST_FLAG_SET(repeat, 1); + GTEST_FLAG_SET(recreate_environments_when_repeating, true); + GTEST_FLAG_SET(shuffle, false); + GTEST_FLAG_SET(stack_trace_depth, kMaxStackTraceDepth); + GTEST_FLAG_SET(stream_result_to, ""); + GTEST_FLAG_SET(throw_on_failure, false); } // Restores the Google Test flags that the tests have modified. This will @@ -1629,43 +1606,43 @@ class GTestFlagSaverTest : public Test { // Verifies that the Google Test flags have their default values, and then // modifies each of them. void VerifyAndModifyFlags() { - EXPECT_FALSE(GTEST_FLAG(also_run_disabled_tests)); - EXPECT_FALSE(GTEST_FLAG(break_on_failure)); - EXPECT_FALSE(GTEST_FLAG(catch_exceptions)); - EXPECT_STREQ("auto", GTEST_FLAG(color).c_str()); - EXPECT_FALSE(GTEST_FLAG(death_test_use_fork)); - EXPECT_FALSE(GTEST_FLAG(fail_fast)); - EXPECT_STREQ("", GTEST_FLAG(filter).c_str()); - EXPECT_FALSE(GTEST_FLAG(list_tests)); - EXPECT_STREQ("", GTEST_FLAG(output).c_str()); - EXPECT_FALSE(GTEST_FLAG(brief)); - EXPECT_TRUE(GTEST_FLAG(print_time)); - EXPECT_EQ(0, GTEST_FLAG(random_seed)); - EXPECT_EQ(1, GTEST_FLAG(repeat)); - EXPECT_TRUE(GTEST_FLAG(recreate_environments_when_repeating)); - EXPECT_FALSE(GTEST_FLAG(shuffle)); - EXPECT_EQ(kMaxStackTraceDepth, GTEST_FLAG(stack_trace_depth)); - EXPECT_STREQ("", GTEST_FLAG(stream_result_to).c_str()); - EXPECT_FALSE(GTEST_FLAG(throw_on_failure)); - - GTEST_FLAG(also_run_disabled_tests) = true; - GTEST_FLAG(break_on_failure) = true; - GTEST_FLAG(catch_exceptions) = true; - GTEST_FLAG(color) = "no"; - GTEST_FLAG(death_test_use_fork) = true; - GTEST_FLAG(fail_fast) = true; - GTEST_FLAG(filter) = "abc"; - GTEST_FLAG(list_tests) = true; - GTEST_FLAG(output) = "xml:foo.xml"; - GTEST_FLAG(brief) = true; - GTEST_FLAG(print_time) = false; - GTEST_FLAG(random_seed) = 1; - GTEST_FLAG(repeat) = 100; - GTEST_FLAG(recreate_environments_when_repeating) = false; - GTEST_FLAG(shuffle) = true; - GTEST_FLAG(stack_trace_depth) = 1; - GTEST_FLAG(stream_result_to) = "localhost:1234"; - GTEST_FLAG(throw_on_failure) = true; + EXPECT_FALSE(GTEST_FLAG_GET(also_run_disabled_tests)); + EXPECT_FALSE(GTEST_FLAG_GET(break_on_failure)); + EXPECT_FALSE(GTEST_FLAG_GET(catch_exceptions)); + EXPECT_STREQ("auto", GTEST_FLAG_GET(color).c_str()); + EXPECT_FALSE(GTEST_FLAG_GET(death_test_use_fork)); + EXPECT_FALSE(GTEST_FLAG_GET(fail_fast)); + EXPECT_STREQ("", GTEST_FLAG_GET(filter).c_str()); + EXPECT_FALSE(GTEST_FLAG_GET(list_tests)); + EXPECT_STREQ("", GTEST_FLAG_GET(output).c_str()); + EXPECT_FALSE(GTEST_FLAG_GET(brief)); + EXPECT_TRUE(GTEST_FLAG_GET(print_time)); + EXPECT_EQ(0, GTEST_FLAG_GET(random_seed)); + EXPECT_EQ(1, GTEST_FLAG_GET(repeat)); + EXPECT_TRUE(GTEST_FLAG_GET(recreate_environments_when_repeating)); + EXPECT_FALSE(GTEST_FLAG_GET(shuffle)); + EXPECT_EQ(kMaxStackTraceDepth, GTEST_FLAG_GET(stack_trace_depth)); + EXPECT_STREQ("", GTEST_FLAG_GET(stream_result_to).c_str()); + EXPECT_FALSE(GTEST_FLAG_GET(throw_on_failure)); + + GTEST_FLAG_SET(also_run_disabled_tests, true); + GTEST_FLAG_SET(break_on_failure, true); + GTEST_FLAG_SET(catch_exceptions, true); + GTEST_FLAG_SET(color, "no"); + GTEST_FLAG_SET(death_test_use_fork, true); + GTEST_FLAG_SET(fail_fast, true); + GTEST_FLAG_SET(filter, "abc"); + GTEST_FLAG_SET(list_tests, true); + GTEST_FLAG_SET(output, "xml:foo.xml"); + GTEST_FLAG_SET(brief, true); + GTEST_FLAG_SET(print_time, false); + GTEST_FLAG_SET(random_seed, 1); + GTEST_FLAG_SET(repeat, 100); + GTEST_FLAG_SET(recreate_environments_when_repeating, false); + GTEST_FLAG_SET(shuffle, true); + GTEST_FLAG_SET(stack_trace_depth, 1); + GTEST_FLAG_SET(stream_result_to, "localhost:1234"); + GTEST_FLAG_SET(throw_on_failure, true); } private: @@ -1781,29 +1758,29 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) { } #endif // !GTEST_OS_WINDOWS_MOBILE -// Tests ParseInt32Flag(). +// Tests ParseFlag(). // Tests that ParseInt32Flag() returns false and doesn't change the // output value when the flag has wrong format TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) { int32_t value = 123; - EXPECT_FALSE(ParseInt32Flag("--a=100", "b", &value)); + EXPECT_FALSE(ParseFlag("--a=100", "b", &value)); EXPECT_EQ(123, value); - EXPECT_FALSE(ParseInt32Flag("a=100", "a", &value)); + EXPECT_FALSE(ParseFlag("a=100", "a", &value)); EXPECT_EQ(123, value); } -// Tests that ParseInt32Flag() returns false and doesn't change the +// Tests that ParseFlag() returns false and doesn't change the // output value when the flag overflows as an Int32. TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) { printf("(expecting 2 warnings)\n"); int32_t value = 123; - EXPECT_FALSE(ParseInt32Flag("--abc=12345678987654321", "abc", &value)); + EXPECT_FALSE(ParseFlag("--abc=12345678987654321", "abc", &value)); EXPECT_EQ(123, value); - EXPECT_FALSE(ParseInt32Flag("--abc=-12345678987654321", "abc", &value)); + EXPECT_FALSE(ParseFlag("--abc=-12345678987654321", "abc", &value)); EXPECT_EQ(123, value); } @@ -1814,10 +1791,10 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) { printf("(expecting 2 warnings)\n"); int32_t value = 123; - EXPECT_FALSE(ParseInt32Flag("--abc=A1", "abc", &value)); + EXPECT_FALSE(ParseFlag("--abc=A1", "abc", &value)); EXPECT_EQ(123, value); - EXPECT_FALSE(ParseInt32Flag("--abc=12X", "abc", &value)); + EXPECT_FALSE(ParseFlag("--abc=12X", "abc", &value)); EXPECT_EQ(123, value); } @@ -1826,11 +1803,10 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) { // the range of an Int32. TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { int32_t value = 123; - EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value)); + EXPECT_TRUE(ParseFlag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value)); EXPECT_EQ(456, value); - EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=-789", - "abc", &value)); + EXPECT_TRUE(ParseFlag("--" GTEST_FLAG_PREFIX_ "abc=-789", "abc", &value)); EXPECT_EQ(-789, value); } @@ -5756,23 +5732,23 @@ class ParseFlagsTest : public Test { protected: // Clears the flags before each test. void SetUp() override { - GTEST_FLAG(also_run_disabled_tests) = false; - GTEST_FLAG(break_on_failure) = false; - GTEST_FLAG(catch_exceptions) = false; - GTEST_FLAG(death_test_use_fork) = false; - GTEST_FLAG(fail_fast) = false; - GTEST_FLAG(filter) = ""; - GTEST_FLAG(list_tests) = false; - GTEST_FLAG(output) = ""; - GTEST_FLAG(brief) = false; - GTEST_FLAG(print_time) = true; - GTEST_FLAG(random_seed) = 0; - GTEST_FLAG(repeat) = 1; - GTEST_FLAG(recreate_environments_when_repeating) = true; - GTEST_FLAG(shuffle) = false; - GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth; - GTEST_FLAG(stream_result_to) = ""; - GTEST_FLAG(throw_on_failure) = false; + GTEST_FLAG_SET(also_run_disabled_tests, false); + GTEST_FLAG_SET(break_on_failure, false); + GTEST_FLAG_SET(catch_exceptions, false); + GTEST_FLAG_SET(death_test_use_fork, false); + GTEST_FLAG_SET(fail_fast, false); + GTEST_FLAG_SET(filter, ""); + GTEST_FLAG_SET(list_tests, false); + GTEST_FLAG_SET(output, ""); + GTEST_FLAG_SET(brief, false); + GTEST_FLAG_SET(print_time, true); + GTEST_FLAG_SET(random_seed, 0); + GTEST_FLAG_SET(repeat, 1); + GTEST_FLAG_SET(recreate_environments_when_repeating, true); + GTEST_FLAG_SET(shuffle, false); + GTEST_FLAG_SET(stack_trace_depth, kMaxStackTraceDepth); + GTEST_FLAG_SET(stream_result_to, ""); + GTEST_FLAG_SET(throw_on_failure, false); } // Asserts that two narrow or wide string arrays are equal. @@ -5789,25 +5765,26 @@ class ParseFlagsTest : public Test { // Verifies that the flag values match the expected values. static void CheckFlags(const Flags& expected) { EXPECT_EQ(expected.also_run_disabled_tests, - GTEST_FLAG(also_run_disabled_tests)); - EXPECT_EQ(expected.break_on_failure, GTEST_FLAG(break_on_failure)); - EXPECT_EQ(expected.catch_exceptions, GTEST_FLAG(catch_exceptions)); - EXPECT_EQ(expected.death_test_use_fork, GTEST_FLAG(death_test_use_fork)); - EXPECT_EQ(expected.fail_fast, GTEST_FLAG(fail_fast)); - EXPECT_STREQ(expected.filter, GTEST_FLAG(filter).c_str()); - EXPECT_EQ(expected.list_tests, GTEST_FLAG(list_tests)); - EXPECT_STREQ(expected.output, GTEST_FLAG(output).c_str()); - EXPECT_EQ(expected.brief, GTEST_FLAG(brief)); - EXPECT_EQ(expected.print_time, GTEST_FLAG(print_time)); - EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed)); - EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat)); + GTEST_FLAG_GET(also_run_disabled_tests)); + EXPECT_EQ(expected.break_on_failure, GTEST_FLAG_GET(break_on_failure)); + EXPECT_EQ(expected.catch_exceptions, GTEST_FLAG_GET(catch_exceptions)); + EXPECT_EQ(expected.death_test_use_fork, + GTEST_FLAG_GET(death_test_use_fork)); + EXPECT_EQ(expected.fail_fast, GTEST_FLAG_GET(fail_fast)); + EXPECT_STREQ(expected.filter, GTEST_FLAG_GET(filter).c_str()); + EXPECT_EQ(expected.list_tests, GTEST_FLAG_GET(list_tests)); + EXPECT_STREQ(expected.output, GTEST_FLAG_GET(output).c_str()); + EXPECT_EQ(expected.brief, GTEST_FLAG_GET(brief)); + EXPECT_EQ(expected.print_time, GTEST_FLAG_GET(print_time)); + EXPECT_EQ(expected.random_seed, GTEST_FLAG_GET(random_seed)); + EXPECT_EQ(expected.repeat, GTEST_FLAG_GET(repeat)); EXPECT_EQ(expected.recreate_environments_when_repeating, - GTEST_FLAG(recreate_environments_when_repeating)); - EXPECT_EQ(expected.shuffle, GTEST_FLAG(shuffle)); - EXPECT_EQ(expected.stack_trace_depth, GTEST_FLAG(stack_trace_depth)); + GTEST_FLAG_GET(recreate_environments_when_repeating)); + EXPECT_EQ(expected.shuffle, GTEST_FLAG_GET(shuffle)); + EXPECT_EQ(expected.stack_trace_depth, GTEST_FLAG_GET(stack_trace_depth)); EXPECT_STREQ(expected.stream_result_to, - GTEST_FLAG(stream_result_to).c_str()); - EXPECT_EQ(expected.throw_on_failure, GTEST_FLAG(throw_on_failure)); + GTEST_FLAG_GET(stream_result_to).c_str()); + EXPECT_EQ(expected.throw_on_failure, GTEST_FLAG_GET(throw_on_failure)); } // Parses a command line (specified by argc1 and argv1), then @@ -6639,7 +6616,7 @@ TEST(StreamingAssertionsTest, AnyThrow) { // Tests that Google Test correctly decides whether to use colors in the output. TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) { - GTEST_FLAG(color) = "yes"; + GTEST_FLAG_SET(color, "yes"); SetEnv("TERM", "xterm"); // TERM supports colors. EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. @@ -6653,18 +6630,18 @@ TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsYes) { TEST(ColoredOutputTest, UsesColorsWhenGTestColorFlagIsAliasOfYes) { SetEnv("TERM", "dumb"); // TERM doesn't support colors. - GTEST_FLAG(color) = "True"; + GTEST_FLAG_SET(color, "True"); EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY. - GTEST_FLAG(color) = "t"; + GTEST_FLAG_SET(color, "t"); EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY. - GTEST_FLAG(color) = "1"; + GTEST_FLAG_SET(color, "1"); EXPECT_TRUE(ShouldUseColor(false)); // Stdout is not a TTY. } TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) { - GTEST_FLAG(color) = "no"; + GTEST_FLAG_SET(color, "no"); SetEnv("TERM", "xterm"); // TERM supports colors. EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. @@ -6678,18 +6655,18 @@ TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsNo) { TEST(ColoredOutputTest, UsesNoColorWhenGTestColorFlagIsInvalid) { SetEnv("TERM", "xterm"); // TERM supports colors. - GTEST_FLAG(color) = "F"; + GTEST_FLAG_SET(color, "F"); EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. - GTEST_FLAG(color) = "0"; + GTEST_FLAG_SET(color, "0"); EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. - GTEST_FLAG(color) = "unknown"; + GTEST_FLAG_SET(color, "unknown"); EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. } TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { - GTEST_FLAG(color) = "auto"; + GTEST_FLAG_SET(color, "auto"); SetEnv("TERM", "xterm"); // TERM supports colors. EXPECT_FALSE(ShouldUseColor(false)); // Stdout is not a TTY. @@ -6697,7 +6674,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { } TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { - GTEST_FLAG(color) = "auto"; + GTEST_FLAG_SET(color, "auto"); #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW // On Windows, we ignore the TERM variable as it's usually not set. |