Merge pull request #724 from duggelz/master
Read Bazel's $XML_OUTPUT_FILE environment variable
This commit is contained in:
commit
72416fab75
@ -2546,10 +2546,9 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value);
|
|||||||
// corresponding to the given Google Test flag.
|
// corresponding to the given Google Test flag.
|
||||||
bool BoolFromGTestEnv(const char* flag, bool default_val);
|
bool BoolFromGTestEnv(const char* flag, bool default_val);
|
||||||
GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
|
GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
|
||||||
const char* StringFromGTestEnv(const char* flag, const char* default_val);
|
std::string StringFromGTestEnv(const char* flag, const char* default_val);
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
|
||||||
|
|
||||||
|
@ -1226,13 +1226,33 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
|
|||||||
|
|
||||||
// Reads and returns the string environment variable corresponding to
|
// Reads and returns the string environment variable corresponding to
|
||||||
// the given flag; if it's not set, returns default_value.
|
// 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_)
|
#if defined(GTEST_GET_STRING_FROM_ENV_)
|
||||||
return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
|
return GTEST_GET_STRING_FROM_ENV_(flag, default_value);
|
||||||
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
|
#endif // defined(GTEST_GET_STRING_FROM_ENV_)
|
||||||
const std::string env_var = FlagToEnvVar(flag);
|
const std::string env_var = FlagToEnvVar(flag);
|
||||||
const char* const value = posix::GetEnv(env_var.c_str());
|
const char* value = posix::GetEnv(env_var.c_str());
|
||||||
return value == NULL ? default_value : value;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -87,6 +87,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
|||||||
TestFlag('break_on_failure', '1', '0')
|
TestFlag('break_on_failure', '1', '0')
|
||||||
TestFlag('color', 'yes', 'auto')
|
TestFlag('color', 'yes', 'auto')
|
||||||
TestFlag('filter', 'FooTest.Bar', '*')
|
TestFlag('filter', 'FooTest.Bar', '*')
|
||||||
|
SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test
|
||||||
TestFlag('output', 'xml:tmp/foo.xml', '')
|
TestFlag('output', 'xml:tmp/foo.xml', '')
|
||||||
TestFlag('print_time', '0', '1')
|
TestFlag('print_time', '0', '1')
|
||||||
TestFlag('repeat', '999', '1')
|
TestFlag('repeat', '999', '1')
|
||||||
@ -98,6 +99,19 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
|||||||
TestFlag('death_test_use_fork', '1', '0')
|
TestFlag('death_test_use_fork', '1', '0')
|
||||||
TestFlag('stack_trace_depth', '0', '100')
|
TestFlag('stack_trace_depth', '0', '100')
|
||||||
|
|
||||||
|
def testXmlOutputFile(self):
|
||||||
|
"""Tests that $XML_OUTPUT_FILE affects the output flag."""
|
||||||
|
|
||||||
|
SetEnvVar('GTEST_OUTPUT', None)
|
||||||
|
SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml')
|
||||||
|
AssertEq('xml:tmp/bar.xml', GetFlag('output'))
|
||||||
|
|
||||||
|
def testXmlOutputFileOverride(self):
|
||||||
|
"""Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT"""
|
||||||
|
|
||||||
|
SetEnvVar('GTEST_OUTPUT', 'xml:tmp/foo.xml')
|
||||||
|
SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml')
|
||||||
|
AssertEq('xml:tmp/foo.xml', GetFlag('output'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
Loading…
Reference in New Issue
Block a user