From d201456903f3ecae1f7794edfab0d5678e642265 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 3 Jul 2008 22:38:12 +0000 Subject: Initial import. --- test/gtest_env_var_test.py | 134 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100755 test/gtest_env_var_test.py (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py new file mode 100755 index 00000000..64d17e85 --- /dev/null +++ b/test/gtest_env_var_test.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# +# Copyright 2008, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Verifies that Google Test correctly parses environment variables.""" + +__author__ = 'wan@google.com (Zhanyong Wan)' + +import gtest_test_utils +import os +import sys +import unittest + +IS_WINDOWS = os.name == 'nt' +IS_LINUX = os.name == 'posix' + +if IS_WINDOWS: + BUILD_DIRS = [ + 'build.dbg\\', + 'build.opt\\', + 'build.dbg8\\', + 'build.opt8\\', + ] + COMMAND = 'gtest_env_var_test_.exe' + +if IS_LINUX: + COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), + 'gtest_env_var_test_') + + +def AssertEq(expected, actual): + if expected != actual: + print 'Expected: %s' % (expected,) + print ' Actual: %s' % (actual,) + raise AssertionError + + +def SetEnvVar(env_var, value): + """Sets the env variable to 'value'; unsets it when 'value' is None.""" + + if value is not None: + os.environ[env_var] = value + elif env_var in os.environ: + del os.environ[env_var] + + +def GetFlag(command, flag): + """Runs gtest_env_var_test_ and returns its output.""" + + cmd = command + if flag is not None: + cmd += ' %s' % (flag,) + stdin, stdout = os.popen2(cmd, 'b') + stdin.close() + line = stdout.readline() + stdout.close() + return line + + +def TestFlag(command, flag, test_val, default_val): + """Verifies that the given flag is affected by the corresponding env var.""" + + env_var = 'GTEST_' + flag.upper() + SetEnvVar(env_var, test_val) + AssertEq(test_val, GetFlag(command, flag)) + SetEnvVar(env_var, None) + AssertEq(default_val, GetFlag(command, flag)) + + +def TestEnvVarAffectsFlag(command): + """An environment variable should affect the corresponding flag.""" + + TestFlag(command, 'break_on_failure', '1', '0') + TestFlag(command, 'color', 'yes', 'auto') + TestFlag(command, 'filter', 'FooTest.Bar', '*') + TestFlag(command, 'output', 'tmp/foo.xml', '') + TestFlag(command, 'repeat', '999', '1') + + if IS_WINDOWS: + TestFlag(command, 'catch_exceptions', '1', '0') + if IS_LINUX: + TestFlag(command, 'stack_trace_depth', '0', '100') + TestFlag(command, 'death_test_style', 'thread-safe', 'fast') + + +if IS_WINDOWS: + + def main(): + for build_dir in BUILD_DIRS: + command = build_dir + COMMAND + print 'Testing with %s . . .' % (command,) + TestEnvVarAffectsFlag(command) + return 0 + + if __name__ == '__main__': + main() + + +if IS_LINUX: + + class GTestEnvVarTest(unittest.TestCase): + def testEnvVarAffectsFlag(self): + TestEnvVarAffectsFlag(COMMAND) + + + if __name__ == '__main__': + gtest_test_utils.Main() -- cgit v1.2.3 From d88da49d028d8d01c1e49761be577ed1cc1f5c1d Mon Sep 17 00:00:00 2001 From: shiqian Date: Fri, 25 Jul 2008 21:13:11 +0000 Subject: Adds a test for the GTEST_PRINT_TIME env var. By Balazs.Dan@gmail.com. --- test/gtest_env_var_test.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 64d17e85..1b86b5a9 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -101,6 +101,7 @@ def TestEnvVarAffectsFlag(command): TestFlag(command, 'color', 'yes', 'auto') TestFlag(command, 'filter', 'FooTest.Bar', '*') TestFlag(command, 'output', 'tmp/foo.xml', '') + TestFlag(command, 'print_time', '1', '0') TestFlag(command, 'repeat', '999', '1') if IS_WINDOWS: -- cgit v1.2.3 From 53e0dc4041f660b6517b15b08b496e164be614f1 Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 8 Jan 2009 01:10:31 +0000 Subject: Implements the --gtest_death_test_use_fork flag and StaticAssertTypeEq. --- test/gtest_env_var_test.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 1b86b5a9..67a22493 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -109,6 +109,7 @@ def TestEnvVarAffectsFlag(command): if IS_LINUX: TestFlag(command, 'stack_trace_depth', '0', '100') TestFlag(command, 'death_test_style', 'thread-safe', 'fast') + TestFlag(command, 'death_test_use_fork', '1', '0') if IS_WINDOWS: -- cgit v1.2.3 From 40e72a8a837b47cbfe2e695068c1845073ab2630 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 6 Mar 2009 20:05:23 +0000 Subject: Implements --gtest_throw_on_failure for using gtest with other testing frameworks. --- test/gtest_env_var_test.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 67a22493..c5acc5ca 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -103,6 +103,7 @@ def TestEnvVarAffectsFlag(command): TestFlag(command, 'output', 'tmp/foo.xml', '') TestFlag(command, 'print_time', '1', '0') TestFlag(command, 'repeat', '999', '1') + TestFlag(command, 'throw_on_failure', '1', '0') if IS_WINDOWS: TestFlag(command, 'catch_exceptions', '1', '0') -- cgit v1.2.3 From 7fa242a44b47ce74d7246440b14571f7a5dd1b17 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 9 Apr 2009 02:57:38 +0000 Subject: Makes the Python tests more stable (by Vlad Losev); fixes a memory leak in GetThreadCount() on Mac (by Vlad Losev); improves fuse_gtest_files.py to support fusing Google Mock files (by Zhanyong Wan). --- test/gtest_env_var_test.py | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index c5acc5ca..92b9cd8a 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -41,18 +41,7 @@ import unittest IS_WINDOWS = os.name == 'nt' IS_LINUX = os.name == 'posix' -if IS_WINDOWS: - BUILD_DIRS = [ - 'build.dbg\\', - 'build.opt\\', - 'build.dbg8\\', - 'build.opt8\\', - ] - COMMAND = 'gtest_env_var_test_.exe' - -if IS_LINUX: - COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), - 'gtest_env_var_test_') +COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_') def AssertEq(expected, actual): @@ -104,34 +93,19 @@ def TestEnvVarAffectsFlag(command): TestFlag(command, 'print_time', '1', '0') TestFlag(command, 'repeat', '999', '1') TestFlag(command, 'throw_on_failure', '1', '0') + TestFlag(command, 'death_test_style', 'threadsafe', 'fast') if IS_WINDOWS: TestFlag(command, 'catch_exceptions', '1', '0') if IS_LINUX: TestFlag(command, 'stack_trace_depth', '0', '100') - TestFlag(command, 'death_test_style', 'thread-safe', 'fast') TestFlag(command, 'death_test_use_fork', '1', '0') -if IS_WINDOWS: - - def main(): - for build_dir in BUILD_DIRS: - command = build_dir + COMMAND - print 'Testing with %s . . .' % (command,) - TestEnvVarAffectsFlag(command) - return 0 - - if __name__ == '__main__': - main() - - -if IS_LINUX: - - class GTestEnvVarTest(unittest.TestCase): - def testEnvVarAffectsFlag(self): - TestEnvVarAffectsFlag(COMMAND) +class GTestEnvVarTest(unittest.TestCase): + def testEnvVarAffectsFlag(self): + TestEnvVarAffectsFlag(COMMAND) - if __name__ == '__main__': - gtest_test_utils.Main() +if __name__ == '__main__': + gtest_test_utils.Main() -- cgit v1.2.3 From f204cd89e591e8cda022f4b471962c8556e19b8c Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 14 Apr 2009 23:19:22 +0000 Subject: Makes gtest print elapsed time by default. --- test/gtest_env_var_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 92b9cd8a..35e8041f 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -90,7 +90,7 @@ def TestEnvVarAffectsFlag(command): TestFlag(command, 'color', 'yes', 'auto') TestFlag(command, 'filter', 'FooTest.Bar', '*') TestFlag(command, 'output', 'tmp/foo.xml', '') - TestFlag(command, 'print_time', '1', '0') + TestFlag(command, 'print_time', '0', '1') TestFlag(command, 'repeat', '999', '1') TestFlag(command, 'throw_on_failure', '1', '0') TestFlag(command, 'death_test_style', 'threadsafe', 'fast') -- cgit v1.2.3 From 532dc2de35f2cef191bc91c3587a9f8f4974756f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 17 Jun 2009 21:06:27 +0000 Subject: Implements a subset of TR1 tuple needed by gtest and gmock (by Zhanyong Wan); cleaned up the Python tests (by Vlad Losev); made run_tests.py invokable from any directory (by Vlad Losev). --- test/gtest_env_var_test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 35e8041f..54719fac 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -33,13 +33,12 @@ __author__ = 'wan@google.com (Zhanyong Wan)' -import gtest_test_utils import os -import sys -import unittest +import gtest_test_utils + IS_WINDOWS = os.name == 'nt' -IS_LINUX = os.name == 'posix' +IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_') @@ -97,12 +96,13 @@ def TestEnvVarAffectsFlag(command): if IS_WINDOWS: TestFlag(command, 'catch_exceptions', '1', '0') + if IS_LINUX: - TestFlag(command, 'stack_trace_depth', '0', '100') TestFlag(command, 'death_test_use_fork', '1', '0') + TestFlag(command, 'stack_trace_depth', '0', '100') -class GTestEnvVarTest(unittest.TestCase): +class GTestEnvVarTest(gtest_test_utils.TestCase): def testEnvVarAffectsFlag(self): TestEnvVarAffectsFlag(COMMAND) -- cgit v1.2.3 From b2db677c9905a34ca6454aa526f7a0cc5cfaeca1 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 1 Jul 2009 04:58:05 +0000 Subject: Reduces the flakiness of gtest-port_test on Mac; improves the Python tests; hides methods that we don't want to publish; makes win-dbg8 the default scons configuration (all by Vlad Losev). --- test/gtest_env_var_test.py | 56 ++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 54719fac..19fd8103 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -59,52 +59,44 @@ def SetEnvVar(env_var, value): del os.environ[env_var] -def GetFlag(command, flag): +def GetFlag(flag): """Runs gtest_env_var_test_ and returns its output.""" - cmd = command + args = [COMMAND] if flag is not None: - cmd += ' %s' % (flag,) - stdin, stdout = os.popen2(cmd, 'b') - stdin.close() - line = stdout.readline() - stdout.close() - return line + args += [flag] + return gtest_test_utils.Subprocess(args).output -def TestFlag(command, flag, test_val, default_val): +def TestFlag(flag, test_val, default_val): """Verifies that the given flag is affected by the corresponding env var.""" env_var = 'GTEST_' + flag.upper() SetEnvVar(env_var, test_val) - AssertEq(test_val, GetFlag(command, flag)) + AssertEq(test_val, GetFlag(flag)) SetEnvVar(env_var, None) - AssertEq(default_val, GetFlag(command, flag)) - - -def TestEnvVarAffectsFlag(command): - """An environment variable should affect the corresponding flag.""" - - TestFlag(command, 'break_on_failure', '1', '0') - TestFlag(command, 'color', 'yes', 'auto') - TestFlag(command, 'filter', 'FooTest.Bar', '*') - TestFlag(command, 'output', 'tmp/foo.xml', '') - TestFlag(command, 'print_time', '0', '1') - TestFlag(command, 'repeat', '999', '1') - TestFlag(command, 'throw_on_failure', '1', '0') - TestFlag(command, 'death_test_style', 'threadsafe', 'fast') - - if IS_WINDOWS: - TestFlag(command, 'catch_exceptions', '1', '0') - - if IS_LINUX: - TestFlag(command, 'death_test_use_fork', '1', '0') - TestFlag(command, 'stack_trace_depth', '0', '100') + AssertEq(default_val, GetFlag(flag)) class GTestEnvVarTest(gtest_test_utils.TestCase): def testEnvVarAffectsFlag(self): - TestEnvVarAffectsFlag(COMMAND) + """Tests that environment variable should affect the corresponding flag.""" + + TestFlag('break_on_failure', '1', '0') + TestFlag('color', 'yes', 'auto') + TestFlag('filter', 'FooTest.Bar', '*') + TestFlag('output', 'tmp/foo.xml', '') + TestFlag('print_time', '0', '1') + TestFlag('repeat', '999', '1') + TestFlag('throw_on_failure', '1', '0') + TestFlag('death_test_style', 'threadsafe', 'fast') + + if IS_WINDOWS: + TestFlag('catch_exceptions', '1', '0') + + if IS_LINUX: + TestFlag('death_test_use_fork', '1', '0') + TestFlag('stack_trace_depth', '0', '100') if __name__ == '__main__': -- cgit v1.2.3 From 16e9dd6e28a8a7fb2d611011e7353e042fcb282f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 4 Sep 2009 18:30:25 +0000 Subject: More implementation of the event listener interface (by Vlad Losev); Reduces the stack space usage of assertions by moving AssertHelper's fields to the heap (by Jorg Brown); Makes String faster, smaller, and simpler (by Zhanyong Wan); Fixes a bug in String::Format() (by Chandler); Adds the /MD version of VC projects to the distribution (by Vlad Losev). --- test/gtest_env_var_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 19fd8103..f8250d4c 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -85,7 +85,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): TestFlag('break_on_failure', '1', '0') TestFlag('color', 'yes', 'auto') TestFlag('filter', 'FooTest.Bar', '*') - TestFlag('output', 'tmp/foo.xml', '') + TestFlag('output', 'xml:tmp/foo.xml', '') TestFlag('print_time', '0', '1') TestFlag('repeat', '999', '1') TestFlag('throw_on_failure', '1', '0') -- cgit v1.2.3 From 6f50ccf32c31cb6e287cdfee149429ac3029bbdb Mon Sep 17 00:00:00 2001 From: vladlosev Date: Mon, 15 Feb 2010 21:31:41 +0000 Subject: Google Test's Python tests now pass on Solaris. --- test/gtest_env_var_test.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index f8250d4c..bcc0bfd5 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -42,6 +42,8 @@ IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_') +environ = os.environ.copy() + def AssertEq(expected, actual): if expected != actual: @@ -54,9 +56,9 @@ def SetEnvVar(env_var, value): """Sets the env variable to 'value'; unsets it when 'value' is None.""" if value is not None: - os.environ[env_var] = value - elif env_var in os.environ: - del os.environ[env_var] + environ[env_var] = value + elif env_var in environ: + del environ[env_var] def GetFlag(flag): @@ -65,7 +67,7 @@ def GetFlag(flag): args = [COMMAND] if flag is not None: args += [flag] - return gtest_test_utils.Subprocess(args).output + return gtest_test_utils.Subprocess(args, env=environ).output def TestFlag(flag, test_val, default_val): -- cgit v1.2.3 From 82cc1d1135879be3b901a10e224dbd827365f8bf Mon Sep 17 00:00:00 2001 From: vladlosev Date: Tue, 26 Oct 2010 23:12:47 +0000 Subject: Changes default of --gtest_catch_exceptions to true. --- test/gtest_env_var_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index bcc0bfd5..ac24337f 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -92,9 +92,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): TestFlag('repeat', '999', '1') TestFlag('throw_on_failure', '1', '0') TestFlag('death_test_style', 'threadsafe', 'fast') - - if IS_WINDOWS: - TestFlag('catch_exceptions', '1', '0') + TestFlag('catch_exceptions', '0', '1') if IS_LINUX: TestFlag('death_test_use_fork', '1', '0') -- cgit v1.2.3 From f0b86fc3b0f625e1db84f3632cb37bd9eae6ae19 Mon Sep 17 00:00:00 2001 From: jgm Date: Fri, 9 Mar 2012 17:12:39 +0000 Subject: Misc small updates to some debug death code, and to messages streaming to macros --- test/gtest_env_var_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index ac24337f..4728bbc3 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -67,7 +67,8 @@ def GetFlag(flag): args = [COMMAND] if flag is not None: args += [flag] - return gtest_test_utils.Subprocess(args, env=environ).output + return gtest_test_utils.Subprocess(args, env=environ, + capture_stderr=False).output def TestFlag(flag, test_val, default_val): -- cgit v1.2.3 From b535c1767e7ec4e9675bb7257d9bc34a84949741 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Thu, 6 Sep 2012 17:09:27 +0000 Subject: Removes obsolete debug code. --- test/gtest_env_var_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/gtest_env_var_test.py') diff --git a/test/gtest_env_var_test.py b/test/gtest_env_var_test.py index 4728bbc3..ac24337f 100755 --- a/test/gtest_env_var_test.py +++ b/test/gtest_env_var_test.py @@ -67,8 +67,7 @@ def GetFlag(flag): args = [COMMAND] if flag is not None: args += [flag] - return gtest_test_utils.Subprocess(args, env=environ, - capture_stderr=False).output + return gtest_test_utils.Subprocess(args, env=environ).output def TestFlag(flag, test_val, default_val): -- cgit v1.2.3