From c113a7151d282cd32d246062783c83ccc65feb28 Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 12:42:23 -0400 Subject: [PATCH 1/9] Added support for WINAPI_PARTITION_TV_TITLE which is defined on XboxOne --- googletest/include/gtest/internal/gtest-port-arch.h | 3 +++ googletest/src/gtest.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index 74ab9490..e1c74733 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -54,6 +54,9 @@ # define GTEST_OS_WINDOWS_PHONE 1 # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) # define GTEST_OS_WINDOWS_RT 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) +# define GTEST_OS_WINDOWS_PHONE 1 +# define GTEST_OS_WINDOWS_TV_TITLE 1 # else // WINAPI_FAMILY defined but no known partition matched. // Default to desktop. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d882ab2e..01041564 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -1663,7 +1663,7 @@ namespace { AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -# if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE // Windows CE doesn't support FormatMessage. const char error_text[] = ""; From 569d713a39d5dd92dfb102f2dc91b489584ce4cd Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 12:42:23 -0400 Subject: [PATCH 2/9] Added support for WINAPI_PARTITION_TV_TITLE which is defined on XboxOne --- googletest/include/gtest/internal/gtest-port-arch.h | 3 +++ googletest/src/gtest.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index bb206167..02ff07b4 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -54,6 +54,9 @@ # define GTEST_OS_WINDOWS_PHONE 1 # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) # define GTEST_OS_WINDOWS_RT 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) +# define GTEST_OS_WINDOWS_PHONE 1 +# define GTEST_OS_WINDOWS_TV_TITLE 1 # else // WINAPI_FAMILY defined but no known partition matched. // Default to desktop. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 0aeeb8e7..407241c8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -1655,7 +1655,7 @@ namespace { AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -# if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE // Windows CE doesn't support FormatMessage. const char error_text[] = ""; From 33d73d42b42ac104db99ad021f018db681022bd8 Mon Sep 17 00:00:00 2001 From: gpetit Date: Mon, 14 Aug 2017 12:42:23 -0400 Subject: [PATCH 3/9] Added support for WINAPI_PARTITION_TV_TITLE which is defined on XboxOne --- googletest/include/gtest/internal/gtest-port-arch.h | 3 +++ googletest/src/gtest.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index bb206167..02ff07b4 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -54,6 +54,9 @@ # define GTEST_OS_WINDOWS_PHONE 1 # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) # define GTEST_OS_WINDOWS_RT 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) +# define GTEST_OS_WINDOWS_PHONE 1 +# define GTEST_OS_WINDOWS_TV_TITLE 1 # else // WINAPI_FAMILY defined but no known partition matched. // Default to desktop. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 0aeeb8e7..407241c8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -1655,7 +1655,7 @@ namespace { AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -# if GTEST_OS_WINDOWS_MOBILE +# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE // Windows CE doesn't support FormatMessage. const char error_text[] = ""; From 8d707dfe817df153efd6fe7832b6149244ed7665 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 22 Jan 2018 11:47:30 -0500 Subject: [PATCH 4/9] code merge --- googletest/test/gtest_color_test.py | 1 - googletest/test/gtest_filter_unittest.py | 38 ++++++++++--------- googletest/test/gtest_list_tests_unittest.py | 8 ++-- googletest/test/gtest_output_test.py | 13 ++++--- googletest/test/gtest_test_utils.py | 16 ++++---- .../test/gtest_throw_on_failure_test.py | 2 +- googletest/test/gtest_uninitialized_test.py | 5 ++- googletest/test/gtest_xml_outfiles_test.py | 4 -- 8 files changed, 44 insertions(+), 43 deletions(-) diff --git a/googletest/test/gtest_color_test.py b/googletest/test/gtest_color_test.py index d02a53ed..7d3e888a 100755 --- a/googletest/test/gtest_color_test.py +++ b/googletest/test/gtest_color_test.py @@ -36,7 +36,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import gtest_test_utils - IS_WINDOWS = os.name = 'nt' COLOR_ENV_VAR = 'GTEST_COLOR' diff --git a/googletest/test/gtest_filter_unittest.py b/googletest/test/gtest_filter_unittest.py index ec0b151b..92cc77c8 100755 --- a/googletest/test/gtest_filter_unittest.py +++ b/googletest/test/gtest_filter_unittest.py @@ -44,12 +44,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import re -try: - from sets import Set as set # For Python 2.3 compatibility -except ImportError: - pass +import sets import sys - import gtest_test_utils # Constants. @@ -59,10 +55,12 @@ import gtest_test_utils # script in a subprocess to print whether the variable is STILL in # os.environ. We then use 'eval' to parse the child's output so that an # exception is thrown if the input is anything other than 'True' nor 'False'. -os.environ['EMPTY_VAR'] = '' -child = gtest_test_utils.Subprocess( - [sys.executable, '-c', 'import os; print(\'EMPTY_VAR\' in os.environ)']) -CAN_PASS_EMPTY_ENV = eval(child.output) +CAN_PASS_EMPTY_ENV = False +if sys.executable: + os.environ['EMPTY_VAR'] = '' + child = gtest_test_utils.Subprocess( + [sys.executable, '-c', 'import os; print \'EMPTY_VAR\' in os.environ']) + CAN_PASS_EMPTY_ENV = eval(child.output) # Check if this platform can unset environment variables in child processes. @@ -71,11 +69,14 @@ CAN_PASS_EMPTY_ENV = eval(child.output) # is NO LONGER in os.environ. # We use 'eval' to parse the child's output so that an exception # is thrown if the input is neither 'True' nor 'False'. -os.environ['UNSET_VAR'] = 'X' -del os.environ['UNSET_VAR'] -child = gtest_test_utils.Subprocess( - [sys.executable, '-c', 'import os; print(\'UNSET_VAR\' not in os.environ)']) -CAN_UNSET_ENV = eval(child.output) +CAN_UNSET_ENV = False +if sys.executable: + os.environ['UNSET_VAR'] = 'X' + del os.environ['UNSET_VAR'] + child = gtest_test_utils.Subprocess( + [sys.executable, '-c', 'import os; print \'UNSET_VAR\' not in os.environ' + ]) + CAN_UNSET_ENV = eval(child.output) # Checks if we should test with an empty filter. This doesn't @@ -97,7 +98,7 @@ SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE' FILTER_FLAG = 'gtest_filter' # The command line flag for including disabled tests. -ALSO_RUN_DISABED_TESTS_FLAG = 'gtest_also_run_disabled_tests' +ALSO_RUN_DISABLED_TESTS_FLAG = 'gtest_also_run_disabled_tests' # Command to run the gtest_filter_unittest_ program. COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_filter_unittest_') @@ -246,14 +247,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase): for slice_var in list_of_sets: full_partition.extend(slice_var) self.assertEqual(len(set_var), len(full_partition)) - self.assertEqual(set(set_var), set(full_partition)) + self.assertEqual(sets.Set(set_var), sets.Set(full_partition)) def AdjustForParameterizedTests(self, tests_to_run): """Adjust tests_to_run in case value parameterized tests are disabled.""" global param_tests_present if not param_tests_present: - return list(set(tests_to_run) - set(PARAM_TESTS)) + return list(sets.Set(tests_to_run) - sets.Set(PARAM_TESTS)) else: return tests_to_run @@ -294,6 +295,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase): Runs all shards of gtest_filter_unittest_ with the given filter, and verifies that the right set of tests were run. The union of tests run on each shard should be identical to tests_to_run, without duplicates. + If check_exit_0, . Args: gtest_filter: A filter to apply to the tests. @@ -339,7 +341,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase): tests_to_run = self.AdjustForParameterizedTests(tests_to_run) # Construct the command line. - args = ['--%s' % ALSO_RUN_DISABED_TESTS_FLAG] + args = ['--%s' % ALSO_RUN_DISABLED_TESTS_FLAG] if gtest_filter is not None: args.append('--%s=%s' % (FILTER_FLAG, gtest_filter)) diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index f2d2fd1b..0844f98a 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -39,9 +39,8 @@ Google Test) the command line flags. __author__ = 'phanna@google.com (Patrick Hanna)' -import gtest_test_utils import re - +import gtest_test_utils # Constants. @@ -71,7 +70,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? +TypedTest/1\. # TypeParam = int\s*\* TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -80,7 +79,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? +My/TypeParamTest/1\. # TypeParam = int\s*\* TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray @@ -123,6 +122,7 @@ def Run(args): # The unit test. + class GTestListTestsUnitTest(gtest_test_utils.TestCase): """Tests using the --gtest_list_tests flag to list all tests.""" diff --git a/googletest/test/gtest_output_test.py b/googletest/test/gtest_output_test.py index 78a00156..e431653a 100755 --- a/googletest/test/gtest_output_test.py +++ b/googletest/test/gtest_output_test.py @@ -31,6 +31,7 @@ """Tests the text output of Google C++ Testing Framework. + SYNOPSIS gtest_output_test.py --build_dir=BUILD/DIR --gengolden # where BUILD/DIR contains the built gtest_output_test_ file. @@ -51,6 +52,7 @@ import gtest_test_utils GENGOLDEN_FLAG = '--gengolden' CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS' +IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' IS_WINDOWS = os.name == 'nt' # TODO(vladl@google.com): remove the _lin suffix. @@ -250,11 +252,12 @@ test_list = GetShellCommandOutput(COMMAND_LIST_TESTS) SUPPORTS_DEATH_TESTS = 'DeathTest' in test_list SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list -SUPPORTS_STACK_TRACES = False +SUPPORTS_STACK_TRACES = IS_LINUX CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and SUPPORTS_TYPED_TESTS and SUPPORTS_THREADS and + SUPPORTS_STACK_TRACES and not IS_WINDOWS) class GTestOutputTest(gtest_test_utils.TestCase): @@ -280,7 +283,7 @@ class GTestOutputTest(gtest_test_utils.TestCase): def testOutput(self): output = GetOutputOfAllCommands() - golden_file = open(GOLDEN_PATH, 'r') + golden_file = open(GOLDEN_PATH, 'rb') # A mis-configured source control system can cause \r appear in EOL # sequences when we read the golden file irrespective of an operating # system used. Therefore, we need to strip those \r's from newlines @@ -331,9 +334,9 @@ if __name__ == '__main__': else: message = ( """Unable to write a golden file when compiled in an environment -that does not support all the required features (death tests, typed tests, -and multiple threads). Please generate the golden file using a binary built -with those features enabled.""") +that does not support all the required features (death tests, +typed tests, stack traces, and multiple threads). +Please build this test and generate the golden file using Blaze on Linux.""") sys.stderr.write(message) sys.exit(1) diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index d2b6748d..89d1469a 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Copyright 2006, Google Inc. # All rights reserved. # @@ -33,10 +31,15 @@ __author__ = 'wan@google.com (Zhanyong Wan)' -import atexit import os -import shutil import sys + +IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' +IS_WINDOWS = os.name == 'nt' +IS_CYGWIN = os.name == 'posix' and 'CYGWIN' in os.uname()[0] + +import atexit +import shutil import tempfile import unittest _test_module = unittest @@ -53,9 +56,6 @@ except: GTEST_OUTPUT_VAR_NAME = 'GTEST_OUTPUT' -IS_WINDOWS = os.name == 'nt' -IS_CYGWIN = os.name == 'posix' and 'CYGWIN' in os.uname()[0] - # The environment variable for specifying the path to the premature-exit file. PREMATURE_EXIT_FILE_ENV_VAR = 'TEST_PREMATURE_EXIT_FILE' @@ -178,7 +178,7 @@ def GetTestExecutablePath(executable_name, build_dir=None): 'Unable to find the test binary "%s". Please make sure to provide\n' 'a path to the binary via the --build_dir flag or the BUILD_DIR\n' 'environment variable.' % path) - sys.stdout.write(message) + print >> sys.stderr, message sys.exit(1) return path diff --git a/googletest/test/gtest_throw_on_failure_test.py b/googletest/test/gtest_throw_on_failure_test.py index 3e7740ca..5678ffea 100755 --- a/googletest/test/gtest_throw_on_failure_test.py +++ b/googletest/test/gtest_throw_on_failure_test.py @@ -70,7 +70,7 @@ def SetEnvVar(env_var, value): def Run(command): """Runs a command; returns True/False if its exit code is/isn't 0.""" - print('Running "%s". . .' % ' '.join(command)) + print 'Running "%s". . .' % ' '.join(command) p = gtest_test_utils.Subprocess(command) return p.exited and p.exit_code == 0 diff --git a/googletest/test/gtest_uninitialized_test.py b/googletest/test/gtest_uninitialized_test.py index 43583700..41bc4810 100755 --- a/googletest/test/gtest_uninitialized_test.py +++ b/googletest/test/gtest_uninitialized_test.py @@ -33,6 +33,7 @@ __author__ = 'wan@google.com (Zhanyong Wan)' +import os import gtest_test_utils @@ -46,8 +47,8 @@ def Assert(condition): def AssertEq(expected, actual): if expected != actual: - print('Expected: %s' % (expected,)) - print(' Actual: %s' % (actual,)) + print 'Expected: %s' % (expected,) + print ' Actual: %s' % (actual,) raise AssertionError diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index 678f546c..24c6ee6b 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -31,15 +31,11 @@ """Unit test for the gtest_xml_output module.""" -__author__ = "keith.ray@gmail.com (Keith Ray)" - import os from xml.dom import minidom, Node - import gtest_test_utils import gtest_xml_test_utils - GTEST_OUTPUT_SUBDIR = "xml_outfiles" GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_" GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" From a0435a54ce837595426c213dfdc8e951201371ee Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 22 Jan 2018 14:14:05 -0500 Subject: [PATCH 5/9] merging --- googletest/test/gtest_test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index 89d1469a..db06f2e1 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -28,6 +28,8 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Unit test utilities for Google C++ Testing Framework.""" +# Suppresses the 'Import not at the top of the file' lint complaint. +# pylint: disable-msg=C6204 __author__ = 'wan@google.com (Zhanyong Wan)' @@ -44,8 +46,6 @@ import tempfile import unittest _test_module = unittest -# Suppresses the 'Import not at the top of the file' lint complaint. -# pylint: disable-msg=C6204 try: import subprocess _SUBPROCESS_MODULE_AVAILABLE = True From 9bc86661f86a5c946f9e0a29ea2e34c8a9897d6b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 22 Jan 2018 14:43:51 -0500 Subject: [PATCH 6/9] more merging --- googletest/test/gtest_list_tests_unittest.py | 8 ++++---- googletest/test/gtest_test_utils.py | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index 0844f98a..f2d2fd1b 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -39,8 +39,9 @@ Google Test) the command line flags. __author__ = 'phanna@google.com (Patrick Hanna)' -import re import gtest_test_utils +import re + # Constants. @@ -70,7 +71,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\* +TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -79,7 +80,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\* +My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray @@ -122,7 +123,6 @@ def Run(args): # The unit test. - class GTestListTestsUnitTest(gtest_test_utils.TestCase): """Tests using the --gtest_list_tests flag to list all tests.""" diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index db06f2e1..7c489336 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -145,8 +145,6 @@ atexit.register(_RemoveTempDir) def GetTempDir(): - """Returns a directory for temporary files.""" - global _temp_dir if not _temp_dir: _temp_dir = tempfile.mkdtemp() From f1c87ad9f518b86a1efc2a68f452aaf53b899bfe Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 22 Jan 2018 15:20:19 -0500 Subject: [PATCH 7/9] merges, cl/155419551 and other --- googletest/include/gtest/gtest.h | 11 ++-- googletest/src/gtest.cc | 9 ++-- googletest/test/gtest_xml_output_unittest.py | 55 ++++++++++++++++---- googletest/test/gtest_xml_test_utils.py | 14 ++--- 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 4a8f6e0a..93b755fb 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -687,6 +687,9 @@ class GTEST_API_ TestInfo { // Returns the line where this test is defined. int line() const { return location_.line; } + // Return true if this test should not be run because it's in another shard. + bool is_in_another_shard() const { return is_in_another_shard_; } + // Returns true if this test should run, that is if the test is not // disabled (or it is disabled but the also_run_disabled_tests flag has // been specified) and its full name matches the user-specified filter. @@ -707,10 +710,9 @@ class GTEST_API_ TestInfo { // Returns true iff this test will appear in the XML report. bool is_reportable() const { - // The XML report includes tests matching the filter. - // In the future, we may trim tests that are excluded because of - // sharding. - return matches_filter_; + // The XML report includes tests matching the filter, excluding those + // run in other shards. + return matches_filter_ && !is_in_another_shard_; } // Returns the result of the test. @@ -774,6 +776,7 @@ class GTEST_API_ TestInfo { bool is_disabled_; // True iff this test is disabled bool matches_filter_; // True if this test matches the // user-specified filter. + bool is_in_another_shard_; // Will be run in another shard. internal::TestFactoryBase* const factory_; // The factory that creates // the test object diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 723d905b..3435f9cb 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4813,10 +4813,11 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) && matches_filter; - const bool is_selected = is_runnable && - (shard_tests == IGNORE_SHARDING_PROTOCOL || - ShouldRunTestOnShard(total_shards, shard_index, - num_runnable_tests)); + const bool is_in_another_shard = + shard_tests != IGNORE_SHARDING_PROTOCOL && + !ShouldRunTestOnShard(total_shards, shard_index, num_runnable_tests); + test_info->is_in_another_shard_ = is_in_another_shard; + const bool is_selected = is_runnable && !is_in_another_shard; num_runnable_tests += is_runnable; num_selected_tests += is_selected; diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 9f92f982..2d50b154 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -31,8 +31,6 @@ """Unit test for the gtest_xml_output module""" -__author__ = 'eefacm@gmail.com (Sean Mcafee)' - import datetime import errno import os @@ -46,9 +44,14 @@ import gtest_xml_test_utils GTEST_FILTER_FLAG = '--gtest_filter' GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' -GTEST_OUTPUT_FLAG = "--gtest_output" -GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml" -GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_" +GTEST_OUTPUT_FLAG = '--gtest_output' +GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml' +GTEST_PROGRAM_NAME = 'gtest_xml_output_unittest_' + +# The environment variables for test sharding. +TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS' +SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX' +SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE' SUPPORTS_STACK_TRACES = False @@ -141,6 +144,19 @@ EXPECTED_FILTERED_TEST_XML = """ """ +EXPECTED_SHARDED_TEST_XML = """ + + + + + + + + + + +""" + EXPECTED_EMPTY_XML = """ @@ -182,7 +198,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): Runs a test program that generates an empty XML output, and checks if the timestamp attribute in the testsuites tag is valid. """ - actual = self._GetXmlOutput('gtest_no_test_unittest', [], 0) + actual = self._GetXmlOutput('gtest_no_test_unittest', [], {}, 0) date_time_str = actual.documentElement.getAttributeNode('timestamp').value # datetime.strptime() is only available in Python 2.5+ so we have to # parse the expected datetime manually. @@ -263,7 +279,22 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0, extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG]) - def _GetXmlOutput(self, gtest_prog_name, extra_args, expected_exit_code): + def testShardedTestXmlOutput(self): + """Verifies XML output when run using multiple shards. + + Runs a test program that executes only one shard and verifies that tests + from other shards do not show up in the XML output. + """ + + self._TestXmlOutput( + GTEST_PROGRAM_NAME, + EXPECTED_SHARDED_TEST_XML, + 0, + extra_env={SHARD_INDEX_ENV_VAR: '0', + TOTAL_SHARDS_ENV_VAR: '10'}) + + def _GetXmlOutput(self, gtest_prog_name, extra_args, extra_env, + expected_exit_code): """ Returns the xml output generated by running the program gtest_prog_name. Furthermore, the program's exit code must be expected_exit_code. @@ -274,7 +305,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] + extra_args) - p = gtest_test_utils.Subprocess(command) + environ_copy = os.environ.copy() + if extra_env: + environ_copy.update(extra_env) + p = gtest_test_utils.Subprocess(command, env=environ_copy) + if p.terminated_by_signal: self.assert_(False, '%s was killed by signal %d' % (gtest_prog_name, p.signal)) @@ -288,7 +323,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): return actual def _TestXmlOutput(self, gtest_prog_name, expected_xml, - expected_exit_code, extra_args=None): + expected_exit_code, extra_args=None, extra_env=None): """ Asserts that the XML document generated by running the program gtest_prog_name matches expected_xml, a string containing another @@ -297,7 +332,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): """ actual = self._GetXmlOutput(gtest_prog_name, extra_args or [], - expected_exit_code) + extra_env or {}, expected_exit_code) expected = minidom.parseString(expected_xml) self.NormalizeXml(actual.documentElement) self.AssertEquivalentNodes(expected.documentElement, diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py index 341956b5..6694519b 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Copyright 2006, Google Inc. # All rights reserved. # @@ -31,12 +29,10 @@ """Unit test utilities for gtest_xml_output""" -__author__ = 'eefacm@gmail.com (Sean Mcafee)' - +import os import re -from xml.dom import minidom, Node - import gtest_test_utils +from xml.dom import minidom, Node GTEST_OUTPUT_FLAG = '--gtest_output' @@ -101,7 +97,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): self.assertEquals( len(expected_children), len(actual_children), 'number of child elements differ in element ' + actual_node.tagName) - for child_id, child in expected_children.items(): + for child_id, child in expected_children.iteritems(): self.assert_(child_id in actual_children, '<%s> is not in <%s> (in element %s)' % (child_id, actual_children, actual_node.tagName)) @@ -187,8 +183,8 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): # Replaces the source line information with a normalized form. cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue) # Removes the actual stack trace. - child.nodeValue = re.sub(r'\nStack trace:\n(.|\n)*', - '', cdata) + child.nodeValue = re.sub(r'Stack trace:\n(.|\n)*', + 'Stack trace:\n*', cdata) for child in element.childNodes: if child.nodeType == Node.ELEMENT_NODE: self.NormalizeXml(child) From bbb17ad0f78cd2c6fbf5931c522db0a30deceb0a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 22 Jan 2018 15:28:55 -0500 Subject: [PATCH 8/9] more code merge --- googletest/test/gtest_xml_output_unittest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 2d50b154..325ca131 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -41,7 +41,6 @@ from xml.dom import minidom, Node import gtest_test_utils import gtest_xml_test_utils - GTEST_FILTER_FLAG = '--gtest_filter' GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' GTEST_OUTPUT_FLAG = '--gtest_output' @@ -228,8 +227,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase): 'gtest_no_test_unittest') try: os.remove(output_file) - except OSError: - e = sys.exc_info()[1] + except OSError, e: if e.errno != errno.ENOENT: raise From 6723b6c588e2dda587682e96e1f1fe0235d3eece Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 23 Jan 2018 10:15:28 -0500 Subject: [PATCH 9/9] Merging, upstream http://cl/182836545 --- googletest/test/gtest_repeat_test.cc | 2 +- googletest/test/gtest_uninitialized_test.py | 5 ++--- googletest/test/gtest_uninitialized_test_.cc | 4 ++-- googletest/test/gtest_unittest.cc | 6 +++--- googletest/test/gtest_xml_test_utils.py | 1 - 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/googletest/test/gtest_repeat_test.cc b/googletest/test/gtest_repeat_test.cc index b9e65e4c..31716043 100644 --- a/googletest/test/gtest_repeat_test.cc +++ b/googletest/test/gtest_repeat_test.cc @@ -67,7 +67,7 @@ namespace { // Used for verifying that global environment set-up and tear-down are -// inside the gtest_repeat loop. +// inside the --gtest_repeat loop. int g_environment_set_up_count = 0; int g_environment_tear_down_count = 0; diff --git a/googletest/test/gtest_uninitialized_test.py b/googletest/test/gtest_uninitialized_test.py index 41bc4810..574db77a 100755 --- a/googletest/test/gtest_uninitialized_test.py +++ b/googletest/test/gtest_uninitialized_test.py @@ -36,7 +36,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import gtest_test_utils - COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_') @@ -57,8 +56,8 @@ def TestExitCodeAndOutput(command): # Verifies that 'command' exits with code 1. p = gtest_test_utils.Subprocess(command) - Assert(p.exited) - AssertEq(1, p.exit_code) + if p.exited and p.exit_code == 0: + Assert('IMPORTANT NOTICE' in p.output); Assert('InitGoogleTest' in p.output) diff --git a/googletest/test/gtest_uninitialized_test_.cc b/googletest/test/gtest_uninitialized_test_.cc index 44316987..502b0add 100644 --- a/googletest/test/gtest_uninitialized_test_.cc +++ b/googletest/test/gtest_uninitialized_test_.cc @@ -34,8 +34,8 @@ TEST(DummyTest, Dummy) { // This test doesn't verify anything. We just need it to create a // realistic stage for testing the behavior of Google Test when - // RUN_ALL_TESTS() is called without testing::InitGoogleTest() being - // called first. + // RUN_ALL_TESTS() is called without + // testing::InitGoogleTest() being called first. } int main() { diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 53945622..a45927d0 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -34,9 +34,9 @@ #include "gtest/gtest.h" -// Verifies that the command line flag variables can be accessed -// in code once has been #included. -// Do not move it after other #includes. +// Verifies that the command line flag variables can be accessed in +// code once "gtest/gtest.h" has been +// #included. Do not move it after other gtest #includes. TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { bool dummy = testing::GTEST_FLAG(also_run_disabled_tests) || testing::GTEST_FLAG(break_on_failure) diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py index 6694519b..30c25d98 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -35,7 +35,6 @@ import gtest_test_utils from xml.dom import minidom, Node -GTEST_OUTPUT_FLAG = '--gtest_output' GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml' class GTestXMLTestCase(gtest_test_utils.TestCase):