Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 """Verifies that Google Test correctly parses environment variables."""
00033
00034 __author__ = 'wan@google.com (Zhanyong Wan)'
00035
00036 import os
00037 import gtest_test_utils
00038
00039
00040 IS_WINDOWS = os.name == 'nt'
00041 IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
00042
00043 COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_')
00044
00045 environ = os.environ.copy()
00046
00047
00048 def AssertEq(expected, actual):
00049 if expected != actual:
00050 print 'Expected: %s' % (expected,)
00051 print ' Actual: %s' % (actual,)
00052 raise AssertionError
00053
00054
00055 def SetEnvVar(env_var, value):
00056 """Sets the env variable to 'value'; unsets it when 'value' is None."""
00057
00058 if value is not None:
00059 environ[env_var] = value
00060 elif env_var in environ:
00061 del environ[env_var]
00062
00063
00064 def GetFlag(flag):
00065 """Runs gtest_env_var_test_ and returns its output."""
00066
00067 args = [COMMAND]
00068 if flag is not None:
00069 args += [flag]
00070 return gtest_test_utils.Subprocess(args, env=environ).output
00071
00072
00073 def TestFlag(flag, test_val, default_val):
00074 """Verifies that the given flag is affected by the corresponding env var."""
00075
00076 env_var = 'GTEST_' + flag.upper()
00077 SetEnvVar(env_var, test_val)
00078 AssertEq(test_val, GetFlag(flag))
00079 SetEnvVar(env_var, None)
00080 AssertEq(default_val, GetFlag(flag))
00081
00082
00083 class GTestEnvVarTest(gtest_test_utils.TestCase):
00084 def testEnvVarAffectsFlag(self):
00085 """Tests that environment variable should affect the corresponding flag."""
00086
00087 TestFlag('break_on_failure', '1', '0')
00088 TestFlag('color', 'yes', 'auto')
00089 TestFlag('filter', 'FooTest.Bar', '*')
00090 TestFlag('output', 'xml:tmp/foo.xml', '')
00091 TestFlag('print_time', '0', '1')
00092 TestFlag('repeat', '999', '1')
00093 TestFlag('throw_on_failure', '1', '0')
00094 TestFlag('death_test_style', 'threadsafe', 'fast')
00095 TestFlag('catch_exceptions', '0', '1')
00096
00097 if IS_LINUX:
00098 TestFlag('death_test_use_fork', '1', '0')
00099 TestFlag('stack_trace_depth', '0', '100')
00100
00101
00102 if __name__ == '__main__':
00103 gtest_test_utils.Main()