From 691e38e518336fa8a9b51915735fe869edb24c08 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 21 Mar 2018 16:31:31 -0400 Subject: [PATCH 1/4] More merges --- .../include/gtest/internal/gtest-port.h | 3 +- googletest/src/gtest-port.cc | 52 +++++++++---------- googletest/src/gtest.cc | 8 ++- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 3e4f7b58..53c1b5f4 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2675,7 +2675,8 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value); // corresponding to the given Google Test flag. bool BoolFromGTestEnv(const char* flag, bool default_val); GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); -std::string StringFromGTestEnv(const char* flag, const char* default_val); +std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(); +const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal } // namespace testing diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 99791f9c..ffea9b32 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1185,11 +1185,12 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) { bool BoolFromGTestEnv(const char* flag, bool default_value) { #if defined(GTEST_GET_BOOL_FROM_ENV_) return GTEST_GET_BOOL_FROM_ENV_(flag, default_value); -#endif // defined(GTEST_GET_BOOL_FROM_ENV_) +#else const std::string env_var = FlagToEnvVar(flag); const char* const string_value = posix::GetEnv(env_var.c_str()); return string_value == NULL ? default_value : strcmp(string_value, "0") != 0; +#endif // defined(GTEST_GET_BOOL_FROM_ENV_) } // Reads and returns a 32-bit integer stored in the environment @@ -1198,7 +1199,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) { Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { #if defined(GTEST_GET_INT32_FROM_ENV_) return GTEST_GET_INT32_FROM_ENV_(flag, default_value); -#endif // defined(GTEST_GET_INT32_FROM_ENV_) +#else const std::string env_var = FlagToEnvVar(flag); const char* const string_value = posix::GetEnv(env_var.c_str()); if (string_value == NULL) { @@ -1216,37 +1217,36 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { } return result; +#endif // defined(GTEST_GET_INT32_FROM_ENV_) +} + +// 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. +// Note that this is meant to be called at the call site so it does +// not check that the flag is 'output' +// In essence this checks env. variable called XML_OUTPUT_FILE +// if it is set we prepend "xml:" to its value , if it not set we return "" +std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(){ + std::string default_value_for_output_flag = ""; + const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); + if (NULL != xml_output_file_env) { + default_value_for_output_flag = std::string("xml:") + xml_output_file_env; + } + return default_value_for_output_flag; } // Reads and returns the string environment variable corresponding to // the given flag; if it's not set, returns default_value. -std::string StringFromGTestEnv(const char* flag, const char* default_value) { +const char* 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_) +#else const std::string env_var = FlagToEnvVar(flag); - const char* value = posix::GetEnv(env_var.c_str()); - if (value != NULL) { - return 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; + const char* const value = posix::GetEnv(env_var.c_str()); + return value == NULL ? default_value : value; +#endif // defined(GTEST_GET_STRING_FROM_ENV_) } } // namespace internal diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d22679f6..07fedd7e 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -230,9 +230,15 @@ GTEST_DEFINE_string_( GTEST_DEFINE_bool_(list_tests, false, "List all tests without running them."); +// The net priority order after flag processing is thus: +// --gtest_output command line flag +// GTEST_OUTPUT environment variable +// XML_OUTPUT_FILE environment variable +// '' GTEST_DEFINE_string_( output, - internal::StringFromGTestEnv("output", ""), + internal::StringFromGTestEnv("output", + internal::SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env().c_str()), "A format (defaults to \"xml\" but can be specified to be \"json\"), " "optionally followed by a colon and an output file name or directory. " "A directory is indicated by a trailing pathname separator. " From 0f6567954f42767e2f4a92d9f3b4afa679a65c16 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 10:56:35 -0400 Subject: [PATCH 2/4] more merges --- googletest/include/gtest/internal/gtest-port.h | 2 +- googletest/src/gtest-port.cc | 2 +- googletest/src/gtest.cc | 2 +- googletest/test/gtest_list_tests_unittest.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 53c1b5f4..751e1764 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2675,7 +2675,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value); // corresponding to the given Google Test flag. bool BoolFromGTestEnv(const char* flag, bool default_val); GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); -std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(); +std::string OutputFlagAlsoCheckEnvVar(); const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index ffea9b32..e710354a 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1228,7 +1228,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { // not check that the flag is 'output' // In essence this checks env. variable called XML_OUTPUT_FILE // if it is set we prepend "xml:" to its value , if it not set we return "" -std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(){ +std::string OutputFlagAlsoCheckEnvVar(){ std::string default_value_for_output_flag = ""; const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); if (NULL != xml_output_file_env) { diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 07fedd7e..9079af8d 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -238,7 +238,7 @@ GTEST_DEFINE_bool_(list_tests, false, GTEST_DEFINE_string_( output, internal::StringFromGTestEnv("output", - internal::SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env().c_str()), + internal::OutputFlagAlsoCheckEnvVar().c_str()), "A format (defaults to \"xml\" but can be specified to be \"json\"), " "optionally followed by a colon and an output file name or directory. " "A directory is indicated by a trailing pathname separator. " diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index ebf1a3c9..0844f98a 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -70,7 +70,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? +TypedTest/1\. # TypeParam = int\s*\* TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -79,7 +79,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? +My/TypeParamTest/1\. # TypeParam = int\s*\* TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray From da71e8c870d6edfa0822dacb74add4bb19bbf4c3 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 10:58:18 -0400 Subject: [PATCH 3/4] more merges --- googletest/test/gtest_env_var_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_env_var_test.py b/googletest/test/gtest_env_var_test.py index 7af00cee..5361508a 100755 --- a/googletest/test/gtest_env_var_test.py +++ b/googletest/test/gtest_env_var_test.py @@ -81,13 +81,14 @@ def TestFlag(flag, test_val, default_val): class GTestEnvVarTest(gtest_test_utils.TestCase): + def testEnvVarAffectsFlag(self): """Tests that environment variable should affect the corresponding flag.""" TestFlag('break_on_failure', '1', '0') TestFlag('color', 'yes', 'auto') TestFlag('filter', 'FooTest.Bar', '*') - SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test + SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test TestFlag('output', 'xml:tmp/foo.xml', '') TestFlag('print_time', '0', '1') TestFlag('repeat', '999', '1') @@ -107,7 +108,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): AssertEq('xml:tmp/bar.xml', GetFlag('output')) def testXmlOutputFileOverride(self): - """Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT""" + """Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT.""" SetEnvVar('GTEST_OUTPUT', 'xml:tmp/foo.xml') SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml') From 4e89c76db83684d4c5b86eb9186af3e33f5f4df0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 12:37:38 -0400 Subject: [PATCH 4/4] reverting gtest_list_tests_unittest.py --- googletest/test/gtest_list_tests_unittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index 0844f98a..ebf1a3c9 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -70,7 +70,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\* +TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -79,7 +79,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\* +My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray