-#!/usr/bin/env python
-#
-# Copyright 2009, Google Inc.
-# All rights reserved.
+# Copyright 2021 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
# 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.
+"""Unit test for Google Test's global test environment behavior.
-"""upload_gmock.py v0.1.0 -- uploads a Google Mock patch for review.
-
-This simple wrapper passes all command line flags and
---cc=googlemock@googlegroups.com to upload.py.
+A user can specify a global test environment via
+testing::AddGlobalTestEnvironment. Failures in the global environment should
+result in all unit tests being skipped.
-USAGE: upload_gmock.py [options for upload.py]
+This script tests such functionality by invoking
+googletest-global-environment-unittest_ (a program written with Google Test).
"""
-__author__ = 'wan@google.com (Zhanyong Wan)'
+import gtest_test_utils
+
+
+def RunAndReturnOutput():
+ """Runs the test program and returns its output."""
+
+ return gtest_test_utils.Subprocess([
+ gtest_test_utils.GetTestExecutablePath(
+ 'googletest-global-environment-unittest_')
+ ]).output
-import os
-import sys
-CC_FLAG = '--cc='
-GMOCK_GROUP = 'googlemock@googlegroups.com'
+class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
+ """Tests global test environment failures."""
+ def testEnvironmentSetUpFails(self):
+ """Tests the behavior of not specifying the fail_fast."""
-def main():
- # Finds the path to upload.py, assuming it is in the same directory
- # as this file.
- my_dir = os.path.dirname(os.path.abspath(__file__))
- upload_py_path = os.path.join(my_dir, 'upload.py')
+ # Run the test.
+ txt = RunAndReturnOutput()
- # Adds Google Mock discussion group to the cc line if it's not there
- # already.
- upload_py_argv = [upload_py_path]
- found_cc_flag = False
- for arg in sys.argv[1:]:
- if arg.startswith(CC_FLAG):
- found_cc_flag = True
- cc_line = arg[len(CC_FLAG):]
- cc_list = [addr for addr in cc_line.split(',') if addr]
- if GMOCK_GROUP not in cc_list:
- cc_list.append(GMOCK_GROUP)
- upload_py_argv.append(CC_FLAG + ','.join(cc_list))
- else:
- upload_py_argv.append(arg)
+ # We should see the text of the global environment setup error.
+ self.assertIn('Canned environment setup error', txt)
- if not found_cc_flag:
- upload_py_argv.append(CC_FLAG + GMOCK_GROUP)
+ # Our test should have been skipped due to the error, and not treated as a
+ # pass.
+ self.assertIn('[ SKIPPED ] 1 test', txt)
+ self.assertIn('[ PASSED ] 0 tests', txt)
- # Invokes upload.py with the modified command line flags.
- os.execv(upload_py_path, upload_py_argv)
+ # The test case shouldn't have been run.
+ self.assertNotIn('Unexpected call', txt)
if __name__ == '__main__':
- main()
+ gtest_test_utils.Main()