diff options
Diffstat (limited to 'googletest/src/gtest-port.cc')
-rw-r--r-- | googletest/src/gtest-port.cc | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 05ffca0..e5bf3dd 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1226,30 +1226,31 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { // Reads and returns the string environment variable corresponding to // the given flag; if it's not set, returns default_value. -const char* StringFromGTestEnv(const char* flag, const char* default_value) { +std::string StringFromGTestEnv(const char* flag, const char* default_value) { #if defined(GTEST_GET_STRING_FROM_ENV_) return GTEST_GET_STRING_FROM_ENV_(flag, default_value); #endif // defined(GTEST_GET_STRING_FROM_ENV_) const std::string env_var = FlagToEnvVar(flag); - const char* const value = posix::GetEnv(env_var.c_str()); - return value == NULL ? default_value : value; -} - -// Reads and returns GTEST_OUTPUT and/or XML_OUTPUT_FILE environment -// variables; if neither is set, returns default value. -// XML_OUTPUT_FILE is set by the Bazel build system, and its format is -// a filename without the "xml:" prefix of GTEST_OUTPUT. -std::string OutputFromGTestEnv(const char* default_value) { -#if defined(GTEST_GET_STRING_FROM_ENV_) - return GTEST_GET_STRING_FROM_ENV_("output", default_value); -#endif // defined(GTEST_GET_STRING_FROM_ENV_) - const char* value = StringFromGTestEnv("output", NULL); - if (value) { + const char* value = posix::GetEnv(env_var.c_str()); + if (value != NULL) { return value; } - value = posix::GetEnv("XML_OUTPUT_FILE"); - if (value) { - return std::string("xml:") + value; + + // As a special case for the 'output' flag, if GTEST_OUTPUT is not + // set, we look for XML_OUTPUT_FILE, which is set by the Bazel build + // system. The value of XML_OUTPUT_FILE is a filename without the + // "xml:" prefix of GTEST_OUTPUT. + // + // The net priority order after flag processing is thus: + // --gtest_output command line flag + // GTEST_OUTPUT environment variable + // XML_OUTPUT_FILE environment variable + // 'default_value' + if (strcmp(flag, "output") == 0) { + value = posix::GetEnv("XML_OUTPUT_FILE"); + if (value != NULL) { + return std::string("xml:") + value; + } } return default_value; } |