MCPcopy Create free account
hub / github.com/apache/singa / ShouldUseColor

Function ShouldUseColor

test/gtest/gtest-all.cc:4069–4099  ·  view source on GitHub ↗

Returns true iff Google Test should use colors in the output.

Source from the content-addressed store, hash-verified

4067
4068// Returns true iff Google Test should use colors in the output.
4069bool ShouldUseColor(bool stdout_is_tty) {
4070 const char* const gtest_color = GTEST_FLAG(color).c_str();
4071
4072 if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
4073#if GTEST_OS_WINDOWS
4074 // On Windows the TERM variable is usually not set, but the
4075 // console there does support colors.
4076 return stdout_is_tty;
4077#else
4078 // On non-Windows platforms, we rely on the TERM variable.
4079 const char* const term = posix::GetEnv("TERM");
4080 const bool term_supports_color =
4081 String::CStringEquals(term, "xterm") ||
4082 String::CStringEquals(term, "xterm-color") ||
4083 String::CStringEquals(term, "xterm-256color") ||
4084 String::CStringEquals(term, "screen") ||
4085 String::CStringEquals(term, "screen-256color") ||
4086 String::CStringEquals(term, "linux") ||
4087 String::CStringEquals(term, "cygwin");
4088 return stdout_is_tty && term_supports_color;
4089#endif // GTEST_OS_WINDOWS
4090 }
4091
4092 return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
4093 String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
4094 String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
4095 String::CStringEquals(gtest_color, "1");
4096 // We take "yes", "true", "t", and "1" as meaning "yes". If the
4097 // value is neither one of these nor "auto", we treat it as "no" to
4098 // be conservative.
4099}
4100
4101// Helpers for printing colored strings to stdout. Note that on Windows, we
4102// cannot simply emit special characters and have the terminal change colors.

Callers 1

ColoredPrintfFunction · 0.85

Calls 1

GetEnvFunction · 0.85

Tested by

no test coverage detected