32 """Verifies that Google Test correctly determines whether to use colors.""" 34 __author__ =
'wan@google.com (Zhanyong Wan)' 37 import gtest_test_utils
40 IS_WINDOWS = os.name =
'nt' 42 COLOR_ENV_VAR =
'GTEST_COLOR' 43 COLOR_FLAG =
'gtest_color' 48 """Sets the env variable to 'value'; unsets it when 'value' is None.""" 51 os.environ[env_var] = value
52 elif env_var
in os.environ:
53 del os.environ[env_var]
57 """Runs gtest_color_test_ and returns its exit code.""" 62 if color_flag
is None:
65 args = [
'--%s=%s' % (COLOR_FLAG, color_flag)]
67 return not p.exited
or p.exit_code
72 """Tests the case when there's neither GTEST_COLOR nor --gtest_color.""" 75 self.assert_(
not UsesColor(
'dumb',
None,
None))
76 self.assert_(
not UsesColor(
'emacs',
None,
None))
77 self.assert_(
not UsesColor(
'xterm-mono',
None,
None))
78 self.assert_(
not UsesColor(
'unknown',
None,
None))
79 self.assert_(
not UsesColor(
None,
None,
None))
80 self.assert_(
UsesColor(
'linux',
None,
None))
81 self.assert_(
UsesColor(
'cygwin',
None,
None))
82 self.assert_(
UsesColor(
'xterm',
None,
None))
83 self.assert_(
UsesColor(
'xterm-color',
None,
None))
84 self.assert_(
UsesColor(
'xterm-256color',
None,
None))
87 """Tests the case when there's --gtest_color but not GTEST_COLOR.""" 89 self.assert_(
not UsesColor(
'dumb',
None,
'no'))
90 self.assert_(
not UsesColor(
'xterm-color',
None,
'no'))
92 self.assert_(
not UsesColor(
'emacs',
None,
'auto'))
93 self.assert_(
UsesColor(
'xterm',
None,
'auto'))
94 self.assert_(
UsesColor(
'dumb',
None,
'yes'))
95 self.assert_(
UsesColor(
'xterm',
None,
'yes'))
98 """Tests the case when there's GTEST_COLOR but not --gtest_color.""" 100 self.assert_(
not UsesColor(
'dumb',
'no',
None))
101 self.assert_(
not UsesColor(
'xterm-color',
'no',
None))
103 self.assert_(
not UsesColor(
'dumb',
'auto',
None))
104 self.assert_(
UsesColor(
'xterm-color',
'auto',
None))
105 self.assert_(
UsesColor(
'dumb',
'yes',
None))
106 self.assert_(
UsesColor(
'xterm-color',
'yes',
None))
109 """Tests the case when there are both GTEST_COLOR and --gtest_color.""" 111 self.assert_(
not UsesColor(
'xterm-color',
'no',
'no'))
112 self.assert_(
UsesColor(
'dumb',
'no',
'yes'))
113 self.assert_(
UsesColor(
'xterm-color',
'no',
'auto'))
116 """Tests using aliases in specifying --gtest_color.""" 118 self.assert_(
UsesColor(
'dumb',
None,
'true'))
119 self.assert_(
UsesColor(
'dumb',
None,
'YES'))
120 self.assert_(
UsesColor(
'dumb',
None,
'T'))
121 self.assert_(
UsesColor(
'dumb',
None,
'1'))
123 self.assert_(
not UsesColor(
'xterm',
None,
'f'))
124 self.assert_(
not UsesColor(
'xterm',
None,
'false'))
125 self.assert_(
not UsesColor(
'xterm',
None,
'0'))
126 self.assert_(
not UsesColor(
'xterm',
None,
'unknown'))
129 if __name__ ==
'__main__':
def GetTestExecutablePath(executable_name, build_dir=None)
def SetEnvVar(env_var, value)
def testAliasesOfYesAndNo(self)
def testEnvVarAndFlag(self)
def UsesColor(term, color_env_var, color_flag)
def testNoEnvVarNoFlag(self)