From 4d69b1607a876a77b8719f035b23254677617a47 Mon Sep 17 00:00:00 2001 From: kosak Date: Sun, 19 Jul 2015 21:50:45 +0000 Subject: [PATCH] GTEST_USE_OWN_FLAGFILE support --- include/gtest/internal/custom/gtest-port.h | 2 ++ include/gtest/internal/gtest-port.h | 4 ++++ src/gtest.cc | 6 ++++++ test/gtest_unittest.cc | 2 ++ 4 files changed, 14 insertions(+) diff --git a/include/gtest/internal/custom/gtest-port.h b/include/gtest/internal/custom/gtest-port.h index b31810da..7e744bd3 100644 --- a/include/gtest/internal/custom/gtest-port.h +++ b/include/gtest/internal/custom/gtest-port.h @@ -32,6 +32,8 @@ // // Flag related macros: // GTEST_FLAG(flag_name) +// GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its +// own flagfile flag parsing. // GTEST_DECLARE_bool_(name) // GTEST_DECLARE_int32_(name) // GTEST_DECLARE_string_(name) diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 864a90cb..f6ed4d00 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -2434,6 +2434,10 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. # define GTEST_FLAG(name) FLAGS_gtest_##name #endif // !defined(GTEST_FLAG) +#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) +# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 +#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) + #if !defined(GTEST_DECLARE_bool_) # define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver diff --git a/src/gtest.cc b/src/gtest.cc index 1c5117d3..08393897 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -296,10 +296,12 @@ GTEST_DEFINE_bool_( "if exceptions are enabled or exit the program with a non-zero code " "otherwise."); +#if GTEST_USE_OWN_FLAGFILE_FLAG_ GTEST_DEFINE_string_( flagfile, internal::StringFromGTestEnv("flagfile", ""), "This flag specifies the flagfile to read command-line flags from."); +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ namespace internal { @@ -5233,6 +5235,7 @@ bool ParseGoogleTestFlag(const char* const arg) { >EST_FLAG(throw_on_failure)); } +#if GTEST_USE_OWN_FLAGFILE_FLAG_ void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { @@ -5253,6 +5256,7 @@ void LoadFlagsFromFile(const std::string& path) { g_help_flag = true; } } +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ // Parses the command line for Google Test flags, without initializing // other parts of Google Test. The type parameter CharType can be @@ -5270,9 +5274,11 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { bool remove_flag = false; if (ParseGoogleTestFlag(arg)) { remove_flag = true; +#if GTEST_USE_OWN_FLAGFILE_FLAG_ } else if (ParseStringFlag(arg, kFlagfileFlag, >EST_FLAG(flagfile))) { LoadFlagsFromFile(GTEST_FLAG(flagfile)); remove_flag = true; +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ } else if (arg_string == "--help" || arg_string == "-h" || arg_string == "-?" || arg_string == "/?" || HasGoogleTestFlagPrefix(arg)) { diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index 88130dfa..dd7f19f4 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -6399,6 +6399,7 @@ TEST_F(InitGoogleTestTest, WideStrings) { } # endif // GTEST_OS_WINDOWS +#if GTEST_USE_OWN_FLAGFILE_FLAG_ class FlagfileTest : public InitGoogleTestTest { public: virtual void SetUp() { @@ -6497,6 +6498,7 @@ TEST_F(FlagfileTest, SeveralFlags) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false); } +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ // Tests current_test_info() in UnitTest. class CurrentTestInfoTest : public Test {