gtest_env_var_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2008, Google Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are
00008 # met:
00009 #
00010 #     * Redistributions of source code must retain the above copyright
00011 # notice, this list of conditions and the following disclaimer.
00012 #     * Redistributions in binary form must reproduce the above
00013 # copyright notice, this list of conditions and the following disclaimer
00014 # in the documentation and/or other materials provided with the
00015 # distribution.
00016 #     * Neither the name of Google Inc. nor the names of its
00017 # contributors may be used to endorse or promote products derived from
00018 # this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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()


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04