32"""Verifies that Google Test correctly determines whether to use colors."""
35import gtest_test_utils
37IS_WINDOWS = os.name ==
'nt'
39COLOR_ENV_VAR =
'GTEST_COLOR'
40COLOR_FLAG =
'gtest_color'
45 """Sets the env variable to 'value'; unsets it when 'value' is None."""
48 os.environ[env_var] = value
49 elif env_var
in os.environ:
50 del os.environ[env_var]
54 """Runs googletest-color-test_ and returns its exit code."""
59 if color_flag
is None:
62 args = [
'--%s=%s' % (COLOR_FLAG, color_flag)]
64 return not p.exited
or p.exit_code
69 """Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
72 self.assert_(
not UsesColor(
'dumb',
None,
None))
73 self.assert_(
not UsesColor(
'emacs',
None,
None))
74 self.assert_(
not UsesColor(
'xterm-mono',
None,
None))
75 self.assert_(
not UsesColor(
'unknown',
None,
None))
76 self.assert_(
not UsesColor(
None,
None,
None))
77 self.assert_(
UsesColor(
'linux',
None,
None))
78 self.assert_(
UsesColor(
'cygwin',
None,
None))
79 self.assert_(
UsesColor(
'xterm',
None,
None))
80 self.assert_(
UsesColor(
'xterm-color',
None,
None))
81 self.assert_(
UsesColor(
'xterm-256color',
None,
None))
84 """Tests the case when there's --gtest_color but not GTEST_COLOR."""
86 self.assert_(
not UsesColor(
'dumb',
None,
'no'))
87 self.assert_(
not UsesColor(
'xterm-color',
None,
'no'))
89 self.assert_(
not UsesColor(
'emacs',
None,
'auto'))
90 self.assert_(
UsesColor(
'xterm',
None,
'auto'))
91 self.assert_(
UsesColor(
'dumb',
None,
'yes'))
92 self.assert_(
UsesColor(
'xterm',
None,
'yes'))
95 """Tests the case when there's GTEST_COLOR but not --gtest_color."""
97 self.assert_(
not UsesColor(
'dumb',
'no',
None))
98 self.assert_(
not UsesColor(
'xterm-color',
'no',
None))
100 self.assert_(
not UsesColor(
'dumb',
'auto',
None))
101 self.assert_(
UsesColor(
'xterm-color',
'auto',
None))
102 self.assert_(
UsesColor(
'dumb',
'yes',
None))
103 self.assert_(
UsesColor(
'xterm-color',
'yes',
None))
106 """Tests the case when there are both GTEST_COLOR and --gtest_color."""
108 self.assert_(
not UsesColor(
'xterm-color',
'no',
'no'))
109 self.assert_(
UsesColor(
'dumb',
'no',
'yes'))
110 self.assert_(
UsesColor(
'xterm-color',
'no',
'auto'))
113 """Tests using aliases in specifying --gtest_color."""
115 self.assert_(
UsesColor(
'dumb',
None,
'true'))
116 self.assert_(
UsesColor(
'dumb',
None,
'YES'))
117 self.assert_(
UsesColor(
'dumb',
None,
'T'))
118 self.assert_(
UsesColor(
'dumb',
None,
'1'))
120 self.assert_(
not UsesColor(
'xterm',
None,
'f'))
121 self.assert_(
not UsesColor(
'xterm',
None,
'false'))
122 self.assert_(
not UsesColor(
'xterm',
None,
'0'))
123 self.assert_(
not UsesColor(
'xterm',
None,
'unknown'))
126if __name__ ==
'__main__':
def SetEnvVar(env_var, value)
def UsesColor(term, color_env_var, color_flag)
def GetTestExecutablePath(executable_name, build_dir=None)
def testAliasesOfYesAndNo(self)
def testEnvVarAndFlag(self)
def testNoEnvVarNoFlag(self)