diff --git a/googlemock/test/gmock_leak_test.py b/googlemock/test/gmock_leak_test.py index 997680ce..a2fee4b6 100755 --- a/googlemock/test/gmock_leak_test.py +++ b/googlemock/test/gmock_leak_test.py @@ -1,108 +1,106 @@ #!/usr/bin/env python # # Copyright 2009, 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. """Tests that leaked mock objects can be caught be Google Mock.""" __author__ = 'wan@google.com (Zhanyong Wan)' - import gmock_test_utils - PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_') TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*'] TEST_WITH_ON_CALL = [PROGRAM_PATH, '--gtest_filter=*OnCall*'] TEST_MULTIPLE_LEAKS = [PROGRAM_PATH, '--gtest_filter=*MultipleLeaked*'] environ = gmock_test_utils.environ SetEnvVar = gmock_test_utils.SetEnvVar # Tests in this file run a Google-Test-based test program and expect it # to terminate prematurely. Therefore they are incompatible with # the premature-exit-file protocol by design. Unset the # premature-exit filepath to prevent Google Test from creating # the file. SetEnvVar(gmock_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None) class GMockLeakTest(gmock_test_utils.TestCase): def testCatchesLeakedMockByDefault(self): self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL, env=environ).exit_code) self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_WITH_ON_CALL, env=environ).exit_code) def testDoesNotCatchLeakedMockWhenDisabled(self): self.assertEquals( 0, gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks=0'], env=environ).exit_code) self.assertEquals( 0, gmock_test_utils.Subprocess(TEST_WITH_ON_CALL + ['--gmock_catch_leaked_mocks=0'], env=environ).exit_code) def testCatchesLeakedMockWhenEnabled(self): self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks'], env=environ).exit_code) self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_WITH_ON_CALL + ['--gmock_catch_leaked_mocks'], env=environ).exit_code) def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self): self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks=1'], env=environ).exit_code) def testCatchesMultipleLeakedMocks(self): self.assertNotEqual( 0, gmock_test_utils.Subprocess(TEST_MULTIPLE_LEAKS + ['--gmock_catch_leaked_mocks'], env=environ).exit_code) if __name__ == '__main__': gmock_test_utils.Main() diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index 9d73d570..8f57d46c 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -1,183 +1,182 @@ #!/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. """Tests the text output of Google C++ Mocking Framework. To update the golden file: gmock_output_test.py --build_dir=BUILD/DIR --gengolden # where BUILD/DIR contains the built gmock_output_test_ file. gmock_output_test.py --gengolden gmock_output_test.py """ __author__ = 'wan@google.com (Zhanyong Wan)' import os import re import sys - import gmock_test_utils # The flag for generating the golden file GENGOLDEN_FLAG = '--gengolden' PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_output_test_') COMMAND = [PROGRAM_PATH, '--gtest_stack_trace_depth=0', '--gtest_print_time=0'] GOLDEN_NAME = 'gmock_output_test_golden.txt' GOLDEN_PATH = os.path.join(gmock_test_utils.GetSourceDir(), GOLDEN_NAME) def ToUnixLineEnding(s): """Changes all Windows/Mac line endings in s to UNIX line endings.""" return s.replace('\r\n', '\n').replace('\r', '\n') def RemoveReportHeaderAndFooter(output): """Removes Google Test result report's header and footer from the output.""" output = re.sub(r'.*gtest_main.*\n', '', output) output = re.sub(r'\[.*\d+ tests.*\n', '', output) output = re.sub(r'\[.* test environment .*\n', '', output) output = re.sub(r'\[=+\] \d+ tests .* ran.*', '', output) output = re.sub(r'.* FAILED TESTS\n', '', output) return output def RemoveLocations(output): """Removes all file location info from a Google Test program's output. Args: output: the output of a Google Test program. Returns: output with all file location info (in the form of 'DIRECTORY/FILE_NAME:LINE_NUMBER: 'or 'DIRECTORY\\FILE_NAME(LINE_NUMBER): ') replaced by 'FILE:#: '. """ return re.sub(r'.*[/\\](.+)(\:\d+|\(\d+\))\:', 'FILE:#:', output) def NormalizeErrorMarker(output): """Normalizes the error marker, which is different on Windows vs on Linux.""" return re.sub(r' error: ', ' Failure\n', output) def RemoveMemoryAddresses(output): """Removes memory addresses from the test output.""" return re.sub(r'@\w+', '@0x#', output) def RemoveTestNamesOfLeakedMocks(output): """Removes the test names of leaked mock objects from the test output.""" return re.sub(r'\(used in test .+\) ', '', output) def GetLeakyTests(output): """Returns a list of test names that leak mock objects.""" # findall() returns a list of all matches of the regex in output. # For example, if '(used in test FooTest.Bar)' is in output, the # list will contain 'FooTest.Bar'. return re.findall(r'\(used in test (.+)\)', output) def GetNormalizedOutputAndLeakyTests(output): """Normalizes the output of gmock_output_test_. Args: output: The test output. Returns: A tuple (the normalized test output, the list of test names that have leaked mocks). """ output = ToUnixLineEnding(output) output = RemoveReportHeaderAndFooter(output) output = NormalizeErrorMarker(output) output = RemoveLocations(output) output = RemoveMemoryAddresses(output) return (RemoveTestNamesOfLeakedMocks(output), GetLeakyTests(output)) def GetShellCommandOutput(cmd): """Runs a command in a sub-process, and returns its STDOUT in a string.""" return gmock_test_utils.Subprocess(cmd, capture_stderr=False).output def GetNormalizedCommandOutputAndLeakyTests(cmd): """Runs a command and returns its normalized output and a list of leaky tests. Args: cmd: the shell command. """ # Disables exception pop-ups on Windows. os.environ['GTEST_CATCH_EXCEPTIONS'] = '1' return GetNormalizedOutputAndLeakyTests(GetShellCommandOutput(cmd)) class GMockOutputTest(gmock_test_utils.TestCase): def testOutput(self): (output, leaky_tests) = GetNormalizedCommandOutputAndLeakyTests(COMMAND) golden_file = open(GOLDEN_PATH, 'rb') golden = golden_file.read() golden_file.close() # The normalized output should match the golden file. self.assertEquals(golden, output) # The raw output should contain 2 leaked mock object errors for # test GMockOutputTest.CatchesLeakedMocks. self.assertEquals(['GMockOutputTest.CatchesLeakedMocks', 'GMockOutputTest.CatchesLeakedMocks'], leaky_tests) if __name__ == '__main__': if sys.argv[1:] == [GENGOLDEN_FLAG]: (output, _) = GetNormalizedCommandOutputAndLeakyTests(COMMAND) golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() # Suppress the error "googletest was imported but a call to its main() # was never detected." os._exit(0) else: gmock_test_utils.Main() diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 405feee7..6888e4ca 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -1,418 +1,426 @@ # Copyright 2017 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. # # Author: misterg@google.com (Gennadiy Civil) # # Bazel BUILD for The Google C++ Testing Framework (Google Test) licenses(["notice"]) config_setting( name = "windows", values = {"cpu": "x64_windows"}, ) config_setting( name = "windows_msvc", values = {"cpu": "x64_windows_msvc"}, ) config_setting( name = "has_absl", values = {"define": "absl=1"}, ) #on windows exclude gtest-tuple.h and gtest-tuple_test.cc cc_test( name = "gtest_all_test", size = "small", srcs = glob( include = [ "gtest-*.cc", "*.h", "googletest/include/gtest/**/*.h", ], exclude = [ "gtest-unittest-api_test.cc", "gtest-tuple_test.cc", "googletest/src/gtest-all.cc", "gtest_all_test.cc", "gtest-death-test_ex_test.cc", "gtest-listener_test.cc", "gtest-unittest-api_test.cc", "gtest-param-test_test.cc", ], ) + select({ "//:windows": [], "//:windows_msvc": [], "//conditions:default": [ "gtest-tuple_test.cc", ], }), copts = select({ "//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"], "//:windows_msvc": ["-DGTEST_USE_OWN_TR1_TUPLE=0"], "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"], }), includes = [ "googletest", "googletest/include", "googletest/include/internal", "googletest/test", ], linkopts = select({ "//:windows": [], "//:windows_msvc": [], "//conditions:default": [ "-pthread", ], }), deps = ["//:gtest_main"], ) + +cc_test( + name = "gtest_test_macro_stack_footprint_test", + size = "small", + srcs = ["gtest_test_macro_stack_footprint_test.cc"], + deps = ["//:gtest"], +) + #These googletest tests have their own main() cc_test( name = "gtest-listener_test", size = "small", srcs = [ "gtest-listener_test.cc", ], deps = [ "//:gtest", ], ) cc_test( name = "gtest-unittest-api_test", size = "small", srcs = [ "gtest-unittest-api_test.cc", ], deps = [ "//:gtest", ], ) cc_test( name = "gtest-param-test_test", size = "small", srcs = [ "gtest-param-test2_test.cc", "gtest-param-test_test.cc", "gtest-param-test_test.h", ], deps = [ "//:gtest", ], ) cc_test( name = "gtest_unittest", size = "small", srcs = ["gtest_unittest.cc"], args = ["--heap_check=strict"], shard_count = 2, deps = ["//:gtest_main"], ) # Py tests py_library( name = "gtest_test_utils", testonly = 1, srcs = ["gtest_test_utils.py"], ) cc_binary( name = "gtest_help_test_", testonly = 1, srcs = ["gtest_help_test_.cc"], deps = ["//:gtest_main"], ) py_test( name = "gtest_help_test", size = "small", srcs = ["gtest_help_test.py"], data = [":gtest_help_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_output_test_", testonly = 1, srcs = ["gtest_output_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_output_test", size = "small", srcs = ["gtest_output_test.py"], args = select({ ":has_absl": [], "//conditions:default": ["--no_stacktrace_support"], }), data = [ "gtest_output_test_golden_lin.txt", ":gtest_output_test_", ], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_color_test_", testonly = 1, srcs = ["gtest_color_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_color_test", size = "small", srcs = ["gtest_color_test.py"], data = [":gtest_color_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_env_var_test_", testonly = 1, srcs = ["gtest_env_var_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_env_var_test", size = "small", srcs = ["gtest_env_var_test.py"], data = [":gtest_env_var_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_filter_unittest_", testonly = 1, srcs = ["gtest_filter_unittest_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_filter_unittest", size = "small", srcs = ["gtest_filter_unittest.py"], data = [":gtest_filter_unittest_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_break_on_failure_unittest_", testonly = 1, srcs = ["gtest_break_on_failure_unittest_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_break_on_failure_unittest", size = "small", srcs = ["gtest_break_on_failure_unittest.py"], data = [":gtest_break_on_failure_unittest_"], deps = [":gtest_test_utils"], ) cc_test( name = "gtest_assert_by_exception_test", size = "small", srcs = ["gtest_assert_by_exception_test.cc"], deps = ["//:gtest"], ) cc_binary( name = "gtest_throw_on_failure_test_", testonly = 1, srcs = ["gtest_throw_on_failure_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_throw_on_failure_test", size = "small", srcs = ["gtest_throw_on_failure_test.py"], data = [":gtest_throw_on_failure_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_list_tests_unittest_", testonly = 1, srcs = ["gtest_list_tests_unittest_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_list_tests_unittest", size = "small", srcs = ["gtest_list_tests_unittest.py"], data = [":gtest_list_tests_unittest_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_shuffle_test_", srcs = ["gtest_shuffle_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_shuffle_test", size = "small", srcs = ["gtest_shuffle_test.py"], data = [":gtest_shuffle_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_catch_exceptions_no_ex_test_", testonly = 1, srcs = ["gtest_catch_exceptions_test_.cc"], deps = ["//:gtest_main"], ) cc_binary( name = "gtest_catch_exceptions_ex_test_", testonly = 1, srcs = ["gtest_catch_exceptions_test_.cc"], copts = ["-fexceptions"], deps = ["//:gtest_main"], ) py_test( name = "gtest_catch_exceptions_test", size = "small", srcs = ["gtest_catch_exceptions_test.py"], data = [ ":gtest_catch_exceptions_ex_test_", ":gtest_catch_exceptions_no_ex_test_", ], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_xml_output_unittest_", testonly = 1, srcs = ["gtest_xml_output_unittest_.cc"], deps = ["//:gtest"], ) cc_test( name = "gtest_no_test_unittest", size = "small", srcs = ["gtest_no_test_unittest.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_xml_output_unittest", size = "small", srcs = [ "gtest_xml_output_unittest.py", "gtest_xml_test_utils.py", ], args = select({ ":has_absl": [], "//conditions:default": ["--no_stacktrace_support"], }), data = [ # We invoke gtest_no_test_unittest to verify the XML output # when the test program contains no test definition. ":gtest_no_test_unittest", ":gtest_xml_output_unittest_", ], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_xml_outfile1_test_", testonly = 1, srcs = ["gtest_xml_outfile1_test_.cc"], deps = ["//:gtest_main"], ) cc_binary( name = "gtest_xml_outfile2_test_", testonly = 1, srcs = ["gtest_xml_outfile2_test_.cc"], deps = ["//:gtest_main"], ) py_test( name = "gtest_xml_outfiles_test", size = "small", srcs = [ "gtest_xml_outfiles_test.py", "gtest_xml_test_utils.py", ], data = [ ":gtest_xml_outfile1_test_", ":gtest_xml_outfile2_test_", ], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_uninitialized_test_", testonly = 1, srcs = ["gtest_uninitialized_test_.cc"], deps = ["//:gtest"], ) py_test( name = "gtest_uninitialized_test", size = "medium", srcs = ["gtest_uninitialized_test.py"], data = [":gtest_uninitialized_test_"], deps = [":gtest_test_utils"], ) cc_binary( name = "gtest_testbridge_test_", testonly = 1, srcs = ["gtest_testbridge_test_.cc"], deps = ["//:gtest_main"], ) # Tests that filtering via testbridge works py_test( name = "gtest_testbridge_test", size = "small", srcs = ["gtest_testbridge_test.py"], data = [":gtest_testbridge_test_"], deps = [":gtest_test_utils"], ) diff --git a/googletest/test/gtest_test_macro_stack_footprint_test.cc b/googletest/test/gtest_test_macro_stack_footprint_test.cc new file mode 100644 index 00000000..48958b85 --- /dev/null +++ b/googletest/test/gtest_test_macro_stack_footprint_test.cc @@ -0,0 +1,90 @@ +// Copyright 2013, 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. +// +// Author: wan@google.com (Zhanyong Wan) +// +// Each TEST() expands to some static registration logic. GCC puts all +// such static initialization logic for a translation unit in a common, +// internal function. Since Google's build system restricts how much +// stack space a function can use, there's a limit on how many TEST()s +// one can put in a single C++ test file. This test ensures that a large +// number of TEST()s can be defined in the same translation unit. + +#include "gtest/gtest.h" + +// This macro defines 10 dummy tests. +#define TEN_TESTS_(test_case_name) \ + TEST(test_case_name, T0) {} \ + TEST(test_case_name, T1) {} \ + TEST(test_case_name, T2) {} \ + TEST(test_case_name, T3) {} \ + TEST(test_case_name, T4) {} \ + TEST(test_case_name, T5) {} \ + TEST(test_case_name, T6) {} \ + TEST(test_case_name, T7) {} \ + TEST(test_case_name, T8) {} \ + TEST(test_case_name, T9) {} + +// This macro defines 100 dummy tests. +#define HUNDRED_TESTS_(test_case_name_prefix) \ + TEN_TESTS_(test_case_name_prefix ## 0) \ + TEN_TESTS_(test_case_name_prefix ## 1) \ + TEN_TESTS_(test_case_name_prefix ## 2) \ + TEN_TESTS_(test_case_name_prefix ## 3) \ + TEN_TESTS_(test_case_name_prefix ## 4) \ + TEN_TESTS_(test_case_name_prefix ## 5) \ + TEN_TESTS_(test_case_name_prefix ## 6) \ + TEN_TESTS_(test_case_name_prefix ## 7) \ + TEN_TESTS_(test_case_name_prefix ## 8) \ + TEN_TESTS_(test_case_name_prefix ## 9) + +// This macro defines 1000 dummy tests. +#define THOUSAND_TESTS_(test_case_name_prefix) \ + HUNDRED_TESTS_(test_case_name_prefix ## 0) \ + HUNDRED_TESTS_(test_case_name_prefix ## 1) \ + HUNDRED_TESTS_(test_case_name_prefix ## 2) \ + HUNDRED_TESTS_(test_case_name_prefix ## 3) \ + HUNDRED_TESTS_(test_case_name_prefix ## 4) \ + HUNDRED_TESTS_(test_case_name_prefix ## 5) \ + HUNDRED_TESTS_(test_case_name_prefix ## 6) \ + HUNDRED_TESTS_(test_case_name_prefix ## 7) \ + HUNDRED_TESTS_(test_case_name_prefix ## 8) \ + HUNDRED_TESTS_(test_case_name_prefix ## 9) + +// Ensures that we can define 1000 TEST()s in the same translation +// unit. +THOUSAND_TESTS_(T) + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + + // We don't actually need to run the dummy tests - the purpose is to + // ensure that they compile. + return 0; +}