The --gtest_color flag should take a priority.

This along with commit c1ef5eb034 should
get back to the initial behavior prior to the change in commit
83b6379783.

Fixes: 111396376
Test: `adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests --gtest_color=yes`
      shows colored output.
Test: `adb shell -t /data/nativetest64/bionic-unit-tests/bionic-unit-tests --gtest_color=no`
      doesn't add color escapes.
Change-Id: I88530e8b264cd0c259c16b09bdf867cdd2e88224
This commit is contained in:
Tao Bao 2018-07-17 18:22:14 -07:00
parent 9842db42e9
commit afacaaba8c

View file

@ -79,11 +79,6 @@ static constexpr const char* COLOR_GREEN = "\033[0;32m";
static constexpr const char* COLOR_YELLOW = "\033[0;33m";
static bool ShouldUseColor() {
bool stdout_is_tty = isatty(STDOUT_FILENO) != 0;
if (!stdout_is_tty) {
return false;
}
const auto& gtest_color = ::testing::GTEST_FLAG(color);
if (gtest_color == "yes" || gtest_color == "true" || gtest_color == "t") {
return true;
@ -92,6 +87,11 @@ static bool ShouldUseColor() {
return false;
}
bool stdout_is_tty = isatty(STDOUT_FILENO) != 0;
if (!stdout_is_tty) {
return false;
}
const char* const term = getenv("COLORTERM");
return term != nullptr && term[0] != 0;
}