mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-22 16:37:31 +09:00
re-introduce old nss im too tired for this
This commit is contained in:
parent
3c46be320d
commit
3a838106b9
2871 changed files with 1374431 additions and 1762417 deletions
|
|
@ -28,16 +28,28 @@
|
|||
# (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)
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
|
||||
load("@rules_python//python:defs.bzl", "py_library", "py_test")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
package(default_visibility = ["//:__subpackages__"])
|
||||
config_setting(
|
||||
name = "windows",
|
||||
values = {"cpu": "x64_windows"},
|
||||
)
|
||||
|
||||
#on windows exclude gtest-tuple.h
|
||||
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 googletest-tuple-test.cc
|
||||
cc_test(
|
||||
name = "gtest_all_test",
|
||||
size = "small",
|
||||
|
|
@ -50,43 +62,41 @@ cc_test(
|
|||
],
|
||||
exclude = [
|
||||
"gtest-unittest-api_test.cc",
|
||||
"googletest-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",
|
||||
"googletest-param-test-test.cc",
|
||||
"googletest-param-test2-test.cc",
|
||||
"googletest-catch-exceptions-test_.cc",
|
||||
"googletest-color-test_.cc",
|
||||
"googletest-env-var-test_.cc",
|
||||
"googletest-failfast-unittest_.cc",
|
||||
"googletest-filter-unittest_.cc",
|
||||
"googletest-global-environment-unittest_.cc",
|
||||
"googletest-break-on-failure-unittest_.cc",
|
||||
"googletest-listener-test.cc",
|
||||
"googletest-output-test_.cc",
|
||||
"googletest-list-tests-unittest_.cc",
|
||||
"googletest-shuffle-test_.cc",
|
||||
"googletest-setuptestsuite-test_.cc",
|
||||
"googletest-uninitialized-test_.cc",
|
||||
"googletest-death-test_ex_test.cc",
|
||||
"googletest-param-test-test",
|
||||
"googletest-throw-on-failure-test_.cc",
|
||||
"googletest-param-test-invalid-name1-test_.cc",
|
||||
"googletest-param-test-invalid-name2-test_.cc",
|
||||
"googletest-listener-test.cc",
|
||||
"googletest-output-test_.cc",
|
||||
"googletest-list-tests-unittest_.cc",
|
||||
"googletest-shuffle-test_.cc",
|
||||
"googletest-uninitialized-test_.cc",
|
||||
"googletest-death-test_ex_test.cc",
|
||||
"googletest-param-test-test",
|
||||
"googletest-throw-on-failure-test_.cc",
|
||||
"googletest-param-test-invalid-name1-test_.cc",
|
||||
"googletest-param-test-invalid-name2-test_.cc",
|
||||
|
||||
],
|
||||
) + select({
|
||||
"//:windows": [],
|
||||
"//conditions:default": [],
|
||||
"//:windows_msvc": [],
|
||||
"//conditions:default": [
|
||||
"googletest-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"],
|
||||
}) + select({
|
||||
# Ensure MSVC treats source files as UTF-8 encoded.
|
||||
"//:msvc_compiler": ["-utf-8"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"googletest",
|
||||
|
|
@ -96,11 +106,15 @@ cc_test(
|
|||
],
|
||||
linkopts = select({
|
||||
"//:windows": [],
|
||||
"//conditions:default": ["-pthread"],
|
||||
"//:windows_msvc": [],
|
||||
"//conditions:default": [
|
||||
"-pthread",
|
||||
],
|
||||
}),
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
|
||||
# Tests death tests.
|
||||
cc_test(
|
||||
name = "googletest-death-test-test",
|
||||
|
|
@ -150,6 +164,7 @@ cc_test(
|
|||
name = "gtest_unittest",
|
||||
size = "small",
|
||||
srcs = ["gtest_unittest.cc"],
|
||||
args = ["--heap_check=strict"],
|
||||
shard_count = 2,
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
|
@ -160,7 +175,6 @@ py_library(
|
|||
name = "gtest_test_utils",
|
||||
testonly = 1,
|
||||
srcs = ["gtest_test_utils.py"],
|
||||
imports = ["."],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
|
|
@ -185,12 +199,13 @@ cc_binary(
|
|||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
|
||||
py_test(
|
||||
name = "googletest-output-test",
|
||||
size = "small",
|
||||
srcs = ["googletest-output-test.py"],
|
||||
args = select({
|
||||
"//:has_absl": [],
|
||||
":has_absl": [],
|
||||
"//conditions:default": ["--no_stacktrace_support"],
|
||||
}),
|
||||
data = [
|
||||
|
|
@ -230,21 +245,6 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-failfast-unittest_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-failfast-unittest_.cc"],
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-failfast-unittest",
|
||||
size = "medium",
|
||||
srcs = ["googletest-failfast-unittest.py"],
|
||||
data = [":googletest-failfast-unittest_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-filter-unittest_",
|
||||
testonly = 1,
|
||||
|
|
@ -260,20 +260,6 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-global-environment-unittest_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-global-environment-unittest_.cc"],
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-global-environment-unittest",
|
||||
size = "medium",
|
||||
srcs = ["googletest-global-environment-unittest.py"],
|
||||
data = [":googletest-global-environment-unittest_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-break-on-failure-unittest_",
|
||||
|
|
@ -282,6 +268,8 @@ cc_binary(
|
|||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
py_test(
|
||||
name = "googletest-break-on-failure-unittest",
|
||||
size = "small",
|
||||
|
|
@ -290,6 +278,7 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
|
||||
cc_test(
|
||||
name = "gtest_assert_by_exception_test",
|
||||
size = "small",
|
||||
|
|
@ -297,6 +286,8 @@ cc_test(
|
|||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-throw-on-failure-test_",
|
||||
testonly = 1,
|
||||
|
|
@ -312,6 +303,7 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-list-tests-unittest_",
|
||||
testonly = 1,
|
||||
|
|
@ -319,38 +311,6 @@ cc_binary(
|
|||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "gtest_skip_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_test.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "gtest_skip_in_environment_setup_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_in_environment_setup_test.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "gtest_skip_check_output_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_check_output_test.py"],
|
||||
data = [":gtest_skip_test"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "gtest_skip_environment_check_output_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_environment_check_output_test.py"],
|
||||
data = [
|
||||
":gtest_skip_in_environment_setup_test",
|
||||
],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-list-tests-unittest",
|
||||
size = "small",
|
||||
|
|
@ -421,7 +381,7 @@ py_test(
|
|||
"gtest_xml_test_utils.py",
|
||||
],
|
||||
args = select({
|
||||
"//:has_absl": [],
|
||||
":has_absl": [],
|
||||
"//conditions:default": ["--no_stacktrace_support"],
|
||||
}),
|
||||
data = [
|
||||
|
|
@ -461,21 +421,6 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-setuptestsuite-test_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-setuptestsuite-test_.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-setuptestsuite-test",
|
||||
size = "medium",
|
||||
srcs = ["googletest-setuptestsuite-test.py"],
|
||||
data = [":googletest-setuptestsuite-test_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-uninitialized-test_",
|
||||
testonly = 1,
|
||||
|
|
@ -507,6 +452,7 @@ py_test(
|
|||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
|
||||
py_test(
|
||||
name = "googletest-json-outfiles-test",
|
||||
size = "small",
|
||||
|
|
@ -528,19 +474,18 @@ py_test(
|
|||
"googletest-json-output-unittest.py",
|
||||
"gtest_json_test_utils.py",
|
||||
],
|
||||
args = select({
|
||||
"//:has_absl": [],
|
||||
"//conditions:default": ["--no_stacktrace_support"],
|
||||
}),
|
||||
data = [
|
||||
# We invoke gtest_no_test_unittest to verify the JSON output
|
||||
# when the test program contains no test definition.
|
||||
":gtest_no_test_unittest",
|
||||
":gtest_xml_output_unittest_",
|
||||
],
|
||||
args = select({
|
||||
":has_absl": [],
|
||||
"//conditions:default": ["--no_stacktrace_support"],
|
||||
}),
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
# Verifies interaction of death tests and exceptions.
|
||||
cc_test(
|
||||
name = "googletest-death-test_ex_catch_test",
|
||||
|
|
@ -570,10 +515,6 @@ py_test(
|
|||
size = "small",
|
||||
srcs = ["googletest-param-test-invalid-name1-test.py"],
|
||||
data = [":googletest-param-test-invalid-name1-test_"],
|
||||
tags = [
|
||||
"no_test_msvc2015",
|
||||
"no_test_msvc2017",
|
||||
],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
|
|
@ -582,9 +523,5 @@ py_test(
|
|||
size = "small",
|
||||
srcs = ["googletest-param-test-invalid-name2-test.py"],
|
||||
data = [":googletest-param-test-invalid-name2-test_"],
|
||||
tags = [
|
||||
"no_test_msvc2015",
|
||||
"no_test_msvc2017",
|
||||
],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class GTestBreakOnFailureUnitTest(gtest_test_utils.TestCase):
|
|||
msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' %
|
||||
(BREAK_ON_FAILURE_ENV_VAR, env_var_value_msg, ' '.join(command),
|
||||
should_or_not))
|
||||
self.assertTrue(has_seg_fault == expect_seg_fault, msg)
|
||||
self.assert_(has_seg_fault == expect_seg_fault, msg)
|
||||
|
||||
def testDefaultBehavior(self):
|
||||
"""Tests the behavior of the default mode."""
|
||||
|
|
|
|||
|
|
@ -83,21 +83,21 @@ if SUPPORTS_SEH_EXCEPTIONS:
|
|||
|
||||
|
||||
def TestSehExceptions(self, test_output):
|
||||
self.assertTrue('SEH exception with code 0x2a thrown '
|
||||
self.assert_('SEH exception with code 0x2a thrown '
|
||||
'in the test fixture\'s constructor'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown '
|
||||
self.assert_('SEH exception with code 0x2a thrown '
|
||||
'in the test fixture\'s destructor'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown in SetUpTestSuite()'
|
||||
self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown in TearDownTestSuite()'
|
||||
self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown in SetUp()'
|
||||
self.assert_('SEH exception with code 0x2a thrown in SetUp()'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown in TearDown()'
|
||||
self.assert_('SEH exception with code 0x2a thrown in TearDown()'
|
||||
in test_output)
|
||||
self.assertTrue('SEH exception with code 0x2a thrown in the test body'
|
||||
self.assert_('SEH exception with code 0x2a thrown in the test body'
|
||||
in test_output)
|
||||
|
||||
def testCatchesSehExceptionsWithCxxExceptionsEnabled(self):
|
||||
|
|
@ -117,12 +117,11 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||
"""
|
||||
|
||||
def testCatchesCxxExceptionsInFixtureConstructor(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description '
|
||||
'"Standard C++ exception" thrown '
|
||||
'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
|
||||
EX_BINARY_OUTPUT)
|
||||
self.assertTrue('unexpected' not in EX_BINARY_OUTPUT,
|
||||
self.assert_('C++ exception with description '
|
||||
'"Standard C++ exception" thrown '
|
||||
'in the test fixture\'s constructor'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
|
||||
'This failure belongs in this test only if '
|
||||
'"CxxExceptionInConstructorTest" (no quotes) '
|
||||
'appears on the same line as words "called unexpectedly"')
|
||||
|
|
@ -131,90 +130,88 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||
EX_BINARY_OUTPUT):
|
||||
|
||||
def testCatchesCxxExceptionsInFixtureDestructor(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description '
|
||||
'"Standard C++ exception" thrown '
|
||||
'in the test fixture\'s destructor' in EX_BINARY_OUTPUT,
|
||||
EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInDestructorTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assert_('C++ exception with description '
|
||||
'"Standard C++ exception" thrown '
|
||||
'in the test fixture\'s destructor'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description "Standard C++ exception"'
|
||||
' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInConstructorTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTestSuiteTest constructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTestSuiteTest destructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTestSuiteTest::SetUp() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTestSuiteTest::TearDown() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTestSuiteTest test body '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in SetUpTestCase()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTestCaseTest constructor '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTestCaseTest destructor '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTestCaseTest test body '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description "Standard C++ exception"'
|
||||
' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in TearDownTestCase()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesCxxExceptionsInSetUp(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description "Standard C++ exception"'
|
||||
' thrown in SetUp()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTest destructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInSetUpTest::TearDown() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue('unexpected' not in EX_BINARY_OUTPUT,
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in SetUp()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTest destructor '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInSetUpTest::TearDown() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('unexpected' not in EX_BINARY_OUTPUT,
|
||||
'This failure belongs in this test only if '
|
||||
'"CxxExceptionInSetUpTest" (no quotes) '
|
||||
'appears on the same line as words "called unexpectedly"')
|
||||
|
||||
def testCatchesCxxExceptionsInTearDown(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description "Standard C++ exception"'
|
||||
' thrown in TearDown()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInTearDownTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInTearDownTest destructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in TearDown()'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInTearDownTest destructor '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesCxxExceptionsInTestBody(self):
|
||||
self.assertTrue(
|
||||
'C++ exception with description "Standard C++ exception"'
|
||||
' thrown in the test body' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInTestBodyTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInTestBodyTest destructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
'CxxExceptionInTestBodyTest::TearDown() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||
' thrown in the test body'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInTestBodyTest destructor '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
self.assert_('CxxExceptionInTestBodyTest::TearDown() '
|
||||
'called as expected.'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testCatchesNonStdCxxExceptions(self):
|
||||
self.assertTrue(
|
||||
'Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT,
|
||||
EX_BINARY_OUTPUT)
|
||||
self.assert_('Unknown C++ exception thrown in the test body'
|
||||
in EX_BINARY_OUTPUT)
|
||||
|
||||
def testUnhandledCxxExceptionsAbortTheProgram(self):
|
||||
# Filters out SEH exception tests on Windows. Unhandled SEH exceptions
|
||||
|
|
@ -227,9 +224,9 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||
FITLER_OUT_SEH_TESTS_FLAG],
|
||||
env=environ).output
|
||||
|
||||
self.assertTrue('Unhandled C++ exception terminating the program'
|
||||
self.assert_('Unhandled C++ exception terminating the program'
|
||||
in uncaught_exceptions_ex_binary_output)
|
||||
self.assertTrue('unexpected' not in uncaught_exceptions_ex_binary_output)
|
||||
self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -64,20 +64,19 @@ class SehExceptionInDestructorTest : public Test {
|
|||
|
||||
TEST_F(SehExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
|
||||
|
||||
class SehExceptionInSetUpTestSuiteTest : public Test {
|
||||
class SehExceptionInSetUpTestCaseTest : public Test {
|
||||
public:
|
||||
static void SetUpTestSuite() { RaiseException(42, 0, 0, NULL); }
|
||||
static void SetUpTestCase() { RaiseException(42, 0, 0, NULL); }
|
||||
};
|
||||
|
||||
TEST_F(SehExceptionInSetUpTestSuiteTest, ThrowsExceptionInSetUpTestSuite) {}
|
||||
TEST_F(SehExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) {}
|
||||
|
||||
class SehExceptionInTearDownTestSuiteTest : public Test {
|
||||
class SehExceptionInTearDownTestCaseTest : public Test {
|
||||
public:
|
||||
static void TearDownTestSuite() { RaiseException(42, 0, 0, NULL); }
|
||||
static void TearDownTestCase() { RaiseException(42, 0, 0, NULL); }
|
||||
};
|
||||
|
||||
TEST_F(SehExceptionInTearDownTestSuiteTest,
|
||||
ThrowsExceptionInTearDownTestSuite) {}
|
||||
TEST_F(SehExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {}
|
||||
|
||||
class SehExceptionInSetUpTest : public Test {
|
||||
protected:
|
||||
|
|
@ -110,24 +109,24 @@ class CxxExceptionInConstructorTest : public Test {
|
|||
throw std::runtime_error("Standard C++ exception"));
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInConstructorTest::TearDownTestSuite() "
|
||||
"CxxExceptionInConstructorTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
protected:
|
||||
~CxxExceptionInConstructorTest() override {
|
||||
~CxxExceptionInConstructorTest() {
|
||||
ADD_FAILURE() << "CxxExceptionInConstructorTest destructor "
|
||||
<< "called unexpectedly.";
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
ADD_FAILURE() << "CxxExceptionInConstructorTest::SetUp() "
|
||||
<< "called unexpectedly.";
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
ADD_FAILURE() << "CxxExceptionInConstructorTest::TearDown() "
|
||||
<< "called unexpectedly.";
|
||||
}
|
||||
|
|
@ -138,78 +137,97 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
|
|||
<< "called unexpectedly.";
|
||||
}
|
||||
|
||||
class CxxExceptionInSetUpTestSuiteTest : public Test {
|
||||
// Exceptions in destructors are not supported in C++11.
|
||||
#if !GTEST_LANG_CXX11
|
||||
class CxxExceptionInDestructorTest : public Test {
|
||||
public:
|
||||
CxxExceptionInSetUpTestSuiteTest() {
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest constructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
throw std::runtime_error("Standard C++ exception");
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest::TearDownTestSuite() "
|
||||
"CxxExceptionInDestructorTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
protected:
|
||||
~CxxExceptionInSetUpTestSuiteTest() override {
|
||||
~CxxExceptionInDestructorTest() {
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
|
||||
throw std::runtime_error("Standard C++ exception"));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(CxxExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
|
||||
#endif // C++11 mode
|
||||
|
||||
class CxxExceptionInSetUpTestCaseTest : public Test {
|
||||
public:
|
||||
CxxExceptionInSetUpTestCaseTest() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest destructor "
|
||||
"CxxExceptionInSetUpTestCaseTest constructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
static void SetUpTestCase() {
|
||||
throw std::runtime_error("Standard C++ exception");
|
||||
}
|
||||
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest::SetUp() "
|
||||
"CxxExceptionInSetUpTestCaseTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
protected:
|
||||
~CxxExceptionInSetUpTestCaseTest() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest::TearDown() "
|
||||
"CxxExceptionInSetUpTestCaseTest destructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestCaseTest::SetUp() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestCaseTest::TearDown() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(CxxExceptionInSetUpTestSuiteTest, ThrowsExceptionInSetUpTestSuite) {
|
||||
TEST_F(CxxExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTestSuiteTest test body "
|
||||
"CxxExceptionInSetUpTestCaseTest test body "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
class CxxExceptionInTearDownTestSuiteTest : public Test {
|
||||
class CxxExceptionInTearDownTestCaseTest : public Test {
|
||||
public:
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
throw std::runtime_error("Standard C++ exception");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(CxxExceptionInTearDownTestSuiteTest,
|
||||
ThrowsExceptionInTearDownTestSuite) {}
|
||||
TEST_F(CxxExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {}
|
||||
|
||||
class CxxExceptionInSetUpTest : public Test {
|
||||
public:
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTest::TearDownTestSuite() "
|
||||
"CxxExceptionInSetUpTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
protected:
|
||||
~CxxExceptionInSetUpTest() override {
|
||||
~CxxExceptionInSetUpTest() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTest destructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
void SetUp() override { throw std::runtime_error("Standard C++ exception"); }
|
||||
virtual void SetUp() { throw std::runtime_error("Standard C++ exception"); }
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
printf("%s",
|
||||
"CxxExceptionInSetUpTest::TearDown() "
|
||||
"called as expected.\n");
|
||||
|
|
@ -223,20 +241,20 @@ TEST_F(CxxExceptionInSetUpTest, ThrowsExceptionInSetUp) {
|
|||
|
||||
class CxxExceptionInTearDownTest : public Test {
|
||||
public:
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInTearDownTest::TearDownTestSuite() "
|
||||
"CxxExceptionInTearDownTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
protected:
|
||||
~CxxExceptionInTearDownTest() override {
|
||||
~CxxExceptionInTearDownTest() {
|
||||
printf("%s",
|
||||
"CxxExceptionInTearDownTest destructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
throw std::runtime_error("Standard C++ exception");
|
||||
}
|
||||
};
|
||||
|
|
@ -245,20 +263,20 @@ TEST_F(CxxExceptionInTearDownTest, ThrowsExceptionInTearDown) {}
|
|||
|
||||
class CxxExceptionInTestBodyTest : public Test {
|
||||
public:
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
printf("%s",
|
||||
"CxxExceptionInTestBodyTest::TearDownTestSuite() "
|
||||
"CxxExceptionInTestBodyTest::TearDownTestCase() "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
protected:
|
||||
~CxxExceptionInTestBodyTest() override {
|
||||
~CxxExceptionInTestBodyTest() {
|
||||
printf("%s",
|
||||
"CxxExceptionInTestBodyTest destructor "
|
||||
"called as expected.\n");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
printf("%s",
|
||||
"CxxExceptionInTestBodyTest::TearDown() "
|
||||
"called as expected.\n");
|
||||
|
|
@ -278,7 +296,7 @@ TEST(CxxExceptionTest, ThrowsNonStdCxxException) {
|
|||
// ones.
|
||||
void TerminateHandler() {
|
||||
fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program.");
|
||||
fflush(nullptr);
|
||||
fflush(NULL);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,58 +69,58 @@ class GTestColorTest(gtest_test_utils.TestCase):
|
|||
"""Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
|
||||
|
||||
if not IS_WINDOWS:
|
||||
self.assertTrue(not UsesColor('dumb', None, None))
|
||||
self.assertTrue(not UsesColor('emacs', None, None))
|
||||
self.assertTrue(not UsesColor('xterm-mono', None, None))
|
||||
self.assertTrue(not UsesColor('unknown', None, None))
|
||||
self.assertTrue(not UsesColor(None, None, None))
|
||||
self.assertTrue(UsesColor('linux', None, None))
|
||||
self.assertTrue(UsesColor('cygwin', None, None))
|
||||
self.assertTrue(UsesColor('xterm', None, None))
|
||||
self.assertTrue(UsesColor('xterm-color', None, None))
|
||||
self.assertTrue(UsesColor('xterm-256color', None, None))
|
||||
self.assert_(not UsesColor('dumb', None, None))
|
||||
self.assert_(not UsesColor('emacs', None, None))
|
||||
self.assert_(not UsesColor('xterm-mono', None, None))
|
||||
self.assert_(not UsesColor('unknown', None, None))
|
||||
self.assert_(not UsesColor(None, None, None))
|
||||
self.assert_(UsesColor('linux', None, None))
|
||||
self.assert_(UsesColor('cygwin', None, None))
|
||||
self.assert_(UsesColor('xterm', None, None))
|
||||
self.assert_(UsesColor('xterm-color', None, None))
|
||||
self.assert_(UsesColor('xterm-256color', None, None))
|
||||
|
||||
def testFlagOnly(self):
|
||||
"""Tests the case when there's --gtest_color but not GTEST_COLOR."""
|
||||
|
||||
self.assertTrue(not UsesColor('dumb', None, 'no'))
|
||||
self.assertTrue(not UsesColor('xterm-color', None, 'no'))
|
||||
self.assert_(not UsesColor('dumb', None, 'no'))
|
||||
self.assert_(not UsesColor('xterm-color', None, 'no'))
|
||||
if not IS_WINDOWS:
|
||||
self.assertTrue(not UsesColor('emacs', None, 'auto'))
|
||||
self.assertTrue(UsesColor('xterm', None, 'auto'))
|
||||
self.assertTrue(UsesColor('dumb', None, 'yes'))
|
||||
self.assertTrue(UsesColor('xterm', None, 'yes'))
|
||||
self.assert_(not UsesColor('emacs', None, 'auto'))
|
||||
self.assert_(UsesColor('xterm', None, 'auto'))
|
||||
self.assert_(UsesColor('dumb', None, 'yes'))
|
||||
self.assert_(UsesColor('xterm', None, 'yes'))
|
||||
|
||||
def testEnvVarOnly(self):
|
||||
"""Tests the case when there's GTEST_COLOR but not --gtest_color."""
|
||||
|
||||
self.assertTrue(not UsesColor('dumb', 'no', None))
|
||||
self.assertTrue(not UsesColor('xterm-color', 'no', None))
|
||||
self.assert_(not UsesColor('dumb', 'no', None))
|
||||
self.assert_(not UsesColor('xterm-color', 'no', None))
|
||||
if not IS_WINDOWS:
|
||||
self.assertTrue(not UsesColor('dumb', 'auto', None))
|
||||
self.assertTrue(UsesColor('xterm-color', 'auto', None))
|
||||
self.assertTrue(UsesColor('dumb', 'yes', None))
|
||||
self.assertTrue(UsesColor('xterm-color', 'yes', None))
|
||||
self.assert_(not UsesColor('dumb', 'auto', None))
|
||||
self.assert_(UsesColor('xterm-color', 'auto', None))
|
||||
self.assert_(UsesColor('dumb', 'yes', None))
|
||||
self.assert_(UsesColor('xterm-color', 'yes', None))
|
||||
|
||||
def testEnvVarAndFlag(self):
|
||||
"""Tests the case when there are both GTEST_COLOR and --gtest_color."""
|
||||
|
||||
self.assertTrue(not UsesColor('xterm-color', 'no', 'no'))
|
||||
self.assertTrue(UsesColor('dumb', 'no', 'yes'))
|
||||
self.assertTrue(UsesColor('xterm-color', 'no', 'auto'))
|
||||
self.assert_(not UsesColor('xterm-color', 'no', 'no'))
|
||||
self.assert_(UsesColor('dumb', 'no', 'yes'))
|
||||
self.assert_(UsesColor('xterm-color', 'no', 'auto'))
|
||||
|
||||
def testAliasesOfYesAndNo(self):
|
||||
"""Tests using aliases in specifying --gtest_color."""
|
||||
|
||||
self.assertTrue(UsesColor('dumb', None, 'true'))
|
||||
self.assertTrue(UsesColor('dumb', None, 'YES'))
|
||||
self.assertTrue(UsesColor('dumb', None, 'T'))
|
||||
self.assertTrue(UsesColor('dumb', None, '1'))
|
||||
self.assert_(UsesColor('dumb', None, 'true'))
|
||||
self.assert_(UsesColor('dumb', None, 'YES'))
|
||||
self.assert_(UsesColor('dumb', None, 'T'))
|
||||
self.assert_(UsesColor('dumb', None, '1'))
|
||||
|
||||
self.assertTrue(not UsesColor('xterm', None, 'f'))
|
||||
self.assertTrue(not UsesColor('xterm', None, 'false'))
|
||||
self.assertTrue(not UsesColor('xterm', None, '0'))
|
||||
self.assertTrue(not UsesColor('xterm', None, 'unknown'))
|
||||
self.assert_(not UsesColor('xterm', None, 'f'))
|
||||
self.assert_(not UsesColor('xterm', None, 'false'))
|
||||
self.assert_(not UsesColor('xterm', None, '0'))
|
||||
self.assert_(not UsesColor('xterm', None, 'unknown'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
// Tests for death tests.
|
||||
|
||||
#include "gtest/gtest-death-test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
|
||||
|
|
@ -41,9 +40,7 @@ using testing::internal::AlwaysTrue;
|
|||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
# include <fcntl.h> // For O_BINARY
|
||||
# include <direct.h> // For chdir().
|
||||
# include <io.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# include <sys/wait.h> // For waitpid.
|
||||
|
|
@ -62,8 +59,6 @@ using testing::internal::AlwaysTrue;
|
|||
|
||||
namespace posix = ::testing::internal::posix;
|
||||
|
||||
using testing::ContainsRegex;
|
||||
using testing::Matcher;
|
||||
using testing::Message;
|
||||
using testing::internal::DeathTest;
|
||||
using testing::internal::DeathTestFactory;
|
||||
|
|
@ -102,8 +97,6 @@ class ReplaceDeathTestFactory {
|
|||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
namespace {
|
||||
|
||||
void DieWithMessage(const ::std::string& message) {
|
||||
fprintf(stderr, "%s", message.c_str());
|
||||
fflush(stderr); // Make sure the text is printed before the process exits.
|
||||
|
|
@ -130,7 +123,9 @@ class TestForDeathTest : public testing::Test {
|
|||
protected:
|
||||
TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
|
||||
|
||||
~TestForDeathTest() override { posix::ChDir(original_dir_.c_str()); }
|
||||
virtual ~TestForDeathTest() {
|
||||
posix::ChDir(original_dir_.c_str());
|
||||
}
|
||||
|
||||
// A static member function that's expected to die.
|
||||
static void StaticMemberFunction() { DieInside("StaticMemberFunction"); }
|
||||
|
|
@ -141,7 +136,7 @@ class TestForDeathTest : public testing::Test {
|
|||
DieInside("MemberFunction");
|
||||
}
|
||||
|
||||
// True if and only if MemberFunction() should die.
|
||||
// True iff MemberFunction() should die.
|
||||
bool should_die_;
|
||||
const FilePath original_dir_;
|
||||
};
|
||||
|
|
@ -158,7 +153,7 @@ class MayDie {
|
|||
}
|
||||
|
||||
private:
|
||||
// True if and only if MemberFunction() should die.
|
||||
// True iff MemberFunction() should die.
|
||||
bool should_die_;
|
||||
};
|
||||
|
||||
|
|
@ -204,26 +199,6 @@ int DieInDebugElse12(int* sideeffect) {
|
|||
return 12;
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Death in dbg due to Windows CRT assertion failure, not opt.
|
||||
int DieInCRTDebugElse12(int* sideeffect) {
|
||||
if (sideeffect) *sideeffect = 12;
|
||||
|
||||
// Create an invalid fd by closing a valid one
|
||||
int fdpipe[2];
|
||||
EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
|
||||
EXPECT_EQ(_close(fdpipe[0]), 0);
|
||||
EXPECT_EQ(_close(fdpipe[1]), 0);
|
||||
|
||||
// _dup() should crash in debug mode
|
||||
EXPECT_EQ(_dup(fdpipe[0]), -1);
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// Tests the ExitedWithCode predicate.
|
||||
|
|
@ -298,13 +273,6 @@ TEST(ExitStatusPredicateTest, KilledBySignal) {
|
|||
|
||||
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
|
|
@ -328,11 +296,6 @@ TEST_F(TestForDeathTest, SingleStatement) {
|
|||
else
|
||||
EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
# if GTEST_USES_PCRE
|
||||
|
||||
void DieWithEmbeddedNul() {
|
||||
fprintf(stderr, "Hello%cmy null world.\n", '\0');
|
||||
|
|
@ -340,6 +303,8 @@ void DieWithEmbeddedNul() {
|
|||
_exit(1);
|
||||
}
|
||||
|
||||
# if GTEST_USES_PCRE
|
||||
|
||||
// Tests that EXPECT_DEATH and ASSERT_DEATH work when the error
|
||||
// message has a NUL character in it.
|
||||
TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
|
||||
|
|
@ -401,19 +366,17 @@ void SigprofAction(int, siginfo_t*, void*) { /* no op */ }
|
|||
|
||||
// Sets SIGPROF action and ITIMER_PROF timer (interval: 1ms).
|
||||
void SetSigprofActionAndTimer() {
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
|
||||
struct sigaction signal_action;
|
||||
memset(&signal_action, 0, sizeof(signal_action));
|
||||
sigemptyset(&signal_action.sa_mask);
|
||||
signal_action.sa_sigaction = SigprofAction;
|
||||
signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr));
|
||||
// timer comes second, to avoid SIGPROF premature delivery, as suggested at
|
||||
// https://www.gnu.org/software/libc/manual/html_node/Setting-an-Alarm.html
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, NULL));
|
||||
}
|
||||
|
||||
// Disables ITIMER_PROF timer and ignores SIGPROF signal.
|
||||
|
|
@ -422,7 +385,7 @@ void DisableSigprofActionAndTimer(struct sigaction* old_signal_action) {
|
|||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 0;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
|
||||
struct sigaction signal_action;
|
||||
memset(&signal_action, 0, sizeof(signal_action));
|
||||
sigemptyset(&signal_action.sa_mask);
|
||||
|
|
@ -489,17 +452,21 @@ TEST_F(TestForDeathTest, MixedStyles) {
|
|||
|
||||
# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
|
||||
|
||||
namespace {
|
||||
|
||||
bool pthread_flag;
|
||||
|
||||
void SetPthreadFlag() {
|
||||
pthread_flag = true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
|
||||
if (!testing::GTEST_FLAG(death_test_use_fork)) {
|
||||
testing::GTEST_FLAG(death_test_style) = "threadsafe";
|
||||
pthread_flag = false;
|
||||
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, nullptr, nullptr));
|
||||
ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, NULL, NULL));
|
||||
ASSERT_DEATH(_exit(1), "");
|
||||
ASSERT_FALSE(pthread_flag);
|
||||
}
|
||||
|
|
@ -527,15 +494,18 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
|
|||
const testing::internal::RE regex(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex);
|
||||
|
||||
# if GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
const ::string regex_str(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex_str);
|
||||
|
||||
# endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
# if !GTEST_USES_PCRE
|
||||
|
||||
const ::std::string regex_std_str(regex_c_str);
|
||||
EXPECT_DEATH(GlobalFunction(), regex_std_str);
|
||||
|
||||
// This one is tricky; a temporary pointer into another temporary. Reference
|
||||
// lifetime extension of the pointer is not sufficient.
|
||||
EXPECT_DEATH(GlobalFunction(), ::std::string(regex_c_str).c_str());
|
||||
|
||||
# endif // !GTEST_USES_PCRE
|
||||
}
|
||||
|
||||
|
|
@ -585,8 +555,8 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) {
|
|||
}, "died but not with expected error");
|
||||
}
|
||||
|
||||
// On exit, *aborted will be true if and only if the EXPECT_DEATH()
|
||||
// statement aborted the function.
|
||||
// On exit, *aborted will be true iff the EXPECT_DEATH() statement
|
||||
// aborted the function.
|
||||
void ExpectDeathTestHelper(bool* aborted) {
|
||||
*aborted = true;
|
||||
EXPECT_DEATH(DieIf(false), "DieIf"); // This assertion should fail.
|
||||
|
|
@ -666,40 +636,6 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
|
|||
# endif
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that EXPECT_DEBUG_DEATH works as expected when in debug mode
|
||||
// the Windows CRT crashes the process with an assertion failure.
|
||||
// 1. Asserts on death.
|
||||
// 2. Has no side effect (doesn't pop up a window or wait for user input).
|
||||
//
|
||||
// And in opt mode, it:
|
||||
// 1. Has side effects but does not assert.
|
||||
TEST_F(TestForDeathTest, CRTDebugDeath) {
|
||||
int sideeffect = 0;
|
||||
|
||||
// Put the regex in a local variable to make sure we don't get an "unused"
|
||||
// warning in opt mode.
|
||||
const char* regex = "dup.* : Assertion failed";
|
||||
|
||||
EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
|
||||
<< "Must accept a streamed message";
|
||||
|
||||
# ifdef NDEBUG
|
||||
|
||||
// Checks that the assignment occurs in opt mode (sideeffect).
|
||||
EXPECT_EQ(12, sideeffect);
|
||||
|
||||
# else
|
||||
|
||||
// Checks that the assignment does not occur in dbg mode (no sideeffect).
|
||||
EXPECT_EQ(0, sideeffect);
|
||||
|
||||
# endif
|
||||
}
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
|
||||
// message to it, and in debug mode it:
|
||||
// 1. Asserts on death.
|
||||
|
|
@ -940,9 +876,9 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
|
|||
class MockDeathTestFactory : public DeathTestFactory {
|
||||
public:
|
||||
MockDeathTestFactory();
|
||||
bool Create(const char* statement,
|
||||
testing::Matcher<const std::string&> matcher, const char* file,
|
||||
int line, DeathTest** test) override;
|
||||
virtual bool Create(const char* statement,
|
||||
const ::testing::internal::RE* regex,
|
||||
const char* file, int line, DeathTest** test);
|
||||
|
||||
// Sets the parameters for subsequent calls to Create.
|
||||
void SetParameters(bool create, DeathTest::TestRole role,
|
||||
|
|
@ -952,12 +888,10 @@ class MockDeathTestFactory : public DeathTestFactory {
|
|||
int AssumeRoleCalls() const { return assume_role_calls_; }
|
||||
int WaitCalls() const { return wait_calls_; }
|
||||
size_t PassedCalls() const { return passed_args_.size(); }
|
||||
bool PassedArgument(int n) const {
|
||||
return passed_args_[static_cast<size_t>(n)];
|
||||
}
|
||||
bool PassedArgument(int n) const { return passed_args_[n]; }
|
||||
size_t AbortCalls() const { return abort_args_.size(); }
|
||||
DeathTest::AbortReason AbortArgument(int n) const {
|
||||
return abort_args_[static_cast<size_t>(n)];
|
||||
return abort_args_[n];
|
||||
}
|
||||
bool TestDeleted() const { return test_deleted_; }
|
||||
|
||||
|
|
@ -999,20 +933,22 @@ class MockDeathTest : public DeathTest {
|
|||
TestRole role, int status, bool passed) :
|
||||
parent_(parent), role_(role), status_(status), passed_(passed) {
|
||||
}
|
||||
~MockDeathTest() override { parent_->test_deleted_ = true; }
|
||||
TestRole AssumeRole() override {
|
||||
virtual ~MockDeathTest() {
|
||||
parent_->test_deleted_ = true;
|
||||
}
|
||||
virtual TestRole AssumeRole() {
|
||||
++parent_->assume_role_calls_;
|
||||
return role_;
|
||||
}
|
||||
int Wait() override {
|
||||
virtual int Wait() {
|
||||
++parent_->wait_calls_;
|
||||
return status_;
|
||||
}
|
||||
bool Passed(bool exit_status_ok) override {
|
||||
virtual bool Passed(bool exit_status_ok) {
|
||||
parent_->passed_args_.push_back(exit_status_ok);
|
||||
return passed_;
|
||||
}
|
||||
void Abort(AbortReason reason) override {
|
||||
virtual void Abort(AbortReason reason) {
|
||||
parent_->abort_args_.push_back(reason);
|
||||
}
|
||||
|
||||
|
|
@ -1056,14 +992,16 @@ void MockDeathTestFactory::SetParameters(bool create,
|
|||
// Sets test to NULL (if create_ is false) or to the address of a new
|
||||
// MockDeathTest object with parameters taken from the last call
|
||||
// to SetParameters (if create_ is true). Always returns true.
|
||||
bool MockDeathTestFactory::Create(
|
||||
const char* /*statement*/, testing::Matcher<const std::string&> /*matcher*/,
|
||||
const char* /*file*/, int /*line*/, DeathTest** test) {
|
||||
bool MockDeathTestFactory::Create(const char* /*statement*/,
|
||||
const ::testing::internal::RE* /*regex*/,
|
||||
const char* /*file*/,
|
||||
int /*line*/,
|
||||
DeathTest** test) {
|
||||
test_deleted_ = false;
|
||||
if (create_) {
|
||||
*test = new MockDeathTest(this, role_, status_, passed_);
|
||||
} else {
|
||||
*test = nullptr;
|
||||
*test = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1076,16 +1014,16 @@ class MacroLogicDeathTest : public testing::Test {
|
|||
static testing::internal::ReplaceDeathTestFactory* replacer_;
|
||||
static MockDeathTestFactory* factory_;
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
static void SetUpTestCase() {
|
||||
factory_ = new MockDeathTestFactory;
|
||||
replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
delete replacer_;
|
||||
replacer_ = nullptr;
|
||||
replacer_ = NULL;
|
||||
delete factory_;
|
||||
factory_ = nullptr;
|
||||
factory_ = NULL;
|
||||
}
|
||||
|
||||
// Runs a death test that breaks the rules by returning. Such a death
|
||||
|
|
@ -1099,9 +1037,10 @@ class MacroLogicDeathTest : public testing::Test {
|
|||
}
|
||||
};
|
||||
|
||||
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
|
||||
nullptr;
|
||||
MockDeathTestFactory* MacroLogicDeathTest::factory_ = nullptr;
|
||||
testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_
|
||||
= NULL;
|
||||
MockDeathTestFactory* MacroLogicDeathTest::factory_ = NULL;
|
||||
|
||||
|
||||
// Test that nothing happens when the factory doesn't return a DeathTest:
|
||||
TEST_F(MacroLogicDeathTest, NothingHappens) {
|
||||
|
|
@ -1340,6 +1279,9 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
|
|||
|
||||
# if GTEST_OS_WINDOWS
|
||||
TEST(EnvironmentTest, HandleFitsIntoSizeT) {
|
||||
// FIXME: Remove this test after this condition is verified
|
||||
// in a static assertion in gtest-death-test.cc in the function
|
||||
// GetStatusFileDescriptor.
|
||||
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
|
||||
}
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
|
@ -1377,53 +1319,8 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
|
|||
}, "Inside");
|
||||
}
|
||||
|
||||
void DieWithMessage(const char* message) {
|
||||
fputs(message, stderr);
|
||||
fflush(stderr); // Make sure the text is printed before the process exits.
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
|
||||
// googletest tests this, of course; here we ensure that including googlemock
|
||||
// has not broken it.
|
||||
#if GTEST_USES_POSIX_RE
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
|
||||
#else
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
|
||||
EXPECT_DEATH(DieWithMessage("Behind O, I am slain!"),
|
||||
Matcher<const std::string&>(ContainsRegex("I am slain")));
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_DEATH(
|
||||
DieWithMessage("Behind O, I am slain!"),
|
||||
Matcher<const std::string&>(ContainsRegex("Ow, I am slain"))),
|
||||
"Expected: contains regular expression \"Ow, I am slain\"");
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
|
||||
EXPECT_DEATH(DieWithMessage("The rest is silence."),
|
||||
ContainsRegex("rest is silence"));
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
|
||||
EXPECT_NONFATAL_FAILURE(
|
||||
EXPECT_DEATH(DieWithMessage("The rest is silence."),
|
||||
ContainsRegex("rest is science")),
|
||||
"Expected: contains regular expression \"rest is science\"");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#else // !GTEST_HAS_DEATH_TEST follows
|
||||
|
||||
namespace {
|
||||
|
||||
using testing::internal::CaptureStderr;
|
||||
using testing::internal::GetCapturedStderr;
|
||||
|
||||
|
|
@ -1472,19 +1369,8 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
|
|||
EXPECT_EQ(1, n);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // !GTEST_HAS_DEATH_TEST
|
||||
|
||||
namespace {
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
|
|
@ -1510,9 +1396,6 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
|
|||
else
|
||||
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// Tests that conditional death test macros expand to code which interacts
|
||||
// well with switch statements.
|
||||
|
|
@ -1538,5 +1421,3 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
|
|||
TEST(NotADeathTest, Test) {
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ TEST(CxxExceptionDeathTest, ExceptionIsFailure) {
|
|||
|
||||
class TestException : public std::exception {
|
||||
public:
|
||||
const char* what() const noexcept override { return "exceptional message"; }
|
||||
virtual const char* what() const throw() { return "exceptional message"; }
|
||||
};
|
||||
|
||||
TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) {
|
||||
|
|
@ -68,7 +68,7 @@ TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) {
|
|||
"exceptional message");
|
||||
// Verifies that the location is mentioned in the failure text.
|
||||
EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""),
|
||||
__FILE__);
|
||||
"googletest-death-test_ex_test.cc");
|
||||
}
|
||||
# endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ environ = os.environ.copy()
|
|||
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -85,12 +85,9 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
|||
|
||||
TestFlag('break_on_failure', '1', '0')
|
||||
TestFlag('color', 'yes', 'auto')
|
||||
SetEnvVar('TESTBRIDGE_TEST_RUNNER_FAIL_FAST', None) # For 'fail_fast' test
|
||||
TestFlag('fail_fast', '1', '0')
|
||||
TestFlag('filter', 'FooTest.Bar', '*')
|
||||
SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test
|
||||
TestFlag('output', 'xml:tmp/foo.xml', '')
|
||||
TestFlag('brief', '1', '0')
|
||||
TestFlag('print_time', '0', '1')
|
||||
TestFlag('repeat', '999', '1')
|
||||
TestFlag('throw_on_failure', '1', '0')
|
||||
|
|
|
|||
|
|
@ -72,11 +72,6 @@ void PrintFlag(const char* flag) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "fail_fast") == 0) {
|
||||
cout << GTEST_FLAG(fail_fast);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "filter") == 0) {
|
||||
cout << GTEST_FLAG(filter);
|
||||
return;
|
||||
|
|
@ -87,11 +82,6 @@ void PrintFlag(const char* flag) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "brief") == 0) {
|
||||
cout << GTEST_FLAG(brief);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "print_time") == 0) {
|
||||
cout << GTEST_FLAG(print_time);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,410 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2020 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.
|
||||
|
||||
"""Unit test for Google Test fail_fast.
|
||||
|
||||
A user can specify if a Google Test program should continue test execution
|
||||
after a test failure via the GTEST_FAIL_FAST environment variable or the
|
||||
--gtest_fail_fast flag. The default value of the flag can also be changed
|
||||
by Bazel fail fast environment variable TESTBRIDGE_TEST_RUNNER_FAIL_FAST.
|
||||
|
||||
This script tests such functionality by invoking googletest-failfast-unittest_
|
||||
(a program written with Google Test) with different environments and command
|
||||
line flags.
|
||||
"""
|
||||
|
||||
import os
|
||||
import gtest_test_utils
|
||||
|
||||
# Constants.
|
||||
|
||||
# Bazel testbridge environment variable for fail fast
|
||||
BAZEL_FAIL_FAST_ENV_VAR = 'TESTBRIDGE_TEST_RUNNER_FAIL_FAST'
|
||||
|
||||
# The environment variable for specifying fail fast.
|
||||
FAIL_FAST_ENV_VAR = 'GTEST_FAIL_FAST'
|
||||
|
||||
# The command line flag for specifying fail fast.
|
||||
FAIL_FAST_FLAG = 'gtest_fail_fast'
|
||||
|
||||
# The command line flag to run disabled tests.
|
||||
RUN_DISABLED_FLAG = 'gtest_also_run_disabled_tests'
|
||||
|
||||
# The command line flag for specifying a filter.
|
||||
FILTER_FLAG = 'gtest_filter'
|
||||
|
||||
# Command to run the googletest-failfast-unittest_ program.
|
||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-failfast-unittest_')
|
||||
|
||||
# The command line flag to tell Google Test to output the list of tests it
|
||||
# will run.
|
||||
LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||
|
||||
# Indicates whether Google Test supports death tests.
|
||||
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
|
||||
[COMMAND, LIST_TESTS_FLAG]).output
|
||||
|
||||
# Utilities.
|
||||
|
||||
environ = os.environ.copy()
|
||||
|
||||
|
||||
def SetEnvVar(env_var, value):
|
||||
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
|
||||
|
||||
if value is not None:
|
||||
environ[env_var] = value
|
||||
elif env_var in environ:
|
||||
del environ[env_var]
|
||||
|
||||
|
||||
def RunAndReturnOutput(test_suite=None, fail_fast=None, run_disabled=False):
|
||||
"""Runs the test program and returns its output."""
|
||||
|
||||
args = []
|
||||
xml_path = os.path.join(gtest_test_utils.GetTempDir(),
|
||||
'.GTestFailFastUnitTest.xml')
|
||||
args += ['--gtest_output=xml:' + xml_path]
|
||||
if fail_fast is not None:
|
||||
if isinstance(fail_fast, str):
|
||||
args += ['--%s=%s' % (FAIL_FAST_FLAG, fail_fast)]
|
||||
elif fail_fast:
|
||||
args += ['--%s' % FAIL_FAST_FLAG]
|
||||
else:
|
||||
args += ['--no%s' % FAIL_FAST_FLAG]
|
||||
if test_suite:
|
||||
args += ['--%s=%s.*' % (FILTER_FLAG, test_suite)]
|
||||
if run_disabled:
|
||||
args += ['--%s' % RUN_DISABLED_FLAG]
|
||||
txt_out = gtest_test_utils.Subprocess([COMMAND] + args, env=environ).output
|
||||
with open(xml_path) as xml_file:
|
||||
return txt_out, xml_file.read()
|
||||
|
||||
|
||||
# The unit test.
|
||||
class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
||||
"""Tests the env variable or the command line flag for fail_fast."""
|
||||
|
||||
def testDefaultBehavior(self):
|
||||
"""Tests the behavior of not specifying the fail_fast."""
|
||||
|
||||
txt, _ = RunAndReturnOutput()
|
||||
self.assertIn('22 FAILED TEST', txt)
|
||||
|
||||
def testGoogletestFlag(self):
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSimpleTest', fail_fast=True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSimpleTest', fail_fast=False)
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
|
||||
def testGoogletestEnvVar(self):
|
||||
"""Tests the behavior of specifying fail_fast via Googletest env var."""
|
||||
|
||||
try:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testBazelEnvVar(self):
|
||||
"""Tests the behavior of specifying fail_fast via Bazel testbridge."""
|
||||
|
||||
try:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
finally:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testFlagOverridesEnvVar(self):
|
||||
"""Tests precedence of flag over env var."""
|
||||
|
||||
try:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest', True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testGoogletestEnvVarOverridesBazelEnvVar(self):
|
||||
"""Tests that the Googletest native env var over Bazel testbridge."""
|
||||
|
||||
try:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '0')
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testEventListener(self):
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
||||
(5, 'OnTestStart'),
|
||||
(5, 'OnTestEnd'),
|
||||
(5, 'OnTestPartResult'),
|
||||
(1, 'OnTestSuiteEnd')]:
|
||||
self.assertEqual(
|
||||
expected_count, txt.count(callback),
|
||||
'Expected %d calls to callback %s match count on output: %s ' %
|
||||
(expected_count, callback, txt))
|
||||
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=False)
|
||||
self.assertIn('3 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 1 test', txt)
|
||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
||||
(5, 'OnTestStart'),
|
||||
(5, 'OnTestEnd'),
|
||||
(5, 'OnTestPartResult'),
|
||||
(1, 'OnTestSuiteEnd')]:
|
||||
self.assertEqual(
|
||||
expected_count, txt.count(callback),
|
||||
'Expected %d calls to callback %s match count on output: %s ' %
|
||||
(expected_count, callback, txt))
|
||||
|
||||
def assertXmlResultCount(self, result, count, xml):
|
||||
self.assertEqual(
|
||||
count, xml.count('result="%s"' % result),
|
||||
'Expected \'result="%s"\' match count of %s: %s ' %
|
||||
(result, count, xml))
|
||||
|
||||
def assertXmlStatusCount(self, status, count, xml):
|
||||
self.assertEqual(
|
||||
count, xml.count('status="%s"' % status),
|
||||
'Expected \'status="%s"\' match count of %s: %s ' %
|
||||
(status, count, xml))
|
||||
|
||||
def assertFailFastXmlAndTxtOutput(self,
|
||||
fail_fast,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert XML and text output of a test execution."""
|
||||
|
||||
txt, xml = RunAndReturnOutput(test_suite, fail_fast, run_disabled)
|
||||
if failure_count > 0:
|
||||
self.assertIn('%s FAILED TEST' % failure_count, txt)
|
||||
if suppressed_count > 0:
|
||||
self.assertIn('%s DISABLED TEST' % suppressed_count, txt)
|
||||
if skipped_count > 0:
|
||||
self.assertIn('[ SKIPPED ] %s tests' % skipped_count, txt)
|
||||
self.assertXmlStatusCount('run',
|
||||
passed_count + failure_count + skipped_count, xml)
|
||||
self.assertXmlStatusCount('notrun', suppressed_count, xml)
|
||||
self.assertXmlResultCount('completed', passed_count + failure_count, xml)
|
||||
self.assertXmlResultCount('skipped', skipped_count, xml)
|
||||
self.assertXmlResultCount('suppressed', suppressed_count, xml)
|
||||
|
||||
def assertFailFastBehavior(self,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert --fail_fast via flag."""
|
||||
|
||||
for fail_fast in ('true', '1', 't', True):
|
||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
||||
failure_count, skipped_count,
|
||||
suppressed_count, run_disabled)
|
||||
|
||||
def assertNotFailFastBehavior(self,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert --nofail_fast via flag."""
|
||||
|
||||
for fail_fast in ('false', '0', 'f', False):
|
||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
||||
failure_count, skipped_count,
|
||||
suppressed_count, run_disabled)
|
||||
|
||||
def testFlag_HasFixtureTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST_F."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasFixtureTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasFixtureTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasSimpleTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasSimpleTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasSimpleTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasParametersTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST_P."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasParametersSuite/HasParametersTest',
|
||||
passed_count=0,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasParametersSuite/HasParametersTest',
|
||||
passed_count=0,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test cases."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=2,
|
||||
suppressed_count=1,
|
||||
run_disabled=False)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=3,
|
||||
skipped_count=0,
|
||||
suppressed_count=1,
|
||||
run_disabled=False)
|
||||
|
||||
def testFlag_HasDisabledRunDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test cases enabled."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
|
||||
def testFlag_HasDisabledSuiteTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test suites."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=0,
|
||||
failure_count=0,
|
||||
skipped_count=0,
|
||||
suppressed_count=5,
|
||||
run_disabled=False)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=0,
|
||||
failure_count=0,
|
||||
skipped_count=0,
|
||||
suppressed_count=5,
|
||||
run_disabled=False)
|
||||
|
||||
def testFlag_HasDisabledSuiteRunDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test suites enabled."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
|
||||
if SUPPORTS_DEATH_TESTS:
|
||||
|
||||
def testFlag_HasDeathTest(self):
|
||||
"""Tests the behavior of fail_fast and death tests."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDeathTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDeathTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
// Copyright 2005, 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.
|
||||
|
||||
|
||||
// Unit test for Google Test test filters.
|
||||
//
|
||||
// A user can specify which test(s) in a Google Test program to run via
|
||||
// either the GTEST_FILTER environment variable or the --gtest_filter
|
||||
// flag. This is used for testing such functionality.
|
||||
//
|
||||
// The program will be invoked from a Python unit test. Don't run it
|
||||
// directly.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Test HasFixtureTest.
|
||||
|
||||
class HasFixtureTest : public testing::Test {};
|
||||
|
||||
TEST_F(HasFixtureTest, Test0) {}
|
||||
|
||||
TEST_F(HasFixtureTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasSimpleTest.
|
||||
|
||||
TEST(HasSimpleTest, Test0) {}
|
||||
|
||||
TEST(HasSimpleTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasDisabledTest.
|
||||
|
||||
TEST(HasDisabledTest, Test0) {}
|
||||
|
||||
TEST(HasDisabledTest, DISABLED_Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasDeathTest
|
||||
|
||||
TEST(HasDeathTest, Test0) { EXPECT_DEATH_IF_SUPPORTED(exit(1), ".*"); }
|
||||
|
||||
TEST(HasDeathTest, Test1) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test2) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test3) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test4) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
// Test DISABLED_HasDisabledSuite
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test0) {}
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasParametersTest
|
||||
|
||||
class HasParametersTest : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(HasParametersTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_P(HasParametersTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(HasParametersSuite, HasParametersTest,
|
||||
testing::Values(1, 2));
|
||||
|
||||
class MyTestListener : public ::testing::EmptyTestEventListener {
|
||||
void OnTestSuiteStart(const ::testing::TestSuite& test_suite) override {
|
||||
printf("We are in OnTestSuiteStart of %s.\n", test_suite.name());
|
||||
}
|
||||
|
||||
void OnTestStart(const ::testing::TestInfo& test_info) override {
|
||||
printf("We are in OnTestStart of %s.%s.\n", test_info.test_suite_name(),
|
||||
test_info.name());
|
||||
}
|
||||
|
||||
void OnTestPartResult(
|
||||
const ::testing::TestPartResult& test_part_result) override {
|
||||
printf("We are in OnTestPartResult %s:%d.\n", test_part_result.file_name(),
|
||||
test_part_result.line_number());
|
||||
}
|
||||
|
||||
void OnTestEnd(const ::testing::TestInfo& test_info) override {
|
||||
printf("We are in OnTestEnd of %s.%s.\n", test_info.test_suite_name(),
|
||||
test_info.name());
|
||||
}
|
||||
|
||||
void OnTestSuiteEnd(const ::testing::TestSuite& test_suite) override {
|
||||
printf("We are in OnTestSuiteEnd of %s.\n", test_suite.name());
|
||||
}
|
||||
};
|
||||
|
||||
TEST(HasSkipTest, Test0) { SUCCEED() << "Expected success."; }
|
||||
|
||||
TEST(HasSkipTest, Test1) { GTEST_SKIP() << "Expected skip."; }
|
||||
|
||||
TEST(HasSkipTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSkipTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSkipTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::UnitTest::GetInstance()->listeners().Append(new MyTestListener());
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -50,6 +50,8 @@ namespace internal {
|
|||
namespace {
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
// FIXME: Move these to the POSIX adapter section in
|
||||
// gtest-port.h.
|
||||
|
||||
// Windows CE doesn't have the remove C function.
|
||||
int remove(const char* path) {
|
||||
|
|
@ -78,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
|
|||
const FilePath cwd = FilePath::GetCurrentDir();
|
||||
posix::ChDir(original_dir.c_str());
|
||||
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_OS2
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Skips the ":".
|
||||
const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
|
||||
|
|
@ -477,7 +479,7 @@ TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
|
|||
|
||||
class DirectoryCreationTest : public Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
testdata_path_.Set(FilePath(
|
||||
TempDir() + GetCurrentExecutableName().string() +
|
||||
"_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_));
|
||||
|
|
@ -494,7 +496,7 @@ class DirectoryCreationTest : public Test {
|
|||
posix::RmDir(testdata_path_.c_str());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
remove(testdata_file_.c_str());
|
||||
remove(unique_file0_.c_str());
|
||||
remove(unique_file1_.c_str());
|
||||
|
|
|
|||
|
|
@ -42,10 +42,7 @@ we test that here also.
|
|||
|
||||
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
|
||||
|
||||
|
|
@ -60,7 +57,7 @@ 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)'])
|
||||
[sys.executable, '-c', 'import os; print \'EMPTY_VAR\' in os.environ'])
|
||||
CAN_PASS_EMPTY_ENV = eval(child.output)
|
||||
|
||||
|
||||
|
|
@ -75,7 +72,7 @@ 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)'
|
||||
[sys.executable, '-c', 'import os; print \'UNSET_VAR\' not in os.environ'
|
||||
])
|
||||
CAN_UNSET_ENV = eval(child.output)
|
||||
|
||||
|
|
@ -236,10 +233,10 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||
"""Asserts that two sets are equal."""
|
||||
|
||||
for elem in lhs:
|
||||
self.assertTrue(elem in rhs, '%s in %s' % (elem, rhs))
|
||||
self.assert_(elem in rhs, '%s in %s' % (elem, rhs))
|
||||
|
||||
for elem in rhs:
|
||||
self.assertTrue(elem in lhs, '%s in %s' % (elem, lhs))
|
||||
self.assert_(elem in lhs, '%s in %s' % (elem, lhs))
|
||||
|
||||
def AssertPartitionIsValid(self, set_var, list_of_sets):
|
||||
"""Asserts that list_of_sets is a valid partition of set_var."""
|
||||
|
|
@ -248,14 +245,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
|
||||
|
||||
|
|
@ -581,13 +578,13 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||
|
||||
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
|
||||
'shard_status_file')
|
||||
self.assertTrue(not os.path.exists(shard_status_file))
|
||||
self.assert_(not os.path.exists(shard_status_file))
|
||||
|
||||
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
||||
try:
|
||||
InvokeWithModifiedEnv(extra_env, RunAndReturnOutput)
|
||||
finally:
|
||||
self.assertTrue(os.path.exists(shard_status_file))
|
||||
self.assert_(os.path.exists(shard_status_file))
|
||||
os.remove(shard_status_file)
|
||||
|
||||
def testShardStatusFileIsCreatedWithListTests(self):
|
||||
|
|
@ -595,7 +592,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||
|
||||
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
|
||||
'shard_status_file2')
|
||||
self.assertTrue(not os.path.exists(shard_status_file))
|
||||
self.assert_(not os.path.exists(shard_status_file))
|
||||
|
||||
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
||||
try:
|
||||
|
|
@ -605,12 +602,12 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||
finally:
|
||||
# This assertion ensures that Google Test enumerated the tests as
|
||||
# opposed to running them.
|
||||
self.assertTrue('[==========]' not in output,
|
||||
self.assert_('[==========]' not in output,
|
||||
'Unexpected output during test enumeration.\n'
|
||||
'Please ensure that LIST_TESTS_FLAG is assigned the\n'
|
||||
'correct flag value for listing Google Test tests.')
|
||||
|
||||
self.assertTrue(os.path.exists(shard_status_file))
|
||||
self.assert_(os.path.exists(shard_status_file))
|
||||
os.remove(shard_status_file)
|
||||
|
||||
if SUPPORTS_DEATH_TESTS:
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ TEST_P(ParamTest, TestX) {
|
|||
TEST_P(ParamTest, TestY) {
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(SeqP, ParamTest, testing::Values(1, 2));
|
||||
INSTANTIATE_TEST_SUITE_P(SeqQ, ParamTest, testing::Values(5, 6));
|
||||
INSTANTIATE_TEST_CASE_P(SeqP, ParamTest, testing::Values(1, 2));
|
||||
INSTANTIATE_TEST_CASE_P(SeqQ, ParamTest, testing::Values(5, 6));
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
# 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
|
||||
# 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.
|
||||
"""Unit test for Google Test's global test environment behavior.
|
||||
|
||||
A user can specify a global test environment via
|
||||
testing::AddGlobalTestEnvironment. Failures in the global environment should
|
||||
result in all unit tests being skipped.
|
||||
|
||||
This script tests such functionality by invoking
|
||||
googletest-global-environment-unittest_ (a program written with Google Test).
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
||||
"""Tests global test environment failures."""
|
||||
|
||||
def testEnvironmentSetUpFails(self):
|
||||
"""Tests the behavior of not specifying the fail_fast."""
|
||||
|
||||
# Run the test.
|
||||
txt = RunAndReturnOutput()
|
||||
|
||||
# We should see the text of the global environment setup error.
|
||||
self.assertIn('Canned environment setup error', txt)
|
||||
|
||||
# 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)
|
||||
|
||||
# The test case shouldn't have been run.
|
||||
self.assertNotIn('Unexpected call', txt)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright 2005, 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.
|
||||
|
||||
// Unit test for Google Test global test environments.
|
||||
//
|
||||
// The program will be invoked from a Python unit test. Don't run it
|
||||
// directly.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// An environment that always fails in its SetUp method.
|
||||
class FailingEnvironment final : public ::testing::Environment {
|
||||
public:
|
||||
void SetUp() override { FAIL() << "Canned environment setup error"; }
|
||||
};
|
||||
|
||||
// Register the environment.
|
||||
auto* const g_environment_ =
|
||||
::testing::AddGlobalTestEnvironment(new FailingEnvironment);
|
||||
|
||||
// A test that doesn't actually run.
|
||||
TEST(SomeTest, DoesFoo) { FAIL() << "Unexpected call"; }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -40,89 +40,55 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_'
|
|||
GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_'
|
||||
|
||||
EXPECTED_1 = {
|
||||
'tests':
|
||||
1,
|
||||
'failures':
|
||||
0,
|
||||
'disabled':
|
||||
0,
|
||||
'errors':
|
||||
0,
|
||||
'time':
|
||||
'*',
|
||||
'timestamp':
|
||||
'*',
|
||||
'name':
|
||||
'AllTests',
|
||||
'testsuites': [{
|
||||
'name':
|
||||
'PropertyOne',
|
||||
'tests':
|
||||
1,
|
||||
'failures':
|
||||
0,
|
||||
'disabled':
|
||||
0,
|
||||
'errors':
|
||||
0,
|
||||
'time':
|
||||
'*',
|
||||
'timestamp':
|
||||
'*',
|
||||
'testsuite': [{
|
||||
'name': 'TestSomeProperties',
|
||||
'status': 'RUN',
|
||||
'result': 'COMPLETED',
|
||||
'time': '*',
|
||||
'timestamp': '*',
|
||||
'classname': 'PropertyOne',
|
||||
'SetUpProp': '1',
|
||||
'TestSomeProperty': '1',
|
||||
'TearDownProp': '1',
|
||||
u'tests': 1,
|
||||
u'failures': 0,
|
||||
u'disabled': 0,
|
||||
u'errors': 0,
|
||||
u'time': u'*',
|
||||
u'timestamp': u'*',
|
||||
u'name': u'AllTests',
|
||||
u'testsuites': [{
|
||||
u'name': u'PropertyOne',
|
||||
u'tests': 1,
|
||||
u'failures': 0,
|
||||
u'disabled': 0,
|
||||
u'errors': 0,
|
||||
u'time': u'*',
|
||||
u'testsuite': [{
|
||||
u'name': u'TestSomeProperties',
|
||||
u'status': u'RUN',
|
||||
u'time': u'*',
|
||||
u'classname': u'PropertyOne',
|
||||
u'SetUpProp': u'1',
|
||||
u'TestSomeProperty': u'1',
|
||||
u'TearDownProp': u'1',
|
||||
}],
|
||||
}],
|
||||
}
|
||||
|
||||
EXPECTED_2 = {
|
||||
'tests':
|
||||
1,
|
||||
'failures':
|
||||
0,
|
||||
'disabled':
|
||||
0,
|
||||
'errors':
|
||||
0,
|
||||
'time':
|
||||
'*',
|
||||
'timestamp':
|
||||
'*',
|
||||
'name':
|
||||
'AllTests',
|
||||
'testsuites': [{
|
||||
'name':
|
||||
'PropertyTwo',
|
||||
'tests':
|
||||
1,
|
||||
'failures':
|
||||
0,
|
||||
'disabled':
|
||||
0,
|
||||
'errors':
|
||||
0,
|
||||
'time':
|
||||
'*',
|
||||
'timestamp':
|
||||
'*',
|
||||
'testsuite': [{
|
||||
'name': 'TestSomeProperties',
|
||||
'status': 'RUN',
|
||||
'result': 'COMPLETED',
|
||||
'timestamp': '*',
|
||||
'time': '*',
|
||||
'classname': 'PropertyTwo',
|
||||
'SetUpProp': '2',
|
||||
'TestSomeProperty': '2',
|
||||
'TearDownProp': '2',
|
||||
u'tests': 1,
|
||||
u'failures': 0,
|
||||
u'disabled': 0,
|
||||
u'errors': 0,
|
||||
u'time': u'*',
|
||||
u'timestamp': u'*',
|
||||
u'name': u'AllTests',
|
||||
u'testsuites': [{
|
||||
u'name': u'PropertyTwo',
|
||||
u'tests': 1,
|
||||
u'failures': 0,
|
||||
u'disabled': 0,
|
||||
u'errors': 0,
|
||||
u'time': u'*',
|
||||
u'testsuite': [{
|
||||
u'name': u'TestSomeProperties',
|
||||
u'status': u'RUN',
|
||||
u'time': u'*',
|
||||
u'classname': u'PropertyTwo',
|
||||
u'SetUpProp': u'2',
|
||||
u'TestSomeProperty': u'2',
|
||||
u'TearDownProp': u'2',
|
||||
}],
|
||||
}],
|
||||
}
|
||||
|
|
@ -167,14 +133,19 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
|
|||
command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_]
|
||||
p = gtest_test_utils.Subprocess(command,
|
||||
working_dir=gtest_test_utils.GetTempDir())
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
|
||||
# FIXME: libtool causes the built test binary to be
|
||||
# named lt-gtest_xml_outfiles_test_ instead of
|
||||
# gtest_xml_outfiles_test_. To account for this possibility, we
|
||||
# allow both names in the following code. We should remove this
|
||||
# when libtool replacement tool is ready.
|
||||
output_file_name1 = test_name + '.json'
|
||||
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
||||
output_file_name2 = 'lt-' + output_file_name1
|
||||
output_file2 = os.path.join(self.output_dir_, output_file_name2)
|
||||
self.assertTrue(os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
||||
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
||||
output_file1)
|
||||
|
||||
if os.path.isfile(output_file1):
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,151 @@
|
|||
// Copyright 2003, 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.
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using testing::Message;
|
||||
using testing::internal::linked_ptr;
|
||||
|
||||
int num;
|
||||
Message* history = NULL;
|
||||
|
||||
// Class which tracks allocation/deallocation
|
||||
class A {
|
||||
public:
|
||||
A(): mynum(num++) { *history << "A" << mynum << " ctor\n"; }
|
||||
virtual ~A() { *history << "A" << mynum << " dtor\n"; }
|
||||
virtual void Use() { *history << "A" << mynum << " use\n"; }
|
||||
protected:
|
||||
int mynum;
|
||||
};
|
||||
|
||||
// Subclass
|
||||
class B : public A {
|
||||
public:
|
||||
B() { *history << "B" << mynum << " ctor\n"; }
|
||||
~B() { *history << "B" << mynum << " dtor\n"; }
|
||||
virtual void Use() { *history << "B" << mynum << " use\n"; }
|
||||
};
|
||||
|
||||
class LinkedPtrTest : public testing::Test {
|
||||
public:
|
||||
LinkedPtrTest() {
|
||||
num = 0;
|
||||
history = new Message;
|
||||
}
|
||||
|
||||
virtual ~LinkedPtrTest() {
|
||||
delete history;
|
||||
history = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LinkedPtrTest, GeneralTest) {
|
||||
{
|
||||
linked_ptr<A> a0, a1, a2;
|
||||
// Use explicit function call notation here to suppress self-assign warning.
|
||||
a0.operator=(a0);
|
||||
a1 = a2;
|
||||
ASSERT_EQ(a0.get(), static_cast<A*>(NULL));
|
||||
ASSERT_EQ(a1.get(), static_cast<A*>(NULL));
|
||||
ASSERT_EQ(a2.get(), static_cast<A*>(NULL));
|
||||
ASSERT_TRUE(a0 == NULL);
|
||||
ASSERT_TRUE(a1 == NULL);
|
||||
ASSERT_TRUE(a2 == NULL);
|
||||
|
||||
{
|
||||
linked_ptr<A> a3(new A);
|
||||
a0 = a3;
|
||||
ASSERT_TRUE(a0 == a3);
|
||||
ASSERT_TRUE(a0 != NULL);
|
||||
ASSERT_TRUE(a0.get() == a3);
|
||||
ASSERT_TRUE(a0 == a3.get());
|
||||
linked_ptr<A> a4(a0);
|
||||
a1 = a4;
|
||||
linked_ptr<A> a5(new A);
|
||||
ASSERT_TRUE(a5.get() != a3);
|
||||
ASSERT_TRUE(a5 != a3.get());
|
||||
a2 = a5;
|
||||
linked_ptr<B> b0(new B);
|
||||
linked_ptr<A> a6(b0);
|
||||
ASSERT_TRUE(b0 == a6);
|
||||
ASSERT_TRUE(a6 == b0);
|
||||
ASSERT_TRUE(b0 != NULL);
|
||||
a5 = b0;
|
||||
a5 = b0;
|
||||
a3->Use();
|
||||
a4->Use();
|
||||
a5->Use();
|
||||
a6->Use();
|
||||
b0->Use();
|
||||
(*b0).Use();
|
||||
b0.get()->Use();
|
||||
}
|
||||
|
||||
a0->Use();
|
||||
a1->Use();
|
||||
a2->Use();
|
||||
|
||||
a1 = a2;
|
||||
a2.reset(new A);
|
||||
a0.reset();
|
||||
|
||||
linked_ptr<A> a7;
|
||||
}
|
||||
|
||||
ASSERT_STREQ(
|
||||
"A0 ctor\n"
|
||||
"A1 ctor\n"
|
||||
"A2 ctor\n"
|
||||
"B2 ctor\n"
|
||||
"A0 use\n"
|
||||
"A0 use\n"
|
||||
"B2 use\n"
|
||||
"B2 use\n"
|
||||
"B2 use\n"
|
||||
"B2 use\n"
|
||||
"B2 use\n"
|
||||
"B2 dtor\n"
|
||||
"A2 dtor\n"
|
||||
"A0 use\n"
|
||||
"A0 use\n"
|
||||
"A1 use\n"
|
||||
"A3 ctor\n"
|
||||
"A0 dtor\n"
|
||||
"A3 dtor\n"
|
||||
"A1 dtor\n",
|
||||
history->GetString().c_str());
|
||||
}
|
||||
|
||||
} // Unnamed namespace
|
||||
|
|
@ -156,14 +156,14 @@ class GTestListTestsUnitTest(gtest_test_utils.TestCase):
|
|||
output = Run(args)
|
||||
|
||||
if expected_output_re:
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
expected_output_re.match(output),
|
||||
('when %s is %s, the output of "%s" is "%s",\n'
|
||||
'which does not match regex "%s"' %
|
||||
(LIST_TESTS_FLAG, flag_expression, ' '.join(args), output,
|
||||
expected_output_re.pattern)))
|
||||
else:
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
not EXPECTED_OUTPUT_NO_FILTER_RE.match(output),
|
||||
('when %s is %s, the output of "%s" is "%s"'%
|
||||
(LIST_TESTS_FLAG, flag_expression, ' '.join(args), output)))
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ TEST_P(ValueParamTest, TestA) {
|
|||
TEST_P(ValueParamTest, TestB) {
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
MyInstantiation, ValueParamTest,
|
||||
testing::Values(MyType("one line"),
|
||||
MyType("two\nlines"),
|
||||
|
|
@ -123,7 +123,7 @@ class MyArray {
|
|||
typedef testing::Types<VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT
|
||||
int*, MyArray<bool, 42> > MyTypes;
|
||||
|
||||
TYPED_TEST_SUITE(TypedTest, MyTypes);
|
||||
TYPED_TEST_CASE(TypedTest, MyTypes);
|
||||
|
||||
TYPED_TEST(TypedTest, TestA) {
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ template <typename T>
|
|||
class TypeParamTest : public testing::Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(TypeParamTest);
|
||||
TYPED_TEST_CASE_P(TypeParamTest);
|
||||
|
||||
TYPED_TEST_P(TypeParamTest, TestA) {
|
||||
}
|
||||
|
|
@ -145,9 +145,9 @@ TYPED_TEST_P(TypeParamTest, TestA) {
|
|||
TYPED_TEST_P(TypeParamTest, TestB) {
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypeParamTest, TestA, TestB);
|
||||
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB);
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, TypeParamTest, MyTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
|||
|
|
@ -35,20 +35,19 @@
|
|||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/custom/gtest.h"
|
||||
|
||||
using ::testing::AddGlobalTestEnvironment;
|
||||
using ::testing::Environment;
|
||||
using ::testing::InitGoogleTest;
|
||||
using ::testing::Test;
|
||||
using ::testing::TestSuite;
|
||||
using ::testing::TestCase;
|
||||
using ::testing::TestEventListener;
|
||||
using ::testing::TestInfo;
|
||||
using ::testing::TestPartResult;
|
||||
using ::testing::UnitTest;
|
||||
|
||||
// Used by tests to register their events.
|
||||
std::vector<std::string>* g_events = nullptr;
|
||||
std::vector<std::string>* g_events = NULL;
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
|
@ -58,66 +57,63 @@ class EventRecordingListener : public TestEventListener {
|
|||
explicit EventRecordingListener(const char* name) : name_(name) {}
|
||||
|
||||
protected:
|
||||
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramStart"));
|
||||
}
|
||||
|
||||
void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int iteration) {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationStart")
|
||||
<< "(" << iteration << ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
|
||||
}
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseStart(const TestCase& /*test_case*/) override {
|
||||
|
||||
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestCaseStart"));
|
||||
}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {
|
||||
virtual void OnTestStart(const TestInfo& /*test_info*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestStart"));
|
||||
}
|
||||
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {
|
||||
virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestPartResult"));
|
||||
}
|
||||
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {
|
||||
virtual void OnTestEnd(const TestInfo& /*test_info*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestEnd"));
|
||||
}
|
||||
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseEnd(const TestCase& /*test_case*/) override {
|
||||
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestCaseEnd"));
|
||||
}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd"));
|
||||
}
|
||||
|
||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int iteration) {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationEnd")
|
||||
<< "(" << iteration << ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
|
||||
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramEnd"));
|
||||
}
|
||||
|
||||
|
|
@ -129,98 +125,34 @@ class EventRecordingListener : public TestEventListener {
|
|||
std::string name_;
|
||||
};
|
||||
|
||||
// This listener is using OnTestSuiteStart, OnTestSuiteEnd API
|
||||
class EventRecordingListener2 : public TestEventListener {
|
||||
public:
|
||||
explicit EventRecordingListener2(const char* name) : name_(name) {}
|
||||
|
||||
protected:
|
||||
void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramStart"));
|
||||
}
|
||||
|
||||
void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationStart") << "(" << iteration
|
||||
<< ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
|
||||
}
|
||||
|
||||
void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestSuiteStart"));
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestStart"));
|
||||
}
|
||||
|
||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestPartResult"));
|
||||
}
|
||||
|
||||
void OnTestEnd(const TestInfo& /*test_info*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestEnd"));
|
||||
}
|
||||
|
||||
void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestSuiteEnd"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
|
||||
}
|
||||
|
||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd"));
|
||||
}
|
||||
|
||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||
int iteration) override {
|
||||
Message message;
|
||||
message << GetFullMethodName("OnTestIterationEnd") << "(" << iteration
|
||||
<< ")";
|
||||
g_events->push_back(message.GetString());
|
||||
}
|
||||
|
||||
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestProgramEnd"));
|
||||
}
|
||||
|
||||
private:
|
||||
std::string GetFullMethodName(const char* name) { return name_ + "." + name; }
|
||||
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
class EnvironmentInvocationCatcher : public Environment {
|
||||
protected:
|
||||
void SetUp() override { g_events->push_back("Environment::SetUp"); }
|
||||
virtual void SetUp() {
|
||||
g_events->push_back("Environment::SetUp");
|
||||
}
|
||||
|
||||
void TearDown() override { g_events->push_back("Environment::TearDown"); }
|
||||
virtual void TearDown() {
|
||||
g_events->push_back("Environment::TearDown");
|
||||
}
|
||||
};
|
||||
|
||||
class ListenerTest : public Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
g_events->push_back("ListenerTest::SetUpTestSuite");
|
||||
static void SetUpTestCase() {
|
||||
g_events->push_back("ListenerTest::SetUpTestCase");
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
g_events->push_back("ListenerTest::TearDownTestSuite");
|
||||
static void TearDownTestCase() {
|
||||
g_events->push_back("ListenerTest::TearDownTestCase");
|
||||
}
|
||||
|
||||
void SetUp() override { g_events->push_back("ListenerTest::SetUp"); }
|
||||
virtual void SetUp() {
|
||||
g_events->push_back("ListenerTest::SetUp");
|
||||
}
|
||||
|
||||
void TearDown() override { g_events->push_back("ListenerTest::TearDown"); }
|
||||
virtual void TearDown() {
|
||||
g_events->push_back("ListenerTest::TearDown");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ListenerTest, DoesFoo) {
|
||||
|
|
@ -241,7 +173,6 @@ TEST_F(ListenerTest, DoesBar) {
|
|||
|
||||
using ::testing::internal::EnvironmentInvocationCatcher;
|
||||
using ::testing::internal::EventRecordingListener;
|
||||
using ::testing::internal::EventRecordingListener2;
|
||||
|
||||
void VerifyResults(const std::vector<std::string>& data,
|
||||
const char* const* expected_data,
|
||||
|
|
@ -276,8 +207,6 @@ int main(int argc, char **argv) {
|
|||
new EventRecordingListener("1st"));
|
||||
UnitTest::GetInstance()->listeners().Append(
|
||||
new EventRecordingListener("2nd"));
|
||||
UnitTest::GetInstance()->listeners().Append(
|
||||
new EventRecordingListener2("3rd"));
|
||||
|
||||
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
|
||||
|
||||
|
|
@ -287,224 +216,88 @@ int main(int argc, char **argv) {
|
|||
::testing::GTEST_FLAG(repeat) = 2;
|
||||
int ret_val = RUN_ALL_TESTS();
|
||||
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// The deprecated OnTestSuiteStart/OnTestCaseStart events are included
|
||||
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"3rd.OnTestProgramStart",
|
||||
"1st.OnTestIterationStart(0)",
|
||||
"2nd.OnTestIterationStart(0)",
|
||||
"3rd.OnTestIterationStart(0)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(0)",
|
||||
"2nd.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationStart(1)",
|
||||
"2nd.OnTestIterationStart(1)",
|
||||
"3rd.OnTestIterationStart(1)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(1)",
|
||||
"2nd.OnTestIterationEnd(1)",
|
||||
"1st.OnTestIterationEnd(1)",
|
||||
"3rd.OnTestProgramEnd",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"};
|
||||
#else
|
||||
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"3rd.OnTestProgramStart",
|
||||
"1st.OnTestIterationStart(0)",
|
||||
"2nd.OnTestIterationStart(0)",
|
||||
"3rd.OnTestIterationStart(0)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(0)",
|
||||
"2nd.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationStart(1)",
|
||||
"2nd.OnTestIterationStart(1)",
|
||||
"3rd.OnTestIterationStart(1)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(1)",
|
||||
"2nd.OnTestIterationEnd(1)",
|
||||
"1st.OnTestIterationEnd(1)",
|
||||
"3rd.OnTestProgramEnd",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"};
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
const char* const expected_events[] = {
|
||||
"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"1st.OnTestIterationStart(0)",
|
||||
"2nd.OnTestIterationStart(0)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestCase",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestCase",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationStart(1)",
|
||||
"2nd.OnTestIterationStart(1)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnTestCaseStart",
|
||||
"2nd.OnTestCaseStart",
|
||||
"ListenerTest::SetUpTestCase",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestCase",
|
||||
"2nd.OnTestCaseEnd",
|
||||
"1st.OnTestCaseEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnTestIterationEnd(1)",
|
||||
"1st.OnTestIterationEnd(1)",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"
|
||||
};
|
||||
VerifyResults(events,
|
||||
expected_events,
|
||||
sizeof(expected_events)/sizeof(expected_events[0]));
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ TEST(MessageTest, StreamsPointer) {
|
|||
|
||||
// Tests streaming a NULL non-char pointer.
|
||||
TEST(MessageTest, StreamsNullPointer) {
|
||||
int* p = nullptr;
|
||||
int* p = NULL;
|
||||
EXPECT_EQ("(null)", (Message() << p).GetString());
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ TEST(MessageTest, StreamsCString) {
|
|||
|
||||
// Tests streaming a NULL C string.
|
||||
TEST(MessageTest, StreamsNullCString) {
|
||||
char* p = nullptr;
|
||||
char* p = NULL;
|
||||
EXPECT_EQ("(null)", (Message() << p).GetString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,9 +42,6 @@
|
|||
# include <windows.h>
|
||||
#elif GTEST_OS_WINDOWS
|
||||
# include <direct.h>
|
||||
#elif GTEST_OS_OS2
|
||||
// For strcasecmp on OS/2
|
||||
#include <strings.h>
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
#include "src/gtest-internal-inl.h"
|
||||
|
|
@ -105,15 +102,10 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
|
|||
_strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
|
||||
_strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
|
||||
_strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
|
||||
#elif GTEST_OS_OS2
|
||||
const bool success =
|
||||
strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
|
||||
#elif GTEST_OS_FUCHSIA
|
||||
const bool success = exe_str == "app";
|
||||
#else
|
||||
// FIXME: remove the hard-coded "lt-" prefix when libtool replacement is ready
|
||||
const bool success =
|
||||
exe_str == "googletest-options-test" ||
|
||||
exe_str == "gtest_all_test" ||
|
||||
|
|
@ -128,7 +120,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
|
|||
|
||||
class XmlOutputChangeDirTest : public Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
original_working_dir_ = FilePath::GetCurrentDir();
|
||||
posix::ChDir("..");
|
||||
// This will make the test fail if run from the root directory.
|
||||
|
|
@ -136,7 +128,7 @@ class XmlOutputChangeDirTest : public Test {
|
|||
FilePath::GetCurrentDir().string());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
posix::ChDir(original_working_dir_.string().c_str());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Expected equality of these values:
|
|||
3
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [mRunning 88 tests from 41 test suites.
|
||||
[0;32m[==========] [mRunning 76 tests from 34 test cases.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
|
|
@ -380,74 +380,66 @@ Stack trace: (omitted)
|
|||
[0;32m[ RUN ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
foo.cc:42: Failure
|
||||
Failed
|
||||
Expected nonfatal failure in foo.cc
|
||||
Expected failure in foo.cc
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
[0;32m[----------] [m1 test from GtestFailAtTest
|
||||
[0;32m[ RUN ] [mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
foo.cc:42: Failure
|
||||
Failed
|
||||
Expected fatal failure in foo.cc
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
[0;32m[----------] [m4 tests from MixedUpTestSuiteTest
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteTest.FirstTestFromNamespaceFoo
|
||||
[0;32m[ OK ] [mMixedUpTestSuiteTest.FirstTestFromNamespaceFoo
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteTest.SecondTestFromNamespaceFoo
|
||||
[0;32m[ OK ] [mMixedUpTestSuiteTest.SecondTestFromNamespaceFoo
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteTest.ThisShouldFail
|
||||
[0;32m[----------] [m4 tests from MixedUpTestCaseTest
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
|
||||
[0;32m[ OK ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.SecondTestFromNamespaceFoo
|
||||
[0;32m[ OK ] [mMixedUpTestCaseTest.SecondTestFromNamespaceFoo
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestSuiteTest,
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseTest,
|
||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test suites.
|
||||
of the classes to put the tests into different test cases.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteTest.ThisShouldFail
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteTest.ThisShouldFailToo
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestSuiteTest,
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseTest,
|
||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test suites.
|
||||
of the classes to put the tests into different test cases.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteTest.ThisShouldFailToo
|
||||
[0;32m[----------] [m2 tests from MixedUpTestSuiteWithSameTestNameTest
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;32m[ OK ] [mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;32m[ RUN ] [mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||
[0;32m[----------] [m2 tests from MixedUpTestCaseWithSameTestNameTest
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;32m[ OK ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite MixedUpTestSuiteWithSameTestNameTest,
|
||||
All tests in the same test case must use the same test fixture
|
||||
class. However, in test case MixedUpTestCaseWithSameTestNameTest,
|
||||
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test suites.
|
||||
of the classes to put the tests into different test cases.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;32m[----------] [m2 tests from TEST_F_before_TEST_in_same_test_case
|
||||
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F
|
||||
[0;32m[ OK ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTEST_F
|
||||
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite TEST_F_before_TEST_in_same_test_case,
|
||||
All tests in the same test case must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test case is
|
||||
illegal. In test case TEST_F_before_TEST_in_same_test_case,
|
||||
test DefinedUsingTEST_F is defined using TEST_F but
|
||||
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
|
|
@ -461,9 +453,9 @@ Stack trace: (omitted)
|
|||
[0;32m[ RUN ] [mTEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite TEST_before_TEST_F_in_same_test_case,
|
||||
All tests in the same test case must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test case is
|
||||
illegal. In test case TEST_before_TEST_F_in_same_test_case,
|
||||
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
|
||||
test DefinedUsingTEST is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
|
|
@ -878,84 +870,6 @@ Expected non-fatal failure.
|
|||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;32m[----------] [m2 tests from DynamicFixture
|
||||
DynamicFixture::SetUpTestSuite
|
||||
[0;32m[ RUN ] [mDynamicFixture.DynamicTestPass
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mDynamicFixture.DynamicTestPass
|
||||
[0;32m[ RUN ] [mDynamicFixture.DynamicTestFail
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Value of: Pass
|
||||
Actual: false
|
||||
Expected: true
|
||||
Stack trace: (omitted)
|
||||
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
|
||||
DynamicFixture::TearDownTestSuite
|
||||
[0;32m[----------] [m1 test from DynamicFixtureAnotherName
|
||||
DynamicFixture::SetUpTestSuite
|
||||
[0;32m[ RUN ] [mDynamicFixtureAnotherName.DynamicTestPass
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mDynamicFixtureAnotherName.DynamicTestPass
|
||||
DynamicFixture::TearDownTestSuite
|
||||
[0;32m[----------] [m2 tests from BadDynamicFixture1
|
||||
DynamicFixture::SetUpTestSuite
|
||||
[0;32m[ RUN ] [mBadDynamicFixture1.FixtureBase
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mBadDynamicFixture1.FixtureBase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture1.TestBase
|
||||
DynamicFixture()
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class, so mixing TEST_F and TEST in the same test suite is
|
||||
illegal. In test suite BadDynamicFixture1,
|
||||
test FixtureBase is defined using TEST_F but
|
||||
test TestBase is defined using TEST. You probably
|
||||
want to change the TEST to TEST_F or move it to another test
|
||||
case.
|
||||
Stack trace: (omitted)
|
||||
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
|
||||
DynamicFixture::TearDownTestSuite
|
||||
[0;32m[----------] [m2 tests from BadDynamicFixture2
|
||||
DynamicFixture::SetUpTestSuite
|
||||
[0;32m[ RUN ] [mBadDynamicFixture2.FixtureBase
|
||||
DynamicFixture()
|
||||
DynamicFixture::SetUp
|
||||
DynamicFixture::TearDown
|
||||
~DynamicFixture()
|
||||
[0;32m[ OK ] [mBadDynamicFixture2.FixtureBase
|
||||
[0;32m[ RUN ] [mBadDynamicFixture2.Derived
|
||||
DynamicFixture()
|
||||
gtest.cc:#: Failure
|
||||
Failed
|
||||
All tests in the same test suite must use the same test fixture
|
||||
class. However, in test suite BadDynamicFixture2,
|
||||
you defined test FixtureBase and test Derived
|
||||
using two different test fixture classes. This can happen if
|
||||
the two classes are from different namespaces or translation
|
||||
units and have the same name. You should probably rename one
|
||||
of the classes to put the tests into different test suites.
|
||||
Stack trace: (omitted)
|
||||
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
DynamicFixture::TearDownTestSuite
|
||||
[0;32m[----------] [m1 test from PrintingFailingParams/FailingParamTest
|
||||
[0;32m[ RUN ] [mPrintingFailingParams/FailingParamTest.Fails/0
|
||||
googletest-output-test_.cc:#: Failure
|
||||
|
|
@ -966,9 +880,6 @@ Expected equality of these values:
|
|||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;32m[----------] [m1 test from EmptyBasenameParamInst
|
||||
[0;32m[ RUN ] [mEmptyBasenameParamInst.Passes/0
|
||||
[0;32m[ OK ] [mEmptyBasenameParamInst.Passes/0
|
||||
[0;32m[----------] [m2 tests from PrintingStrings/ParamTest
|
||||
[0;32m[ RUN ] [mPrintingStrings/ParamTest.Success/a
|
||||
[0;32m[ OK ] [mPrintingStrings/ParamTest.Success/a
|
||||
|
|
@ -982,43 +893,6 @@ Expected failure
|
|||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
[0;32m[----------] [m3 tests from GoogleTestVerification
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Parameterized test suite NoTests is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are defined via TEST_P . No test cases will run.
|
||||
|
||||
Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from code that always depend on code that provides TEST_P. Failing to do so is often an indication of dead code, e.g. the last TEST_P was removed but the rest got left behind.
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NoTests);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Parameterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing.
|
||||
|
||||
Ideally, TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTest);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Type parameterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run.
|
||||
|
||||
Ideally, TYPED_TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTypesTest);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
[0;32m[----------] [mGlobal test environment tear-down
|
||||
BarEnvironment::TearDown() called.
|
||||
googletest-output-test_.cc:#: Failure
|
||||
|
|
@ -1032,9 +906,9 @@ Failed
|
|||
Expected fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [m88 tests from 41 test suites ran.
|
||||
[0;32m[ PASSED ] [m31 tests.
|
||||
[0;31m[ FAILED ] [m57 tests, listed below:
|
||||
[0;32m[==========] [m76 tests from 34 test cases ran.
|
||||
[0;32m[ PASSED ] [m26 tests.
|
||||
[0;31m[ FAILED ] [m50 tests, listed below:
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
|
||||
|
|
@ -1054,10 +928,9 @@ Stack trace: (omitted)
|
|||
[0;31m[ FAILED ] [mNonFatalFailureInSetUpTest.FailureInSetUp
|
||||
[0;31m[ FAILED ] [mFatalFailureInSetUpTest.FailureInSetUp
|
||||
[0;31m[ FAILED ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
[0;31m[ FAILED ] [mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteTest.ThisShouldFail
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteTest.ThisShouldFailToo
|
||||
[0;31m[ FAILED ] [mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||
[0;31m[ FAILED ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
|
||||
[0;31m[ FAILED ] [mTEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
|
||||
[0;31m[ FAILED ] [mExpectNonfatalFailureTest.FailsWhenThereIsNoNonfatalFailure
|
||||
|
|
@ -1084,20 +957,14 @@ Stack trace: (omitted)
|
|||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectFatalFailure
|
||||
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectNonFatalFailure
|
||||
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
|
||||
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
|
||||
57 FAILED TESTS
|
||||
50 FAILED TESTS
|
||||
[0;33m YOU HAVE 1 DISABLED TEST
|
||||
|
||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
[==========] Running 4 tests from 2 test suites.
|
||||
[==========] Running 4 tests from 2 test cases.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 3 tests from FatalFailureTest
|
||||
[ RUN ] FatalFailureTest.FatalFailureInSubroutine
|
||||
|
|
@ -1150,7 +1017,7 @@ Stack trace: (omitted)
|
|||
[----------] 1 test from LoggingTest (? ms total)
|
||||
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 4 tests from 2 test suites ran. (? ms total)
|
||||
[==========] 4 tests from 2 test cases ran. (? ms total)
|
||||
[ PASSED ] 0 tests.
|
||||
[ FAILED ] 4 tests, listed below:
|
||||
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
|
||||
|
|
@ -1160,21 +1027,21 @@ Stack trace: (omitted)
|
|||
|
||||
4 FAILED TESTS
|
||||
Note: Google Test filter = *DISABLED_*
|
||||
[==========] Running 1 test from 1 test suite.
|
||||
[==========] Running 1 test from 1 test case.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 1 test from DisabledTestsWarningTest
|
||||
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 1 test from 1 test suite ran.
|
||||
[==========] 1 test from 1 test case ran.
|
||||
[ PASSED ] 1 test.
|
||||
Note: Google Test filter = PassingTest.*
|
||||
Note: This is test shard 2 of 2.
|
||||
[==========] Running 1 test from 1 test suite.
|
||||
[==========] Running 1 test from 1 test case.
|
||||
[----------] Global test environment set-up.
|
||||
[----------] 1 test from PassingTest
|
||||
[ RUN ] PassingTest.PassingTest2
|
||||
[ OK ] PassingTest.PassingTest2
|
||||
[----------] Global test environment tear-down
|
||||
[==========] 1 test from 1 test suite ran.
|
||||
[==========] 1 test from 1 test case ran.
|
||||
[ PASSED ] 1 test.
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
r"""Tests the text output of Google C++ Testing and Mocking Framework.
|
||||
"""Tests the text output of Google C++ Testing and Mocking Framework.
|
||||
|
||||
To update the golden file:
|
||||
googletest_output_test.py --build_dir=BUILD/DIR --gengolden
|
||||
|
|
@ -55,6 +55,7 @@ NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'
|
|||
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
|
||||
# FIXME: remove the _lin suffix.
|
||||
GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'
|
||||
|
||||
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')
|
||||
|
|
@ -286,7 +287,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
|
|||
# sequences when we read the golden file irrespective of an operating
|
||||
# system used. Therefore, we need to strip those \r's from newlines
|
||||
# unconditionally.
|
||||
golden = ToUnixLineEnding(golden_file.read().decode())
|
||||
golden = ToUnixLineEnding(golden_file.read())
|
||||
golden_file.close()
|
||||
|
||||
# We want the test to pass regardless of certain features being
|
||||
|
|
@ -331,7 +332,7 @@ if __name__ == '__main__':
|
|||
if CAN_GENERATE_GOLDEN_FILE:
|
||||
output = GetOutputOfAllCommands()
|
||||
golden_file = open(GOLDEN_PATH, 'wb')
|
||||
golden_file.write(output.encode())
|
||||
golden_file.write(output)
|
||||
golden_file.close()
|
||||
else:
|
||||
message = (
|
||||
|
|
|
|||
|
|
@ -92,17 +92,9 @@ TEST_P(FailingParamTest, Fails) {
|
|||
|
||||
// This generates a test which will fail. Google Test is expected to print
|
||||
// its parameter when it outputs the list of all failed tests.
|
||||
INSTANTIATE_TEST_SUITE_P(PrintingFailingParams,
|
||||
FailingParamTest,
|
||||
testing::Values(2));
|
||||
|
||||
// Tests that an empty value for the test suite basename yields just
|
||||
// the test name without any prior /
|
||||
class EmptyBasenameParamInst : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(EmptyBasenameParamInst, Passes) { EXPECT_EQ(1, GetParam()); }
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(, EmptyBasenameParamInst, testing::Values(1));
|
||||
INSTANTIATE_TEST_CASE_P(PrintingFailingParams,
|
||||
FailingParamTest,
|
||||
testing::Values(2));
|
||||
|
||||
static const char kGoldenString[] = "\"Line\0 1\"\nLine 2";
|
||||
|
||||
|
|
@ -182,7 +174,7 @@ TEST(SCOPED_TRACETest, AcceptedValues) {
|
|||
SCOPED_TRACE("literal string");
|
||||
SCOPED_TRACE(std::string("std::string"));
|
||||
SCOPED_TRACE(1337); // streamable type
|
||||
const char* null_value = nullptr;
|
||||
const char* null_value = NULL;
|
||||
SCOPED_TRACE(null_value);
|
||||
|
||||
ADD_FAILURE() << "Just checking that all these values work fine.";
|
||||
|
|
@ -314,8 +306,9 @@ TEST(SCOPED_TRACETest, WorksConcurrently) {
|
|||
printf("(expecting 6 failures)\n");
|
||||
|
||||
CheckPoints check_points;
|
||||
ThreadWithParam<CheckPoints*> thread(&ThreadWithScopedTrace, &check_points,
|
||||
nullptr);
|
||||
ThreadWithParam<CheckPoints*> thread(&ThreadWithScopedTrace,
|
||||
&check_points,
|
||||
NULL);
|
||||
check_points.n1.WaitForNotification();
|
||||
|
||||
{
|
||||
|
|
@ -372,13 +365,15 @@ class NonFatalFailureInFixtureConstructorTest : public testing::Test {
|
|||
ADD_FAILURE() << "Expected failure #1, in the test fixture c'tor.";
|
||||
}
|
||||
|
||||
~NonFatalFailureInFixtureConstructorTest() override {
|
||||
~NonFatalFailureInFixtureConstructorTest() {
|
||||
ADD_FAILURE() << "Expected failure #5, in the test fixture d'tor.";
|
||||
}
|
||||
|
||||
void SetUp() override { ADD_FAILURE() << "Expected failure #2, in SetUp()."; }
|
||||
virtual void SetUp() {
|
||||
ADD_FAILURE() << "Expected failure #2, in SetUp().";
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
ADD_FAILURE() << "Expected failure #4, in TearDown.";
|
||||
}
|
||||
};
|
||||
|
|
@ -395,17 +390,17 @@ class FatalFailureInFixtureConstructorTest : public testing::Test {
|
|||
Init();
|
||||
}
|
||||
|
||||
~FatalFailureInFixtureConstructorTest() override {
|
||||
~FatalFailureInFixtureConstructorTest() {
|
||||
ADD_FAILURE() << "Expected failure #2, in the test fixture d'tor.";
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
ADD_FAILURE() << "UNEXPECTED failure in SetUp(). "
|
||||
<< "We should never get here, as the test fixture c'tor "
|
||||
<< "had a fatal failure.";
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
ADD_FAILURE() << "UNEXPECTED failure in TearDown(). "
|
||||
<< "We should never get here, as the test fixture c'tor "
|
||||
<< "had a fatal failure.";
|
||||
|
|
@ -426,15 +421,18 @@ TEST_F(FatalFailureInFixtureConstructorTest, FailureInConstructor) {
|
|||
// Tests non-fatal failures in SetUp().
|
||||
class NonFatalFailureInSetUpTest : public testing::Test {
|
||||
protected:
|
||||
~NonFatalFailureInSetUpTest() override { Deinit(); }
|
||||
virtual ~NonFatalFailureInSetUpTest() {
|
||||
Deinit();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
printf("(expecting 4 failures)\n");
|
||||
ADD_FAILURE() << "Expected failure #1, in SetUp().";
|
||||
}
|
||||
|
||||
void TearDown() override { FAIL() << "Expected failure #3, in TearDown()."; }
|
||||
|
||||
virtual void TearDown() {
|
||||
FAIL() << "Expected failure #3, in TearDown().";
|
||||
}
|
||||
private:
|
||||
void Deinit() {
|
||||
FAIL() << "Expected failure #4, in the test fixture d'tor.";
|
||||
|
|
@ -448,15 +446,18 @@ TEST_F(NonFatalFailureInSetUpTest, FailureInSetUp) {
|
|||
// Tests fatal failures in SetUp().
|
||||
class FatalFailureInSetUpTest : public testing::Test {
|
||||
protected:
|
||||
~FatalFailureInSetUpTest() override { Deinit(); }
|
||||
virtual ~FatalFailureInSetUpTest() {
|
||||
Deinit();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
printf("(expecting 3 failures)\n");
|
||||
FAIL() << "Expected failure #1, in SetUp().";
|
||||
}
|
||||
|
||||
void TearDown() override { FAIL() << "Expected failure #2, in TearDown()."; }
|
||||
|
||||
virtual void TearDown() {
|
||||
FAIL() << "Expected failure #2, in TearDown().";
|
||||
}
|
||||
private:
|
||||
void Deinit() {
|
||||
FAIL() << "Expected failure #3, in the test fixture d'tor.";
|
||||
|
|
@ -469,55 +470,109 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) {
|
|||
}
|
||||
|
||||
TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
|
||||
ADD_FAILURE_AT("foo.cc", 42) << "Expected nonfatal failure in foo.cc";
|
||||
ADD_FAILURE_AT("foo.cc", 42) << "Expected failure in foo.cc";
|
||||
}
|
||||
|
||||
TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
|
||||
GTEST_FAIL_AT("foo.cc", 42) << "Expected fatal failure in foo.cc";
|
||||
#if GTEST_IS_THREADSAFE
|
||||
|
||||
// A unary function that may die.
|
||||
void DieIf(bool should_die) {
|
||||
GTEST_CHECK_(!should_die) << " - death inside DieIf().";
|
||||
}
|
||||
|
||||
// The MixedUpTestSuiteTest test case verifies that Google Test will fail a
|
||||
// Tests running death tests in a multi-threaded context.
|
||||
|
||||
// Used for coordination between the main and the spawn thread.
|
||||
struct SpawnThreadNotifications {
|
||||
SpawnThreadNotifications() {}
|
||||
|
||||
Notification spawn_thread_started;
|
||||
Notification spawn_thread_ok_to_terminate;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SpawnThreadNotifications);
|
||||
};
|
||||
|
||||
// The function to be executed in the thread spawn by the
|
||||
// MultipleThreads test (below).
|
||||
static void ThreadRoutine(SpawnThreadNotifications* notifications) {
|
||||
// Signals the main thread that this thread has started.
|
||||
notifications->spawn_thread_started.Notify();
|
||||
|
||||
// Waits for permission to finish from the main thread.
|
||||
notifications->spawn_thread_ok_to_terminate.WaitForNotification();
|
||||
}
|
||||
|
||||
// This is a death-test test, but it's not named with a DeathTest
|
||||
// suffix. It starts threads which might interfere with later
|
||||
// death tests, so it must run after all other death tests.
|
||||
class DeathTestAndMultiThreadsTest : public testing::Test {
|
||||
protected:
|
||||
// Starts a thread and waits for it to begin.
|
||||
virtual void SetUp() {
|
||||
thread_.reset(new ThreadWithParam<SpawnThreadNotifications*>(
|
||||
&ThreadRoutine, ¬ifications_, NULL));
|
||||
notifications_.spawn_thread_started.WaitForNotification();
|
||||
}
|
||||
// Tells the thread to finish, and reaps it.
|
||||
// Depending on the version of the thread library in use,
|
||||
// a manager thread might still be left running that will interfere
|
||||
// with later death tests. This is unfortunate, but this class
|
||||
// cleans up after itself as best it can.
|
||||
virtual void TearDown() {
|
||||
notifications_.spawn_thread_ok_to_terminate.Notify();
|
||||
}
|
||||
|
||||
private:
|
||||
SpawnThreadNotifications notifications_;
|
||||
testing::internal::scoped_ptr<ThreadWithParam<SpawnThreadNotifications*> >
|
||||
thread_;
|
||||
};
|
||||
|
||||
#endif // GTEST_IS_THREADSAFE
|
||||
|
||||
// The MixedUpTestCaseTest test case verifies that Google Test will fail a
|
||||
// test if it uses a different fixture class than what other tests in
|
||||
// the same test case use. It deliberately contains two fixture
|
||||
// classes with the same name but defined in different namespaces.
|
||||
|
||||
// The MixedUpTestSuiteWithSameTestNameTest test case verifies that
|
||||
// The MixedUpTestCaseWithSameTestNameTest test case verifies that
|
||||
// when the user defines two tests with the same test case name AND
|
||||
// same test name (but in different namespaces), the second test will
|
||||
// fail.
|
||||
|
||||
namespace foo {
|
||||
|
||||
class MixedUpTestSuiteTest : public testing::Test {
|
||||
class MixedUpTestCaseTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(MixedUpTestSuiteTest, FirstTestFromNamespaceFoo) {}
|
||||
TEST_F(MixedUpTestSuiteTest, SecondTestFromNamespaceFoo) {}
|
||||
TEST_F(MixedUpTestCaseTest, FirstTestFromNamespaceFoo) {}
|
||||
TEST_F(MixedUpTestCaseTest, SecondTestFromNamespaceFoo) {}
|
||||
|
||||
class MixedUpTestSuiteWithSameTestNameTest : public testing::Test {
|
||||
class MixedUpTestCaseWithSameTestNameTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(MixedUpTestSuiteWithSameTestNameTest,
|
||||
TEST_F(MixedUpTestCaseWithSameTestNameTest,
|
||||
TheSecondTestWithThisNameShouldFail) {}
|
||||
|
||||
} // namespace foo
|
||||
|
||||
namespace bar {
|
||||
|
||||
class MixedUpTestSuiteTest : public testing::Test {
|
||||
class MixedUpTestCaseTest : public testing::Test {
|
||||
};
|
||||
|
||||
// The following two tests are expected to fail. We rely on the
|
||||
// golden file to check that Google Test generates the right error message.
|
||||
TEST_F(MixedUpTestSuiteTest, ThisShouldFail) {}
|
||||
TEST_F(MixedUpTestSuiteTest, ThisShouldFailToo) {}
|
||||
TEST_F(MixedUpTestCaseTest, ThisShouldFail) {}
|
||||
TEST_F(MixedUpTestCaseTest, ThisShouldFailToo) {}
|
||||
|
||||
class MixedUpTestSuiteWithSameTestNameTest : public testing::Test {
|
||||
class MixedUpTestCaseWithSameTestNameTest : public testing::Test {
|
||||
};
|
||||
|
||||
// Expected to fail. We rely on the golden file to check that Google Test
|
||||
// generates the right error message.
|
||||
TEST_F(MixedUpTestSuiteWithSameTestNameTest,
|
||||
TEST_F(MixedUpTestCaseWithSameTestNameTest,
|
||||
TheSecondTestWithThisNameShouldFail) {}
|
||||
|
||||
} // namespace bar
|
||||
|
|
@ -728,27 +783,19 @@ TEST_P(ParamTest, Failure) {
|
|||
EXPECT_EQ("b", GetParam()) << "Expected failure";
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PrintingStrings,
|
||||
ParamTest,
|
||||
testing::Values(std::string("a")),
|
||||
ParamNameFunc);
|
||||
INSTANTIATE_TEST_CASE_P(PrintingStrings,
|
||||
ParamTest,
|
||||
testing::Values(std::string("a")),
|
||||
ParamNameFunc);
|
||||
|
||||
// The case where a suite has INSTANTIATE_TEST_SUITE_P but not TEST_P.
|
||||
using NoTests = ParamTest;
|
||||
INSTANTIATE_TEST_SUITE_P(ThisIsOdd, NoTests, ::testing::Values("Hello"));
|
||||
|
||||
// fails under kErrorOnUninstantiatedParameterizedTest=true
|
||||
class DetectNotInstantiatedTest : public testing::TestWithParam<int> {};
|
||||
TEST_P(DetectNotInstantiatedTest, Used) { }
|
||||
|
||||
// This would make the test failure from the above go away.
|
||||
// INSTANTIATE_TEST_SUITE_P(Fix, DetectNotInstantiatedTest, testing::Values(1));
|
||||
// This #ifdef block tests the output of typed tests.
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
|
||||
template <typename T>
|
||||
class TypedTest : public testing::Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(TypedTest, testing::Types<int>);
|
||||
TYPED_TEST_CASE(TypedTest, testing::Types<int>);
|
||||
|
||||
TYPED_TEST(TypedTest, Success) {
|
||||
EXPECT_EQ(0, TypeParam());
|
||||
|
|
@ -767,24 +814,29 @@ class TypedTestNames {
|
|||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (std::is_same<T, char>::value)
|
||||
if (testing::internal::IsSame<T, char>::value)
|
||||
return std::string("char") + ::testing::PrintToString(i);
|
||||
if (std::is_same<T, int>::value)
|
||||
if (testing::internal::IsSame<T, int>::value)
|
||||
return std::string("int") + ::testing::PrintToString(i);
|
||||
}
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames);
|
||||
TYPED_TEST_CASE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames);
|
||||
|
||||
TYPED_TEST(TypedTestWithNames, Success) {}
|
||||
|
||||
TYPED_TEST(TypedTestWithNames, Failure) { FAIL(); }
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// This #ifdef block tests the output of type-parameterized tests.
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
template <typename T>
|
||||
class TypedTestP : public testing::Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(TypedTestP);
|
||||
TYPED_TEST_CASE_P(TypedTestP);
|
||||
|
||||
TYPED_TEST_P(TypedTestP, Success) {
|
||||
EXPECT_EQ(0U, TypeParam());
|
||||
|
|
@ -794,41 +846,28 @@ TYPED_TEST_P(TypedTestP, Failure) {
|
|||
EXPECT_EQ(1U, TypeParam()) << "Expected failure";
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypedTestP, Success, Failure);
|
||||
REGISTER_TYPED_TEST_CASE_P(TypedTestP, Success, Failure);
|
||||
|
||||
typedef testing::Types<unsigned char, unsigned int> UnsignedTypes;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Unsigned, TypedTestP, UnsignedTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Unsigned, TypedTestP, UnsignedTypes);
|
||||
|
||||
class TypedTestPNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (std::is_same<T, unsigned char>::value) {
|
||||
if (testing::internal::IsSame<T, unsigned char>::value) {
|
||||
return std::string("unsignedChar") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (std::is_same<T, unsigned int>::value) {
|
||||
if (testing::internal::IsSame<T, unsigned int>::value) {
|
||||
return std::string("unsignedInt") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
|
||||
TypedTestPNames);
|
||||
|
||||
template <typename T>
|
||||
class DetectNotInstantiatedTypesTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest);
|
||||
TYPED_TEST_P(DetectNotInstantiatedTypesTest, Used) {
|
||||
TypeParam instantiate;
|
||||
(void)instantiate;
|
||||
}
|
||||
REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used);
|
||||
|
||||
// kErrorOnUninstantiatedTypeParameterizedTest=true would make the above fail.
|
||||
// Adding the following would make that test failure go away.
|
||||
//
|
||||
// typedef ::testing::Types<char, int, unsigned int> MyTypes;
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(All, DetectNotInstantiatedTypesTest, MyTypes);
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
|
|
@ -838,6 +877,8 @@ REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used);
|
|||
TEST(ADeathTest, ShouldRunFirst) {
|
||||
}
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST
|
||||
|
||||
// We rely on the golden file to verify that typed tests whose test
|
||||
// case name ends with DeathTest are run first.
|
||||
|
||||
|
|
@ -846,11 +887,15 @@ class ATypedDeathTest : public testing::Test {
|
|||
};
|
||||
|
||||
typedef testing::Types<int, double> NumericTypes;
|
||||
TYPED_TEST_SUITE(ATypedDeathTest, NumericTypes);
|
||||
TYPED_TEST_CASE(ATypedDeathTest, NumericTypes);
|
||||
|
||||
TYPED_TEST(ATypedDeathTest, ShouldRunFirst) {
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
|
||||
// We rely on the golden file to verify that type-parameterized tests
|
||||
// whose test case name ends with DeathTest are run first.
|
||||
|
|
@ -859,14 +904,16 @@ template <typename T>
|
|||
class ATypeParamDeathTest : public testing::Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(ATypeParamDeathTest);
|
||||
TYPED_TEST_CASE_P(ATypeParamDeathTest);
|
||||
|
||||
TYPED_TEST_P(ATypeParamDeathTest, ShouldRunFirst) {
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(ATypeParamDeathTest, ShouldRunFirst);
|
||||
REGISTER_TYPED_TEST_CASE_P(ATypeParamDeathTest, ShouldRunFirst);
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, ATypeParamDeathTest, NumericTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes);
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
|
|
@ -919,7 +966,7 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
|
|||
class ExpectFailureWithThreadsTest : public ExpectFailureTest {
|
||||
protected:
|
||||
static void AddFailureInOtherThread(FailureMode failure) {
|
||||
ThreadWithParam<FailureMode> thread(&AddFailure, failure, nullptr);
|
||||
ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
|
||||
thread.Join();
|
||||
}
|
||||
};
|
||||
|
|
@ -987,64 +1034,16 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
|
|||
"Some other non-fatal failure.");
|
||||
}
|
||||
|
||||
class DynamicFixture : public testing::Test {
|
||||
protected:
|
||||
DynamicFixture() { printf("DynamicFixture()\n"); }
|
||||
~DynamicFixture() override { printf("~DynamicFixture()\n"); }
|
||||
void SetUp() override { printf("DynamicFixture::SetUp\n"); }
|
||||
void TearDown() override { printf("DynamicFixture::TearDown\n"); }
|
||||
|
||||
static void SetUpTestSuite() { printf("DynamicFixture::SetUpTestSuite\n"); }
|
||||
static void TearDownTestSuite() {
|
||||
printf("DynamicFixture::TearDownTestSuite\n");
|
||||
}
|
||||
};
|
||||
|
||||
template <bool Pass>
|
||||
class DynamicTest : public DynamicFixture {
|
||||
public:
|
||||
void TestBody() override { EXPECT_TRUE(Pass); }
|
||||
};
|
||||
|
||||
auto dynamic_test = (
|
||||
// Register two tests with the same fixture correctly.
|
||||
testing::RegisterTest(
|
||||
"DynamicFixture", "DynamicTestPass", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest(
|
||||
"DynamicFixture", "DynamicTestFail", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<false>; }),
|
||||
|
||||
// Register the same fixture with another name. That's fine.
|
||||
testing::RegisterTest(
|
||||
"DynamicFixtureAnotherName", "DynamicTestPass", nullptr, nullptr,
|
||||
__FILE__, __LINE__,
|
||||
[]() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
|
||||
// Register two tests with the same fixture incorrectly.
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture1", "FixtureBase", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture1", "TestBase", nullptr, nullptr, __FILE__, __LINE__,
|
||||
[]() -> testing::Test* { return new DynamicTest<true>; }),
|
||||
|
||||
// Register two tests with the same fixture incorrectly by omitting the
|
||||
// return type.
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture2", "FixtureBase", nullptr, nullptr, __FILE__,
|
||||
__LINE__, []() -> DynamicFixture* { return new DynamicTest<true>; }),
|
||||
testing::RegisterTest("BadDynamicFixture2", "Derived", nullptr, nullptr,
|
||||
__FILE__, __LINE__,
|
||||
[]() { return new DynamicTest<true>; }));
|
||||
|
||||
// Two test environments for testing testing::AddGlobalTestEnvironment().
|
||||
|
||||
class FooEnvironment : public testing::Environment {
|
||||
public:
|
||||
void SetUp() override { printf("%s", "FooEnvironment::SetUp() called.\n"); }
|
||||
virtual void SetUp() {
|
||||
printf("%s", "FooEnvironment::SetUp() called.\n");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
printf("%s", "FooEnvironment::TearDown() called.\n");
|
||||
FAIL() << "Expected fatal failure.";
|
||||
}
|
||||
|
|
@ -1052,9 +1051,11 @@ class FooEnvironment : public testing::Environment {
|
|||
|
||||
class BarEnvironment : public testing::Environment {
|
||||
public:
|
||||
void SetUp() override { printf("%s", "BarEnvironment::SetUp() called.\n"); }
|
||||
virtual void SetUp() {
|
||||
printf("%s", "BarEnvironment::SetUp() called.\n");
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
printf("%s", "BarEnvironment::TearDown() called.\n");
|
||||
ADD_FAILURE() << "Expected non-fatal failure.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ class DummyTest : public ::testing::TestWithParam<const char *> {};
|
|||
TEST_P(DummyTest, Dummy) {
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(InvalidTestName,
|
||||
DummyTest,
|
||||
::testing::Values("InvalidWithQuotes"),
|
||||
::testing::PrintToStringParamName());
|
||||
INSTANTIATE_TEST_CASE_P(InvalidTestName,
|
||||
DummyTest,
|
||||
::testing::Values("InvalidWithQuotes"),
|
||||
::testing::PrintToStringParamName());
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ std::string StringParamTestSuffix(
|
|||
TEST_P(DummyTest, Dummy) {
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DuplicateTestNames,
|
||||
DummyTest,
|
||||
::testing::Values("a", "b", "a", "c"),
|
||||
StringParamTestSuffix);
|
||||
INSTANTIATE_TEST_CASE_P(DuplicateTestNames,
|
||||
DummyTest,
|
||||
::testing::Values("a", "b", "a", "c"),
|
||||
StringParamTestSuffix);
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
# include <algorithm>
|
||||
# include <iostream>
|
||||
# include <list>
|
||||
# include <set>
|
||||
# include <sstream>
|
||||
# include <string>
|
||||
# include <vector>
|
||||
|
|
@ -50,13 +49,19 @@ using ::std::sort;
|
|||
|
||||
using ::testing::AddGlobalTestEnvironment;
|
||||
using ::testing::Bool;
|
||||
using ::testing::Combine;
|
||||
using ::testing::Message;
|
||||
using ::testing::Range;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
using ::testing::ValuesIn;
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
using ::testing::Combine;
|
||||
using ::testing::get;
|
||||
using ::testing::make_tuple;
|
||||
using ::testing::tuple;
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
using ::testing::internal::ParamGenerator;
|
||||
using ::testing::internal::UnitTestOptions;
|
||||
|
||||
|
|
@ -68,9 +73,49 @@ using ::testing::internal::UnitTestOptions;
|
|||
// EXPECT_THAT() and the matchers know how to print tuples.
|
||||
template <typename T>
|
||||
::std::string PrintValue(const T& value) {
|
||||
return testing::PrintToString(value);
|
||||
::std::stringstream stream;
|
||||
stream << value;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
|
||||
// These overloads allow printing tuples in our tests. We cannot
|
||||
// define an operator<< for tuples, as that definition needs to be in
|
||||
// the std namespace in order to be picked up by Google Test via
|
||||
// Argument-Dependent Lookup, yet defining anything in the std
|
||||
// namespace in non-STL code is undefined behavior.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
::std::string PrintValue(const tuple<T1, T2>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
::std::string PrintValue(const tuple<T1, T2, T3>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value)
|
||||
<< ", "<< get<2>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
::std::string PrintValue(
|
||||
const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value)
|
||||
<< ", "<< get<2>(value) << ", " << get<3>(value)
|
||||
<< ", "<< get<4>(value) << ", " << get<5>(value)
|
||||
<< ", "<< get<6>(value) << ", " << get<7>(value)
|
||||
<< ", "<< get<8>(value) << ", " << get<9>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
// Verifies that a sequence generated by the generator and accessed
|
||||
// via the iterator object matches the expected one using Google Test
|
||||
// assertions.
|
||||
|
|
@ -405,28 +450,31 @@ TEST(BoolTest, BoolWorks) {
|
|||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
|
||||
// Tests that Combine() with two parameters generates the expected sequence.
|
||||
TEST(CombineTest, CombineWithTwoParameters) {
|
||||
const char* foo = "foo";
|
||||
const char* bar = "bar";
|
||||
const ParamGenerator<std::tuple<const char*, int> > gen =
|
||||
const ParamGenerator<tuple<const char*, int> > gen =
|
||||
Combine(Values(foo, bar), Values(3, 4));
|
||||
|
||||
std::tuple<const char*, int> expected_values[] = {
|
||||
std::make_tuple(foo, 3), std::make_tuple(foo, 4), std::make_tuple(bar, 3),
|
||||
std::make_tuple(bar, 4)};
|
||||
tuple<const char*, int> expected_values[] = {
|
||||
make_tuple(foo, 3), make_tuple(foo, 4),
|
||||
make_tuple(bar, 3), make_tuple(bar, 4)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
// Tests that Combine() with three parameters generates the expected sequence.
|
||||
TEST(CombineTest, CombineWithThreeParameters) {
|
||||
const ParamGenerator<std::tuple<int, int, int> > gen =
|
||||
Combine(Values(0, 1), Values(3, 4), Values(5, 6));
|
||||
std::tuple<int, int, int> expected_values[] = {
|
||||
std::make_tuple(0, 3, 5), std::make_tuple(0, 3, 6),
|
||||
std::make_tuple(0, 4, 5), std::make_tuple(0, 4, 6),
|
||||
std::make_tuple(1, 3, 5), std::make_tuple(1, 3, 6),
|
||||
std::make_tuple(1, 4, 5), std::make_tuple(1, 4, 6)};
|
||||
const ParamGenerator<tuple<int, int, int> > gen = Combine(Values(0, 1),
|
||||
Values(3, 4),
|
||||
Values(5, 6));
|
||||
tuple<int, int, int> expected_values[] = {
|
||||
make_tuple(0, 3, 5), make_tuple(0, 3, 6),
|
||||
make_tuple(0, 4, 5), make_tuple(0, 4, 6),
|
||||
make_tuple(1, 3, 5), make_tuple(1, 3, 6),
|
||||
make_tuple(1, 4, 5), make_tuple(1, 4, 6)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
|
|
@ -434,11 +482,10 @@ TEST(CombineTest, CombineWithThreeParameters) {
|
|||
// sequence generates a sequence with the number of elements equal to the
|
||||
// number of elements in the sequence generated by the second parameter.
|
||||
TEST(CombineTest, CombineWithFirstParameterSingleValue) {
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(42), Values(0, 1));
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(42),
|
||||
Values(0, 1));
|
||||
|
||||
std::tuple<int, int> expected_values[] = {std::make_tuple(42, 0),
|
||||
std::make_tuple(42, 1)};
|
||||
tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
|
|
@ -446,27 +493,26 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
|
|||
// sequence generates a sequence with the number of elements equal to the
|
||||
// number of elements in the sequence generated by the first parameter.
|
||||
TEST(CombineTest, CombineWithSecondParameterSingleValue) {
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(0, 1), Values(42));
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
|
||||
Values(42));
|
||||
|
||||
std::tuple<int, int> expected_values[] = {std::make_tuple(0, 42),
|
||||
std::make_tuple(1, 42)};
|
||||
tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
// Tests that when the first parameter produces an empty sequence,
|
||||
// Combine() produces an empty sequence, too.
|
||||
TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Range(0, 0), Values(0, 1));
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Range(0, 0),
|
||||
Values(0, 1));
|
||||
VerifyGeneratorIsEmpty(gen);
|
||||
}
|
||||
|
||||
// Tests that when the second parameter produces an empty sequence,
|
||||
// Combine() produces an empty sequence, too.
|
||||
TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(0, 1), Range(1, 1));
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
|
||||
Range(1, 1));
|
||||
VerifyGeneratorIsEmpty(gen);
|
||||
}
|
||||
|
||||
|
|
@ -475,41 +521,44 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
|
|||
TEST(CombineTest, CombineWithMaxNumberOfParameters) {
|
||||
const char* foo = "foo";
|
||||
const char* bar = "bar";
|
||||
const ParamGenerator<
|
||||
std::tuple<const char*, int, int, int, int, int, int, int, int, int> >
|
||||
gen =
|
||||
Combine(Values(foo, bar), Values(1), Values(2), Values(3), Values(4),
|
||||
Values(5), Values(6), Values(7), Values(8), Values(9));
|
||||
const ParamGenerator<tuple<const char*, int, int, int, int, int, int, int,
|
||||
int, int> > gen = Combine(Values(foo, bar),
|
||||
Values(1), Values(2),
|
||||
Values(3), Values(4),
|
||||
Values(5), Values(6),
|
||||
Values(7), Values(8),
|
||||
Values(9));
|
||||
|
||||
std::tuple<const char*, int, int, int, int, int, int, int, int, int>
|
||||
expected_values[] = {std::make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
|
||||
std::make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
|
||||
tuple<const char*, int, int, int, int, int, int, int, int, int>
|
||||
expected_values[] = {make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
|
||||
make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
class NonDefaultConstructAssignString {
|
||||
public:
|
||||
NonDefaultConstructAssignString(const std::string& s) : str_(s) {}
|
||||
NonDefaultConstructAssignString() = delete;
|
||||
NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) =
|
||||
default;
|
||||
NonDefaultConstructAssignString& operator=(
|
||||
const NonDefaultConstructAssignString&) = delete;
|
||||
~NonDefaultConstructAssignString() = default;
|
||||
|
||||
const std::string& str() const { return str_; }
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
|
||||
// Not default constructible
|
||||
NonDefaultConstructAssignString();
|
||||
// Not assignable
|
||||
void operator=(const NonDefaultConstructAssignString&);
|
||||
};
|
||||
|
||||
TEST(CombineTest, NonDefaultConstructAssign) {
|
||||
const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen =
|
||||
const ParamGenerator<tuple<int, NonDefaultConstructAssignString> > gen =
|
||||
Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"),
|
||||
NonDefaultConstructAssignString("B")));
|
||||
|
||||
ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator
|
||||
it = gen.begin();
|
||||
ParamGenerator<tuple<int, NonDefaultConstructAssignString> >::iterator it =
|
||||
gen.begin();
|
||||
|
||||
EXPECT_EQ(0, std::get<0>(*it));
|
||||
EXPECT_EQ("A", std::get<1>(*it).str());
|
||||
|
|
@ -530,6 +579,8 @@ TEST(CombineTest, NonDefaultConstructAssign) {
|
|||
EXPECT_TRUE(it == gen.end());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
// Tests that an generator produces correct sequence after being
|
||||
// assigned from another generator.
|
||||
|
|
@ -544,12 +595,12 @@ TEST(ParamGeneratorTest, AssignmentWorks) {
|
|||
|
||||
// This test verifies that the tests are expanded and run as specified:
|
||||
// one test per element from the sequence produced by the generator
|
||||
// specified in INSTANTIATE_TEST_SUITE_P. It also verifies that the test's
|
||||
// specified in INSTANTIATE_TEST_CASE_P. It also verifies that the test's
|
||||
// fixture constructor, SetUp(), and TearDown() have run and have been
|
||||
// supplied with the correct parameters.
|
||||
|
||||
// The use of environment object allows detection of the case where no test
|
||||
// case functionality is run at all. In this case TearDownTestSuite will not
|
||||
// case functionality is run at all. In this case TestCaseTearDown will not
|
||||
// be able to detect missing tests, naturally.
|
||||
template <int kExpectedCalls>
|
||||
class TestGenerationEnvironment : public ::testing::Environment {
|
||||
|
|
@ -564,7 +615,7 @@ class TestGenerationEnvironment : public ::testing::Environment {
|
|||
void TearDownExecuted() { tear_down_count_++; }
|
||||
void TestBodyExecuted() { test_body_count_++; }
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// If all MultipleTestGenerationTest tests have been de-selected
|
||||
// by the filter flag, the following checks make no sense.
|
||||
bool perform_check = false;
|
||||
|
|
@ -621,16 +672,16 @@ class TestGenerationTest : public TestWithParam<int> {
|
|||
Environment::Instance()->FixtureConstructorExecuted();
|
||||
current_parameter_ = GetParam();
|
||||
}
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
Environment::Instance()->SetUpExecuted();
|
||||
EXPECT_EQ(current_parameter_, GetParam());
|
||||
}
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
Environment::Instance()->TearDownExecuted();
|
||||
EXPECT_EQ(current_parameter_, GetParam());
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
static void SetUpTestCase() {
|
||||
bool all_tests_in_test_case_selected = true;
|
||||
|
||||
for (int i = 0; i < PARAMETER_COUNT; ++i) {
|
||||
|
|
@ -651,7 +702,7 @@ class TestGenerationTest : public TestWithParam<int> {
|
|||
collected_parameters_.clear();
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
vector<int> expected_values(test_generation_params,
|
||||
test_generation_params + PARAMETER_COUNT);
|
||||
// Test execution order is not guaranteed by Google Test,
|
||||
|
|
@ -677,17 +728,17 @@ TEST_P(TestGenerationTest, TestsExpandedAndRun) {
|
|||
EXPECT_EQ(current_parameter_, GetParam());
|
||||
collected_parameters_.push_back(GetParam());
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(TestExpansionModule, TestGenerationTest,
|
||||
ValuesIn(test_generation_params));
|
||||
INSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest,
|
||||
ValuesIn(test_generation_params));
|
||||
|
||||
// This test verifies that the element sequence (third parameter of
|
||||
// INSTANTIATE_TEST_SUITE_P) is evaluated in InitGoogleTest() and neither at
|
||||
// the call site of INSTANTIATE_TEST_SUITE_P nor in RUN_ALL_TESTS(). For
|
||||
// INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at
|
||||
// the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For
|
||||
// that, we declare param_value_ to be a static member of
|
||||
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in
|
||||
// main(), just before invocation of InitGoogleTest(). After calling
|
||||
// InitGoogleTest(), we set the value to 2. If the sequence is evaluated
|
||||
// before or after InitGoogleTest, INSTANTIATE_TEST_SUITE_P will create a
|
||||
// before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a
|
||||
// test with parameter other than 1, and the test body will fail the
|
||||
// assertion.
|
||||
class GeneratorEvaluationTest : public TestWithParam<int> {
|
||||
|
|
@ -703,8 +754,9 @@ int GeneratorEvaluationTest::param_value_ = 0;
|
|||
TEST_P(GeneratorEvaluationTest, GeneratorsEvaluatedInMain) {
|
||||
EXPECT_EQ(1, GetParam());
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(GenEvalModule, GeneratorEvaluationTest,
|
||||
Values(GeneratorEvaluationTest::param_value()));
|
||||
INSTANTIATE_TEST_CASE_P(GenEvalModule,
|
||||
GeneratorEvaluationTest,
|
||||
Values(GeneratorEvaluationTest::param_value()));
|
||||
|
||||
// Tests that generators defined in a different translation unit are
|
||||
// functional. Generator extern_gen is defined in gtest-param-test_test2.cc.
|
||||
|
|
@ -715,8 +767,9 @@ TEST_P(ExternalGeneratorTest, ExternalGenerator) {
|
|||
// which we verify here.
|
||||
EXPECT_EQ(GetParam(), 33);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(ExternalGeneratorModule, ExternalGeneratorTest,
|
||||
extern_gen);
|
||||
INSTANTIATE_TEST_CASE_P(ExternalGeneratorModule,
|
||||
ExternalGeneratorTest,
|
||||
extern_gen);
|
||||
|
||||
// Tests that a parameterized test case can be defined in one translation
|
||||
// unit and instantiated in another. This test will be instantiated in
|
||||
|
|
@ -731,19 +784,20 @@ TEST_P(ExternalInstantiationTest, IsMultipleOf33) {
|
|||
class MultipleInstantiationTest : public TestWithParam<int> {};
|
||||
TEST_P(MultipleInstantiationTest, AllowsMultipleInstances) {
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(Sequence1, MultipleInstantiationTest, Values(1, 2));
|
||||
INSTANTIATE_TEST_SUITE_P(Sequence2, MultipleInstantiationTest, Range(3, 5));
|
||||
INSTANTIATE_TEST_CASE_P(Sequence1, MultipleInstantiationTest, Values(1, 2));
|
||||
INSTANTIATE_TEST_CASE_P(Sequence2, MultipleInstantiationTest, Range(3, 5));
|
||||
|
||||
// Tests that a parameterized test case can be instantiated
|
||||
// in multiple translation units. This test will be instantiated
|
||||
// here and in gtest-param-test_test2.cc.
|
||||
// InstantiationInMultipleTranslationUnitsTest fixture class
|
||||
// is defined in gtest-param-test_test.h.
|
||||
TEST_P(InstantiationInMultipleTranslationUnitsTest, IsMultipleOf42) {
|
||||
TEST_P(InstantiationInMultipleTranslaionUnitsTest, IsMultipleOf42) {
|
||||
EXPECT_EQ(0, GetParam() % 42);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(Sequence1, InstantiationInMultipleTranslationUnitsTest,
|
||||
Values(42, 42 * 2));
|
||||
INSTANTIATE_TEST_CASE_P(Sequence1,
|
||||
InstantiationInMultipleTranslaionUnitsTest,
|
||||
Values(42, 42*2));
|
||||
|
||||
// Tests that each iteration of parameterized test runs in a separate test
|
||||
// object.
|
||||
|
|
@ -751,7 +805,7 @@ class SeparateInstanceTest : public TestWithParam<int> {
|
|||
public:
|
||||
SeparateInstanceTest() : count_(0) {}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
EXPECT_GE(global_count_, 2)
|
||||
<< "If some (but not all) SeparateInstanceTest tests have been "
|
||||
<< "filtered out this test will fail. Make sure that all "
|
||||
|
|
@ -769,20 +823,20 @@ TEST_P(SeparateInstanceTest, TestsRunInSeparateInstances) {
|
|||
EXPECT_EQ(0, count_++);
|
||||
global_count_++;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
|
||||
INSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
|
||||
|
||||
// Tests that all instantiations of a test have named appropriately. Test
|
||||
// defined with TEST_P(TestSuiteName, TestName) and instantiated with
|
||||
// INSTANTIATE_TEST_SUITE_P(SequenceName, TestSuiteName, generator) must be
|
||||
// named SequenceName/TestSuiteName.TestName/i, where i is the 0-based index of
|
||||
// the sequence element used to instantiate the test.
|
||||
// defined with TEST_P(TestCaseName, TestName) and instantiated with
|
||||
// INSTANTIATE_TEST_CASE_P(SequenceName, TestCaseName, generator) must be named
|
||||
// SequenceName/TestCaseName.TestName/i, where i is the 0-based index of the
|
||||
// sequence element used to instantiate the test.
|
||||
class NamingTest : public TestWithParam<int> {};
|
||||
|
||||
TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) {
|
||||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_suite_name());
|
||||
EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name());
|
||||
|
||||
Message index_stream;
|
||||
index_stream << "TestsReportCorrectNamesAndParameters/" << GetParam();
|
||||
|
|
@ -791,7 +845,7 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) {
|
|||
EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
|
||||
INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
|
||||
|
||||
// Tests that macros in test names are expanded correctly.
|
||||
class MacroNamingTest : public TestWithParam<int> {};
|
||||
|
|
@ -803,11 +857,11 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
|
|||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
|
||||
EXPECT_STREQ("FooSomeTestName/0", test_info->name());
|
||||
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name());
|
||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
|
||||
INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42));
|
||||
|
||||
// Tests the same thing for non-parametrized tests.
|
||||
class MacroNamingTestNonParametrized : public ::testing::Test {};
|
||||
|
|
@ -817,40 +871,10 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
|
|||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_suite_name());
|
||||
EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name());
|
||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
||||
}
|
||||
|
||||
TEST(MacroNameing, LookupNames) {
|
||||
std::set<std::string> know_suite_names, know_test_names;
|
||||
|
||||
auto ins = testing::UnitTest::GetInstance();
|
||||
int ts = 0;
|
||||
while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) {
|
||||
know_suite_names.insert(suite->name());
|
||||
|
||||
int ti = 0;
|
||||
while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) {
|
||||
know_test_names.insert(std::string(suite->name()) + "." + info->name());
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the expected form of the test suit name actually exists.
|
||||
EXPECT_NE( //
|
||||
know_suite_names.find("FortyTwo/MacroNamingTest"),
|
||||
know_suite_names.end());
|
||||
EXPECT_NE(
|
||||
know_suite_names.find("MacroNamingTestNonParametrized"),
|
||||
know_suite_names.end());
|
||||
// Check that the expected form of the test name actually exists.
|
||||
EXPECT_NE( //
|
||||
know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"),
|
||||
know_test_names.end());
|
||||
EXPECT_NE(
|
||||
know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"),
|
||||
know_test_names.end());
|
||||
}
|
||||
|
||||
// Tests that user supplied custom parameter names are working correctly.
|
||||
// Runs the test with a builtin helper method which uses PrintToString,
|
||||
// as well as a custom function and custom functor to ensure all possible
|
||||
|
|
@ -864,14 +888,17 @@ struct CustomParamNameFunctor {
|
|||
}
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(CustomParamNameFunctor, CustomFunctorNamingTest,
|
||||
Values(std::string("FunctorName")),
|
||||
CustomParamNameFunctor());
|
||||
INSTANTIATE_TEST_CASE_P(CustomParamNameFunctor,
|
||||
CustomFunctorNamingTest,
|
||||
Values(std::string("FunctorName")),
|
||||
CustomParamNameFunctor());
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(AllAllowedCharacters, CustomFunctorNamingTest,
|
||||
Values("abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "01234567890_"),
|
||||
CustomParamNameFunctor());
|
||||
INSTANTIATE_TEST_CASE_P(AllAllowedCharacters,
|
||||
CustomFunctorNamingTest,
|
||||
Values("abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"01234567890_"),
|
||||
CustomParamNameFunctor());
|
||||
|
||||
inline std::string CustomParamNameFunction(
|
||||
const ::testing::TestParamInfo<std::string>& inf) {
|
||||
|
|
@ -881,41 +908,45 @@ inline std::string CustomParamNameFunction(
|
|||
class CustomFunctionNamingTest : public TestWithParam<std::string> {};
|
||||
TEST_P(CustomFunctionNamingTest, CustomTestNames) {}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(CustomParamNameFunction, CustomFunctionNamingTest,
|
||||
Values(std::string("FunctionName")),
|
||||
CustomParamNameFunction);
|
||||
INSTANTIATE_TEST_CASE_P(CustomParamNameFunction,
|
||||
CustomFunctionNamingTest,
|
||||
Values(std::string("FunctionName")),
|
||||
CustomParamNameFunction);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(CustomParamNameFunctionP, CustomFunctionNamingTest,
|
||||
Values(std::string("FunctionNameP")),
|
||||
&CustomParamNameFunction);
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
// Test custom naming with a lambda
|
||||
|
||||
class CustomLambdaNamingTest : public TestWithParam<std::string> {};
|
||||
TEST_P(CustomLambdaNamingTest, CustomTestNames) {}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(CustomParamNameLambda, CustomLambdaNamingTest,
|
||||
Values(std::string("LambdaName")),
|
||||
[](const ::testing::TestParamInfo<std::string>& inf) {
|
||||
return inf.param;
|
||||
});
|
||||
INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest,
|
||||
Values(std::string("LambdaName")),
|
||||
[](const ::testing::TestParamInfo<std::string>& inf) {
|
||||
return inf.param;
|
||||
});
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
TEST(CustomNamingTest, CheckNameRegistry) {
|
||||
::testing::UnitTest* unit_test = ::testing::UnitTest::GetInstance();
|
||||
std::set<std::string> test_names;
|
||||
for (int suite_num = 0; suite_num < unit_test->total_test_suite_count();
|
||||
++suite_num) {
|
||||
const ::testing::TestSuite* test_suite = unit_test->GetTestSuite(suite_num);
|
||||
for (int test_num = 0; test_num < test_suite->total_test_count();
|
||||
for (int case_num = 0;
|
||||
case_num < unit_test->total_test_case_count();
|
||||
++case_num) {
|
||||
const ::testing::TestCase* test_case = unit_test->GetTestCase(case_num);
|
||||
for (int test_num = 0;
|
||||
test_num < test_case->total_test_count();
|
||||
++test_num) {
|
||||
const ::testing::TestInfo* test_info = test_suite->GetTestInfo(test_num);
|
||||
const ::testing::TestInfo* test_info = test_case->GetTestInfo(test_num);
|
||||
test_names.insert(std::string(test_info->name()));
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctorName"));
|
||||
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionName"));
|
||||
EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionNameP"));
|
||||
#if GTEST_LANG_CXX11
|
||||
EXPECT_EQ(1u, test_names.count("CustomTestNames/LambdaName"));
|
||||
#endif // GTEST_LANG_CXX11
|
||||
}
|
||||
|
||||
// Test a numeric name to ensure PrintToStringParamName works correctly.
|
||||
|
|
@ -930,8 +961,10 @@ TEST_P(CustomIntegerNamingTest, TestsReportCorrectNames) {
|
|||
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PrintToString, CustomIntegerNamingTest, Range(0, 5),
|
||||
::testing::PrintToStringParamName());
|
||||
INSTANTIATE_TEST_CASE_P(PrintToString,
|
||||
CustomIntegerNamingTest,
|
||||
Range(0, 5),
|
||||
::testing::PrintToStringParamName());
|
||||
|
||||
// Test a custom struct with PrintToString.
|
||||
|
||||
|
|
@ -955,9 +988,10 @@ TEST_P(CustomStructNamingTest, TestsReportCorrectNames) {
|
|||
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(PrintToString, CustomStructNamingTest,
|
||||
Values(CustomStruct(0), CustomStruct(1)),
|
||||
::testing::PrintToStringParamName());
|
||||
INSTANTIATE_TEST_CASE_P(PrintToString,
|
||||
CustomStructNamingTest,
|
||||
Values(CustomStruct(0), CustomStruct(1)),
|
||||
::testing::PrintToStringParamName());
|
||||
|
||||
// Test that using a stateful parameter naming function works as expected.
|
||||
|
||||
|
|
@ -986,8 +1020,10 @@ TEST_P(StatefulNamingTest, TestsReportCorrectNames) {
|
|||
EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(StatefulNamingFunctor, StatefulNamingTest, Range(0, 5),
|
||||
StatefulNamingFunctor());
|
||||
INSTANTIATE_TEST_CASE_P(StatefulNamingFunctor,
|
||||
StatefulNamingTest,
|
||||
Range(0, 5),
|
||||
StatefulNamingFunctor());
|
||||
|
||||
// Class that cannot be streamed into an ostream. It needs to be copyable
|
||||
// (and, in case of MSVC, also assignable) in order to be a test parameter
|
||||
|
|
@ -996,8 +1032,6 @@ INSTANTIATE_TEST_SUITE_P(StatefulNamingFunctor, StatefulNamingTest, Range(0, 5),
|
|||
class Unstreamable {
|
||||
public:
|
||||
explicit Unstreamable(int value) : value_(value) {}
|
||||
// -Wunused-private-field: dummy accessor for `value_`.
|
||||
const int& dummy_value() const { return value_; }
|
||||
|
||||
private:
|
||||
int value_;
|
||||
|
|
@ -1012,8 +1046,9 @@ TEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) {
|
|||
EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(InstantiationWithComments, CommentTest,
|
||||
Values(Unstreamable(1)));
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationWithComments,
|
||||
CommentTest,
|
||||
Values(Unstreamable(1)));
|
||||
|
||||
// Verify that we can create a hierarchy of test fixtures, where the base
|
||||
// class fixture is not parameterized and the derived class is. In this case
|
||||
|
|
@ -1053,64 +1088,19 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
|
|||
".* value-parameterized test .*");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(RangeZeroToFive, ParameterizedDerivedTest,
|
||||
Range(0, 5));
|
||||
INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5));
|
||||
|
||||
// Tests param generator working with Enums
|
||||
enum MyEnums {
|
||||
ENUM1 = 1,
|
||||
ENUM2 = 3,
|
||||
ENUM3 = 8,
|
||||
};
|
||||
|
||||
class MyEnumTest : public testing::TestWithParam<MyEnums> {};
|
||||
|
||||
TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
|
||||
INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest,
|
||||
::testing::Values(ENUM1, ENUM2, 0));
|
||||
|
||||
namespace works_here {
|
||||
// Never used not instantiated, this should work.
|
||||
class NotUsedTest : public testing::TestWithParam<int> {};
|
||||
|
||||
///////
|
||||
// Never used not instantiated, this should work.
|
||||
template <typename T>
|
||||
class NotUsedTypeTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(NotUsedTypeTest);
|
||||
|
||||
// Used but not instantiated, this would fail. but...
|
||||
class NotInstantiatedTest : public testing::TestWithParam<int> {};
|
||||
// ... we mark is as allowed.
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest);
|
||||
|
||||
TEST_P(NotInstantiatedTest, Used) { }
|
||||
|
||||
using OtherName = NotInstantiatedTest;
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OtherName);
|
||||
TEST_P(OtherName, Used) { }
|
||||
|
||||
// Used but not instantiated, this would fail. but...
|
||||
template <typename T>
|
||||
class NotInstantiatedTypeTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(NotInstantiatedTypeTest);
|
||||
// ... we mark is as allowed.
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTypeTest);
|
||||
|
||||
TYPED_TEST_P(NotInstantiatedTypeTest, Used) { }
|
||||
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used);
|
||||
} // namespace works_here
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Used in TestGenerationTest test suite.
|
||||
// Used in TestGenerationTest test case.
|
||||
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
|
||||
// Used in GeneratorEvaluationTest test suite. Tests that the updated value
|
||||
// Used in GeneratorEvaluationTest test case. Tests that the updated value
|
||||
// will be picked up for instantiating tests in GeneratorEvaluationTest.
|
||||
GeneratorEvaluationTest::set_param_value(1);
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
// Used in GeneratorEvaluationTest test suite. Tests that value updated
|
||||
// Used in GeneratorEvaluationTest test case. Tests that value updated
|
||||
// here will NOT be used for instantiating tests in
|
||||
// GeneratorEvaluationTest.
|
||||
GeneratorEvaluationTest::set_param_value(2);
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@
|
|||
// This header file provides classes and functions used internally
|
||||
// for testing Google Test itself.
|
||||
|
||||
#ifndef GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
#define GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
#ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
#define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
|
@ -44,8 +44,8 @@ class ExternalInstantiationTest : public ::testing::TestWithParam<int> {
|
|||
|
||||
// Test fixture for testing instantiation of a test in multiple
|
||||
// translation units.
|
||||
class InstantiationInMultipleTranslationUnitsTest
|
||||
class InstantiationInMultipleTranslaionUnitsTest
|
||||
: public ::testing::TestWithParam<int> {
|
||||
};
|
||||
|
||||
#endif // GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
#endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
|
|
|
|||
|
|
@ -46,16 +46,16 @@ ParamGenerator<int> extern_gen = Values(33);
|
|||
// and instantiated in another. The test is defined in
|
||||
// googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
|
||||
// defined in gtest-param-test_test.h.
|
||||
INSTANTIATE_TEST_SUITE_P(MultiplesOf33,
|
||||
ExternalInstantiationTest,
|
||||
Values(33, 66));
|
||||
INSTANTIATE_TEST_CASE_P(MultiplesOf33,
|
||||
ExternalInstantiationTest,
|
||||
Values(33, 66));
|
||||
|
||||
// Tests that a parameterized test case can be instantiated
|
||||
// in multiple translation units. Another instantiation is defined
|
||||
// in googletest-param-test-test.cc and
|
||||
// InstantiationInMultipleTranslationUnitsTest fixture is defined in
|
||||
// InstantiationInMultipleTranslaionUnitsTest fixture is defined in
|
||||
// gtest-param-test_test.h
|
||||
INSTANTIATE_TEST_SUITE_P(Sequence2,
|
||||
InstantiationInMultipleTranslationUnitsTest,
|
||||
Values(42*3, 42*4, 42*5));
|
||||
INSTANTIATE_TEST_CASE_P(Sequence2,
|
||||
InstantiationInMultipleTranslaionUnitsTest,
|
||||
Values(42*3, 42*4, 42*5));
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
#endif // GTEST_OS_MAC
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <utility> // For std::pair and std::make_pair.
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -90,10 +89,10 @@ TEST(IsXDigitTest, ReturnsFalseForWideNonAscii) {
|
|||
|
||||
class Base {
|
||||
public:
|
||||
// Copy constructor and assignment operator do exactly what we need, so we
|
||||
// use them.
|
||||
Base() : member_(0) {}
|
||||
explicit Base(int n) : member_(n) {}
|
||||
Base(const Base&) = default;
|
||||
Base& operator=(const Base&) = default;
|
||||
virtual ~Base() {}
|
||||
int member() { return member_; }
|
||||
|
||||
|
|
@ -201,13 +200,32 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) {
|
|||
EXPECT_TRUE(converted);
|
||||
}
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
TEST(IteratorTraitsTest, WorksForSTLContainerIterators) {
|
||||
StaticAssertTypeEq<int,
|
||||
IteratorTraits< ::std::vector<int>::const_iterator>::value_type>();
|
||||
StaticAssertTypeEq<bool,
|
||||
IteratorTraits< ::std::list<bool>::iterator>::value_type>();
|
||||
}
|
||||
|
||||
TEST(IteratorTraitsTest, WorksForPointerToNonConst) {
|
||||
StaticAssertTypeEq<char, IteratorTraits<char*>::value_type>();
|
||||
StaticAssertTypeEq<const void*, IteratorTraits<const void**>::value_type>();
|
||||
}
|
||||
|
||||
TEST(IteratorTraitsTest, WorksForPointerToConst) {
|
||||
StaticAssertTypeEq<char, IteratorTraits<const char*>::value_type>();
|
||||
StaticAssertTypeEq<const void*,
|
||||
IteratorTraits<const void* const*>::value_type>();
|
||||
}
|
||||
|
||||
// Tests that the element_type typedef is available in scoped_ptr and refers
|
||||
// to the parameter type.
|
||||
TEST(ScopedPtrTest, DefinesElementType) {
|
||||
StaticAssertTypeEq<int, ::testing::internal::scoped_ptr<int>::element_type>();
|
||||
}
|
||||
|
||||
// FIXME: Implement THE REST of scoped_ptr tests.
|
||||
|
||||
TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
|
||||
if (AlwaysFalse())
|
||||
GTEST_CHECK_(false) << "This should never be executed; "
|
||||
|
|
@ -223,9 +241,6 @@ TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
|
|||
else
|
||||
GTEST_CHECK_(true) << "";
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
|
||||
switch (0) {
|
||||
|
|
@ -247,9 +262,9 @@ TEST(FormatFileLocationTest, FormatsFileLocation) {
|
|||
}
|
||||
|
||||
TEST(FormatFileLocationTest, FormatsUnknownFile) {
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "unknown file",
|
||||
FormatFileLocation(nullptr, 42));
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation(nullptr, 42));
|
||||
EXPECT_PRED_FORMAT2(
|
||||
IsSubstring, "unknown file", FormatFileLocation(NULL, 42));
|
||||
EXPECT_PRED_FORMAT2(IsSubstring, "42", FormatFileLocation(NULL, 42));
|
||||
}
|
||||
|
||||
TEST(FormatFileLocationTest, FormatsUknownLine) {
|
||||
|
|
@ -257,7 +272,7 @@ TEST(FormatFileLocationTest, FormatsUknownLine) {
|
|||
}
|
||||
|
||||
TEST(FormatFileLocationTest, FormatsUknownFileAndLine) {
|
||||
EXPECT_EQ("unknown file:", FormatFileLocation(nullptr, -1));
|
||||
EXPECT_EQ("unknown file:", FormatFileLocation(NULL, -1));
|
||||
}
|
||||
|
||||
// Verifies behavior of FormatCompilerIndependentFileLocation.
|
||||
|
|
@ -267,7 +282,7 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsFileLocation) {
|
|||
|
||||
TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFile) {
|
||||
EXPECT_EQ("unknown file:42",
|
||||
FormatCompilerIndependentFileLocation(nullptr, 42));
|
||||
FormatCompilerIndependentFileLocation(NULL, 42));
|
||||
}
|
||||
|
||||
TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) {
|
||||
|
|
@ -275,17 +290,15 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownLine) {
|
|||
}
|
||||
|
||||
TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) {
|
||||
EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1));
|
||||
EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(NULL, -1));
|
||||
}
|
||||
|
||||
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA || \
|
||||
GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
|
||||
GTEST_OS_NETBSD || GTEST_OS_OPENBSD
|
||||
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA
|
||||
void* ThreadFunc(void* data) {
|
||||
internal::Mutex* mutex = static_cast<internal::Mutex*>(data);
|
||||
mutex->Lock();
|
||||
mutex->Unlock();
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TEST(GetThreadCountTest, ReturnsCorrectValue) {
|
||||
|
|
@ -373,14 +386,21 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
|
|||
|
||||
#if GTEST_USES_POSIX_RE
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST
|
||||
|
||||
template <typename Str>
|
||||
class RETest : public ::testing::Test {};
|
||||
|
||||
// Defines StringTypes as the list of all string types that class RE
|
||||
// supports.
|
||||
typedef testing::Types< ::std::string, const char*> StringTypes;
|
||||
typedef testing::Types<
|
||||
::std::string,
|
||||
# if GTEST_HAS_GLOBAL_STRING
|
||||
::string,
|
||||
# endif // GTEST_HAS_GLOBAL_STRING
|
||||
const char*> StringTypes;
|
||||
|
||||
TYPED_TEST_SUITE(RETest, StringTypes);
|
||||
TYPED_TEST_CASE(RETest, StringTypes);
|
||||
|
||||
// Tests RE's implicit constructors.
|
||||
TYPED_TEST(RETest, ImplicitConstructorWorks) {
|
||||
|
|
@ -428,6 +448,8 @@ TYPED_TEST(RETest, PartialMatchWorks) {
|
|||
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
#elif GTEST_USES_SIMPLE_RE
|
||||
|
||||
TEST(IsInSetTest, NulCharIsNotInAnySet) {
|
||||
|
|
@ -943,7 +965,7 @@ TEST(ThreadLocalTest, DefaultConstructorInitializesToDefaultValues) {
|
|||
EXPECT_EQ(0, t1.get());
|
||||
|
||||
ThreadLocal<void*> t2;
|
||||
EXPECT_TRUE(t2.get() == nullptr);
|
||||
EXPECT_TRUE(t2.get() == NULL);
|
||||
}
|
||||
|
||||
TEST(ThreadLocalTest, SingleParamConstructorInitializesToParam) {
|
||||
|
|
@ -993,7 +1015,7 @@ void AddTwo(int* param) { *param += 2; }
|
|||
|
||||
TEST(ThreadWithParamTest, ConstructorExecutesThreadFunc) {
|
||||
int i = 40;
|
||||
ThreadWithParam<int*> thread(&AddTwo, &i, nullptr);
|
||||
ThreadWithParam<int*> thread(&AddTwo, &i, NULL);
|
||||
thread.Join();
|
||||
EXPECT_EQ(42, i);
|
||||
}
|
||||
|
|
@ -1033,10 +1055,10 @@ class AtomicCounterWithMutex {
|
|||
// functionality as we are testing them here.
|
||||
pthread_mutex_t memory_barrier_mutex;
|
||||
GTEST_CHECK_POSIX_SUCCESS_(
|
||||
pthread_mutex_init(&memory_barrier_mutex, nullptr));
|
||||
pthread_mutex_init(&memory_barrier_mutex, NULL));
|
||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex));
|
||||
|
||||
SleepMilliseconds(static_cast<int>(random_.Generate(30)));
|
||||
SleepMilliseconds(random_.Generate(30));
|
||||
|
||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
|
||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
|
||||
|
|
@ -1044,7 +1066,7 @@ class AtomicCounterWithMutex {
|
|||
// On Windows, performing an interlocked access puts up a memory barrier.
|
||||
volatile LONG dummy = 0;
|
||||
::InterlockedIncrement(&dummy);
|
||||
SleepMilliseconds(static_cast<int>(random_.Generate(30)));
|
||||
SleepMilliseconds(random_.Generate(30));
|
||||
::InterlockedIncrement(&dummy);
|
||||
#else
|
||||
# error "Memory barrier not implemented on this platform."
|
||||
|
|
@ -1073,7 +1095,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
|
|||
typedef ThreadWithParam<pair<AtomicCounterWithMutex*, int> > ThreadType;
|
||||
const int kCycleCount = 20;
|
||||
const int kThreadCount = 7;
|
||||
std::unique_ptr<ThreadType> counting_threads[kThreadCount];
|
||||
scoped_ptr<ThreadType> counting_threads[kThreadCount];
|
||||
Notification threads_can_start;
|
||||
// Creates and runs kThreadCount threads that increment locked_counter
|
||||
// kCycleCount times each.
|
||||
|
|
@ -1096,7 +1118,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
|
|||
|
||||
template <typename T>
|
||||
void RunFromThread(void (func)(T), T param) {
|
||||
ThreadWithParam<T> thread(func, param, nullptr);
|
||||
ThreadWithParam<T> thread(func, param, NULL);
|
||||
thread.Join();
|
||||
}
|
||||
|
||||
|
|
@ -1186,6 +1208,8 @@ class DestructorTracker {
|
|||
return DestructorCall::List().size() - 1;
|
||||
}
|
||||
const size_t index_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(DestructorTracker);
|
||||
};
|
||||
|
||||
typedef ThreadLocal<DestructorTracker>* ThreadParam;
|
||||
|
|
@ -1226,8 +1250,8 @@ TEST(ThreadLocalTest, DestroysManagedObjectAtThreadExit) {
|
|||
ASSERT_EQ(0U, DestructorCall::List().size());
|
||||
|
||||
// This creates another DestructorTracker object in the new thread.
|
||||
ThreadWithParam<ThreadParam> thread(&CallThreadLocalGet,
|
||||
&thread_local_tracker, nullptr);
|
||||
ThreadWithParam<ThreadParam> thread(
|
||||
&CallThreadLocalGet, &thread_local_tracker, NULL);
|
||||
thread.Join();
|
||||
|
||||
// The thread has exited, and we should have a DestroyedTracker
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,54 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019, 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 SetUpTestSuite and TearDownTestSuite errors are noticed."""
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-setuptestsuite-test_')
|
||||
|
||||
|
||||
class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSetupErrorAndTearDownError(self):
|
||||
p = gtest_test_utils.Subprocess(COMMAND)
|
||||
self.assertNotEqual(p.exit_code, 0, msg=p.output)
|
||||
|
||||
self.assertIn(
|
||||
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'\n'
|
||||
' 2 FAILED TEST SUITES\n',
|
||||
p.output)
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
|
|
@ -177,23 +177,23 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||
self.assertEqual(len(SHARDED_TESTS), len(SHUFFLED_SHARDED_TESTS))
|
||||
|
||||
def testShuffleChangesTestOrder(self):
|
||||
self.assertTrue(SHUFFLED_ALL_TESTS != ALL_TESTS, SHUFFLED_ALL_TESTS)
|
||||
self.assertTrue(SHUFFLED_ACTIVE_TESTS != ACTIVE_TESTS, SHUFFLED_ACTIVE_TESTS)
|
||||
self.assertTrue(SHUFFLED_FILTERED_TESTS != FILTERED_TESTS,
|
||||
self.assert_(SHUFFLED_ALL_TESTS != ALL_TESTS, SHUFFLED_ALL_TESTS)
|
||||
self.assert_(SHUFFLED_ACTIVE_TESTS != ACTIVE_TESTS, SHUFFLED_ACTIVE_TESTS)
|
||||
self.assert_(SHUFFLED_FILTERED_TESTS != FILTERED_TESTS,
|
||||
SHUFFLED_FILTERED_TESTS)
|
||||
self.assertTrue(SHUFFLED_SHARDED_TESTS != SHARDED_TESTS,
|
||||
self.assert_(SHUFFLED_SHARDED_TESTS != SHARDED_TESTS,
|
||||
SHUFFLED_SHARDED_TESTS)
|
||||
|
||||
def testShuffleChangesTestCaseOrder(self):
|
||||
self.assertTrue(GetTestCases(SHUFFLED_ALL_TESTS) != GetTestCases(ALL_TESTS),
|
||||
self.assert_(GetTestCases(SHUFFLED_ALL_TESTS) != GetTestCases(ALL_TESTS),
|
||||
GetTestCases(SHUFFLED_ALL_TESTS))
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
GetTestCases(SHUFFLED_ACTIVE_TESTS) != GetTestCases(ACTIVE_TESTS),
|
||||
GetTestCases(SHUFFLED_ACTIVE_TESTS))
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
GetTestCases(SHUFFLED_FILTERED_TESTS) != GetTestCases(FILTERED_TESTS),
|
||||
GetTestCases(SHUFFLED_FILTERED_TESTS))
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
GetTestCases(SHUFFLED_SHARDED_TESTS) != GetTestCases(SHARDED_TESTS),
|
||||
GetTestCases(SHUFFLED_SHARDED_TESTS))
|
||||
|
||||
|
|
@ -213,29 +213,29 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||
|
||||
def testShuffleDoesNotCreateNewTest(self):
|
||||
for test in SHUFFLED_ALL_TESTS:
|
||||
self.assertTrue(test in ALL_TESTS, '%s is an invalid test' % (test,))
|
||||
self.assert_(test in ALL_TESTS, '%s is an invalid test' % (test,))
|
||||
for test in SHUFFLED_ACTIVE_TESTS:
|
||||
self.assertTrue(test in ACTIVE_TESTS, '%s is an invalid test' % (test,))
|
||||
self.assert_(test in ACTIVE_TESTS, '%s is an invalid test' % (test,))
|
||||
for test in SHUFFLED_FILTERED_TESTS:
|
||||
self.assertTrue(test in FILTERED_TESTS, '%s is an invalid test' % (test,))
|
||||
self.assert_(test in FILTERED_TESTS, '%s is an invalid test' % (test,))
|
||||
for test in SHUFFLED_SHARDED_TESTS:
|
||||
self.assertTrue(test in SHARDED_TESTS, '%s is an invalid test' % (test,))
|
||||
self.assert_(test in SHARDED_TESTS, '%s is an invalid test' % (test,))
|
||||
|
||||
def testShuffleIncludesAllTests(self):
|
||||
for test in ALL_TESTS:
|
||||
self.assertTrue(test in SHUFFLED_ALL_TESTS, '%s is missing' % (test,))
|
||||
self.assert_(test in SHUFFLED_ALL_TESTS, '%s is missing' % (test,))
|
||||
for test in ACTIVE_TESTS:
|
||||
self.assertTrue(test in SHUFFLED_ACTIVE_TESTS, '%s is missing' % (test,))
|
||||
self.assert_(test in SHUFFLED_ACTIVE_TESTS, '%s is missing' % (test,))
|
||||
for test in FILTERED_TESTS:
|
||||
self.assertTrue(test in SHUFFLED_FILTERED_TESTS, '%s is missing' % (test,))
|
||||
self.assert_(test in SHUFFLED_FILTERED_TESTS, '%s is missing' % (test,))
|
||||
for test in SHARDED_TESTS:
|
||||
self.assertTrue(test in SHUFFLED_SHARDED_TESTS, '%s is missing' % (test,))
|
||||
self.assert_(test in SHUFFLED_SHARDED_TESTS, '%s is missing' % (test,))
|
||||
|
||||
def testShuffleLeavesDeathTestsAtFront(self):
|
||||
non_death_test_found = False
|
||||
for test in SHUFFLED_ACTIVE_TESTS:
|
||||
if 'DeathTest.' in test:
|
||||
self.assertTrue(not non_death_test_found,
|
||||
self.assert_(not non_death_test_found,
|
||||
'%s appears after a non-death test' % (test,))
|
||||
else:
|
||||
non_death_test_found = True
|
||||
|
|
@ -293,11 +293,11 @@ class GTestShuffleUnitTest(gtest_test_utils.TestCase):
|
|||
GetTestsForAllIterations(
|
||||
{}, [ShuffleFlag(), RandomSeedFlag(1), RepeatFlag(3)]))
|
||||
|
||||
self.assertTrue(tests_in_iteration1 != tests_in_iteration2,
|
||||
self.assert_(tests_in_iteration1 != tests_in_iteration2,
|
||||
tests_in_iteration1)
|
||||
self.assertTrue(tests_in_iteration1 != tests_in_iteration3,
|
||||
self.assert_(tests_in_iteration1 != tests_in_iteration3,
|
||||
tests_in_iteration1)
|
||||
self.assertTrue(tests_in_iteration2 != tests_in_iteration3,
|
||||
self.assert_(tests_in_iteration2 != tests_in_iteration3,
|
||||
tests_in_iteration2)
|
||||
|
||||
def testShuffleShardedTestsPreservesPartition(self):
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ using ::testing::Test;
|
|||
using ::testing::TestEventListeners;
|
||||
using ::testing::TestInfo;
|
||||
using ::testing::UnitTest;
|
||||
using ::testing::internal::scoped_ptr;
|
||||
|
||||
// The test methods are empty, as the sole purpose of this program is
|
||||
// to print the test names before/after shuffling.
|
||||
|
|
@ -76,13 +77,13 @@ TEST(DISABLED_D, DISABLED_B) {}
|
|||
// iteration with a "----" marker.
|
||||
class TestNamePrinter : public EmptyTestEventListener {
|
||||
public:
|
||||
void OnTestIterationStart(const UnitTest& /* unit_test */,
|
||||
int /* iteration */) override {
|
||||
virtual void OnTestIterationStart(const UnitTest& /* unit_test */,
|
||||
int /* iteration */) {
|
||||
printf("----\n");
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& test_info) override {
|
||||
printf("%s.%s\n", test_info.test_suite_name(), test_info.name());
|
||||
virtual void OnTestStart(const TestInfo& test_info) {
|
||||
printf("%s.%s\n", test_info.test_case_name(), test_info.name());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -46,10 +46,9 @@ class TestPartResultTest : public Test {
|
|||
TestPartResultTest()
|
||||
: r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"),
|
||||
r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"),
|
||||
r3_(TestPartResult::kFatalFailure, nullptr, -1, "Failure!"),
|
||||
r4_(TestPartResult::kSkip, "foo/bar.cc", 2, "Skipped!") {}
|
||||
r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {}
|
||||
|
||||
TestPartResult r1_, r2_, r3_, r4_;
|
||||
TestPartResult r1_, r2_, r3_;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -80,7 +79,6 @@ TEST_F(TestPartResultTest, ResultAccessorsWork) {
|
|||
EXPECT_FALSE(success.failed());
|
||||
EXPECT_FALSE(success.nonfatally_failed());
|
||||
EXPECT_FALSE(success.fatally_failed());
|
||||
EXPECT_FALSE(success.skipped());
|
||||
|
||||
const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure,
|
||||
"file.cc",
|
||||
|
|
@ -90,7 +88,6 @@ TEST_F(TestPartResultTest, ResultAccessorsWork) {
|
|||
EXPECT_TRUE(nonfatal_failure.failed());
|
||||
EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
|
||||
EXPECT_FALSE(nonfatal_failure.fatally_failed());
|
||||
EXPECT_FALSE(nonfatal_failure.skipped());
|
||||
|
||||
const TestPartResult fatal_failure(TestPartResult::kFatalFailure,
|
||||
"file.cc",
|
||||
|
|
@ -100,14 +97,6 @@ TEST_F(TestPartResultTest, ResultAccessorsWork) {
|
|||
EXPECT_TRUE(fatal_failure.failed());
|
||||
EXPECT_FALSE(fatal_failure.nonfatally_failed());
|
||||
EXPECT_TRUE(fatal_failure.fatally_failed());
|
||||
EXPECT_FALSE(fatal_failure.skipped());
|
||||
|
||||
const TestPartResult skip(TestPartResult::kSkip, "file.cc", 42, "message");
|
||||
EXPECT_FALSE(skip.passed());
|
||||
EXPECT_FALSE(skip.failed());
|
||||
EXPECT_FALSE(skip.nonfatally_failed());
|
||||
EXPECT_FALSE(skip.fatally_failed());
|
||||
EXPECT_TRUE(skip.skipped());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::type().
|
||||
|
|
@ -115,27 +104,23 @@ TEST_F(TestPartResultTest, type) {
|
|||
EXPECT_EQ(TestPartResult::kSuccess, r1_.type());
|
||||
EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type());
|
||||
EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type());
|
||||
EXPECT_EQ(TestPartResult::kSkip, r4_.type());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::file_name().
|
||||
TEST_F(TestPartResultTest, file_name) {
|
||||
EXPECT_STREQ("foo/bar.cc", r1_.file_name());
|
||||
EXPECT_STREQ(nullptr, r3_.file_name());
|
||||
EXPECT_STREQ("foo/bar.cc", r4_.file_name());
|
||||
EXPECT_STREQ(NULL, r3_.file_name());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::line_number().
|
||||
TEST_F(TestPartResultTest, line_number) {
|
||||
EXPECT_EQ(10, r1_.line_number());
|
||||
EXPECT_EQ(-1, r2_.line_number());
|
||||
EXPECT_EQ(2, r4_.line_number());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::message().
|
||||
TEST_F(TestPartResultTest, message) {
|
||||
EXPECT_STREQ("Success!", r1_.message());
|
||||
EXPECT_STREQ("Skipped!", r4_.message());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::passed().
|
||||
|
|
@ -143,7 +128,6 @@ TEST_F(TestPartResultTest, Passed) {
|
|||
EXPECT_TRUE(r1_.passed());
|
||||
EXPECT_FALSE(r2_.passed());
|
||||
EXPECT_FALSE(r3_.passed());
|
||||
EXPECT_FALSE(r4_.passed());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::failed().
|
||||
|
|
@ -151,15 +135,6 @@ TEST_F(TestPartResultTest, Failed) {
|
|||
EXPECT_FALSE(r1_.failed());
|
||||
EXPECT_TRUE(r2_.failed());
|
||||
EXPECT_TRUE(r3_.failed());
|
||||
EXPECT_FALSE(r4_.failed());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::failed().
|
||||
TEST_F(TestPartResultTest, Skipped) {
|
||||
EXPECT_FALSE(r1_.skipped());
|
||||
EXPECT_FALSE(r2_.skipped());
|
||||
EXPECT_FALSE(r3_.skipped());
|
||||
EXPECT_TRUE(r4_.skipped());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::fatally_failed().
|
||||
|
|
@ -167,7 +142,6 @@ TEST_F(TestPartResultTest, FatallyFailed) {
|
|||
EXPECT_FALSE(r1_.fatally_failed());
|
||||
EXPECT_FALSE(r2_.fatally_failed());
|
||||
EXPECT_TRUE(r3_.fatally_failed());
|
||||
EXPECT_FALSE(r4_.fatally_failed());
|
||||
}
|
||||
|
||||
// Tests TestPartResult::nonfatally_failed().
|
||||
|
|
@ -175,7 +149,6 @@ TEST_F(TestPartResultTest, NonfatallyFailed) {
|
|||
EXPECT_FALSE(r1_.nonfatally_failed());
|
||||
EXPECT_TRUE(r2_.nonfatally_failed());
|
||||
EXPECT_FALSE(r3_.nonfatally_failed());
|
||||
EXPECT_FALSE(r4_.nonfatally_failed());
|
||||
}
|
||||
|
||||
// Tests the TestPartResultArray class.
|
||||
|
|
@ -227,4 +200,6 @@ TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
|
|||
EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), "");
|
||||
}
|
||||
|
||||
// FIXME: Add a test for the class HasNewFatalFailureHelper.
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
|
|
@ -27,23 +27,35 @@
|
|||
// (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 for Google Test itself. This verifies that the basic constructs of
|
||||
// Google Test work.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "googletest-param-test-test.h"
|
||||
|
||||
class SetupFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
ASSERT_EQ("", "SET_UP_FAIL");
|
||||
}
|
||||
};
|
||||
using ::testing::Values;
|
||||
using ::testing::internal::ParamGenerator;
|
||||
|
||||
TEST_F(SetupFailTest, NoopPassingTest) {}
|
||||
// Tests that generators defined in a different translation unit
|
||||
// are functional. The test using extern_gen_2 is defined
|
||||
// in googletest-param-test-test.cc.
|
||||
ParamGenerator<int> extern_gen_2 = Values(33);
|
||||
|
||||
class TearDownFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void TearDownTestSuite() {
|
||||
ASSERT_EQ("", "TEAR_DOWN_FAIL");
|
||||
}
|
||||
};
|
||||
// Tests that a parameterized test case can be defined in one translation unit
|
||||
// and instantiated in another. The test is defined in
|
||||
// googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
|
||||
// defined in gtest-param-test_test.h.
|
||||
INSTANTIATE_TEST_CASE_P(MultiplesOf33,
|
||||
ExternalInstantiationTest,
|
||||
Values(33, 66));
|
||||
|
||||
// Tests that a parameterized test case can be instantiated
|
||||
// in multiple translation units. Another instantiation is defined
|
||||
// in googletest-param-test-test.cc and
|
||||
// InstantiationInMultipleTranslaionUnitsTest fixture is defined in
|
||||
// gtest-param-test_test.h
|
||||
INSTANTIATE_TEST_CASE_P(Sequence2,
|
||||
InstantiationInMultipleTranslaionUnitsTest,
|
||||
Values(42*3, 42*4, 42*5));
|
||||
|
||||
TEST_F(TearDownFailTest, NoopPassingTest) {}
|
||||
|
|
@ -68,12 +68,13 @@ 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
|
||||
|
||||
|
||||
# The tests.
|
||||
# The tests. FIXME: refactor the class to share common
|
||||
# logic with code in googletest-break-on-failure-unittest.py.
|
||||
class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
||||
"""Tests the throw-on-failure mode."""
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
|||
variable; None if the variable should be unset.
|
||||
flag_value: value of the --gtest_break_on_failure flag;
|
||||
None if the flag should not be present.
|
||||
should_fail: True if and only if the program is expected to fail.
|
||||
should_fail: True iff the program is expected to fail.
|
||||
"""
|
||||
|
||||
SetEnvVar(THROW_ON_FAILURE, env_var_value)
|
||||
|
|
@ -120,7 +121,7 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
|||
'exit code.' %
|
||||
(THROW_ON_FAILURE, env_var_value_msg, ' '.join(command),
|
||||
should_or_not))
|
||||
self.assertTrue(failed == should_fail, msg)
|
||||
self.assert_(failed == should_fail, msg)
|
||||
|
||||
def testDefaultBehavior(self):
|
||||
"""Tests the behavior of the default mode."""
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
// ones.
|
||||
void TerminateHandler() {
|
||||
fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program.");
|
||||
fflush(nullptr);
|
||||
fflush(NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,319 @@
|
|||
// Copyright 2007, 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.
|
||||
|
||||
|
||||
#include "gtest/internal/gtest-tuple.h"
|
||||
#include <utility>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using ::std::tr1::get;
|
||||
using ::std::tr1::make_tuple;
|
||||
using ::std::tr1::tuple;
|
||||
using ::std::tr1::tuple_element;
|
||||
using ::std::tr1::tuple_size;
|
||||
using ::testing::StaticAssertTypeEq;
|
||||
|
||||
// Tests that tuple_element<K, tuple<T0, T1, ..., TN> >::type returns TK.
|
||||
TEST(tuple_element_Test, ReturnsElementType) {
|
||||
StaticAssertTypeEq<int, tuple_element<0, tuple<int, char> >::type>();
|
||||
StaticAssertTypeEq<int&, tuple_element<1, tuple<double, int&> >::type>();
|
||||
StaticAssertTypeEq<bool, tuple_element<2, tuple<double, int, bool> >::type>();
|
||||
}
|
||||
|
||||
// Tests that tuple_size<T>::value gives the number of fields in tuple
|
||||
// type T.
|
||||
TEST(tuple_size_Test, ReturnsNumberOfFields) {
|
||||
EXPECT_EQ(0, +tuple_size<tuple<> >::value);
|
||||
EXPECT_EQ(1, +tuple_size<tuple<void*> >::value);
|
||||
EXPECT_EQ(1, +tuple_size<tuple<char> >::value);
|
||||
EXPECT_EQ(1, +(tuple_size<tuple<tuple<int, double> > >::value));
|
||||
EXPECT_EQ(2, +(tuple_size<tuple<int&, const char> >::value));
|
||||
EXPECT_EQ(3, +(tuple_size<tuple<char*, void, const bool&> >::value));
|
||||
}
|
||||
|
||||
// Tests comparing a tuple with itself.
|
||||
TEST(ComparisonTest, ComparesWithSelf) {
|
||||
const tuple<int, char, bool> a(5, 'a', false);
|
||||
|
||||
EXPECT_TRUE(a == a);
|
||||
EXPECT_FALSE(a != a);
|
||||
}
|
||||
|
||||
// Tests comparing two tuples with the same value.
|
||||
TEST(ComparisonTest, ComparesEqualTuples) {
|
||||
const tuple<int, bool> a(5, true), b(5, true);
|
||||
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_FALSE(a != b);
|
||||
}
|
||||
|
||||
// Tests comparing two different tuples that have no reference fields.
|
||||
TEST(ComparisonTest, ComparesUnequalTuplesWithoutReferenceFields) {
|
||||
typedef tuple<const int, char> FooTuple;
|
||||
|
||||
const FooTuple a(0, 'x');
|
||||
const FooTuple b(1, 'a');
|
||||
|
||||
EXPECT_TRUE(a != b);
|
||||
EXPECT_FALSE(a == b);
|
||||
|
||||
const FooTuple c(1, 'b');
|
||||
|
||||
EXPECT_TRUE(b != c);
|
||||
EXPECT_FALSE(b == c);
|
||||
}
|
||||
|
||||
// Tests comparing two different tuples that have reference fields.
|
||||
TEST(ComparisonTest, ComparesUnequalTuplesWithReferenceFields) {
|
||||
typedef tuple<int&, const char&> FooTuple;
|
||||
|
||||
int i = 5;
|
||||
const char ch = 'a';
|
||||
const FooTuple a(i, ch);
|
||||
|
||||
int j = 6;
|
||||
const FooTuple b(j, ch);
|
||||
|
||||
EXPECT_TRUE(a != b);
|
||||
EXPECT_FALSE(a == b);
|
||||
|
||||
j = 5;
|
||||
const char ch2 = 'b';
|
||||
const FooTuple c(j, ch2);
|
||||
|
||||
EXPECT_TRUE(b != c);
|
||||
EXPECT_FALSE(b == c);
|
||||
}
|
||||
|
||||
// Tests that a tuple field with a reference type is an alias of the
|
||||
// variable it's supposed to reference.
|
||||
TEST(ReferenceFieldTest, IsAliasOfReferencedVariable) {
|
||||
int n = 0;
|
||||
tuple<bool, int&> t(true, n);
|
||||
|
||||
n = 1;
|
||||
EXPECT_EQ(n, get<1>(t))
|
||||
<< "Changing a underlying variable should update the reference field.";
|
||||
|
||||
// Makes sure that the implementation doesn't do anything funny with
|
||||
// the & operator for the return type of get<>().
|
||||
EXPECT_EQ(&n, &(get<1>(t)))
|
||||
<< "The address of a reference field should equal the address of "
|
||||
<< "the underlying variable.";
|
||||
|
||||
get<1>(t) = 2;
|
||||
EXPECT_EQ(2, n)
|
||||
<< "Changing a reference field should update the underlying variable.";
|
||||
}
|
||||
|
||||
// Tests that tuple's default constructor default initializes each field.
|
||||
// This test needs to compile without generating warnings.
|
||||
TEST(TupleConstructorTest, DefaultConstructorDefaultInitializesEachField) {
|
||||
// The TR1 report requires that tuple's default constructor default
|
||||
// initializes each field, even if it's a primitive type. If the
|
||||
// implementation forgets to do this, this test will catch it by
|
||||
// generating warnings about using uninitialized variables (assuming
|
||||
// a decent compiler).
|
||||
|
||||
tuple<> empty;
|
||||
|
||||
tuple<int> a1, b1;
|
||||
b1 = a1;
|
||||
EXPECT_EQ(0, get<0>(b1));
|
||||
|
||||
tuple<int, double> a2, b2;
|
||||
b2 = a2;
|
||||
EXPECT_EQ(0, get<0>(b2));
|
||||
EXPECT_EQ(0.0, get<1>(b2));
|
||||
|
||||
tuple<double, char, bool*> a3, b3;
|
||||
b3 = a3;
|
||||
EXPECT_EQ(0.0, get<0>(b3));
|
||||
EXPECT_EQ('\0', get<1>(b3));
|
||||
EXPECT_TRUE(get<2>(b3) == NULL);
|
||||
|
||||
tuple<int, int, int, int, int, int, int, int, int, int> a10, b10;
|
||||
b10 = a10;
|
||||
EXPECT_EQ(0, get<0>(b10));
|
||||
EXPECT_EQ(0, get<1>(b10));
|
||||
EXPECT_EQ(0, get<2>(b10));
|
||||
EXPECT_EQ(0, get<3>(b10));
|
||||
EXPECT_EQ(0, get<4>(b10));
|
||||
EXPECT_EQ(0, get<5>(b10));
|
||||
EXPECT_EQ(0, get<6>(b10));
|
||||
EXPECT_EQ(0, get<7>(b10));
|
||||
EXPECT_EQ(0, get<8>(b10));
|
||||
EXPECT_EQ(0, get<9>(b10));
|
||||
}
|
||||
|
||||
// Tests constructing a tuple from its fields.
|
||||
TEST(TupleConstructorTest, ConstructsFromFields) {
|
||||
int n = 1;
|
||||
// Reference field.
|
||||
tuple<int&> a(n);
|
||||
EXPECT_EQ(&n, &(get<0>(a)));
|
||||
|
||||
// Non-reference fields.
|
||||
tuple<int, char> b(5, 'a');
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_EQ('a', get<1>(b));
|
||||
|
||||
// Const reference field.
|
||||
const int m = 2;
|
||||
tuple<bool, const int&> c(true, m);
|
||||
EXPECT_TRUE(get<0>(c));
|
||||
EXPECT_EQ(&m, &(get<1>(c)));
|
||||
}
|
||||
|
||||
// Tests tuple's copy constructor.
|
||||
TEST(TupleConstructorTest, CopyConstructor) {
|
||||
tuple<double, bool> a(0.0, true);
|
||||
tuple<double, bool> b(a);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
|
||||
EXPECT_TRUE(get<1>(b));
|
||||
}
|
||||
|
||||
// Tests constructing a tuple from another tuple that has a compatible
|
||||
// but different type.
|
||||
TEST(TupleConstructorTest, ConstructsFromDifferentTupleType) {
|
||||
tuple<int, int, char> a(0, 1, 'a');
|
||||
tuple<double, long, int> b(a);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
|
||||
EXPECT_EQ(1, get<1>(b));
|
||||
EXPECT_EQ('a', get<2>(b));
|
||||
}
|
||||
|
||||
// Tests constructing a 2-tuple from an std::pair.
|
||||
TEST(TupleConstructorTest, ConstructsFromPair) {
|
||||
::std::pair<int, char> a(1, 'a');
|
||||
tuple<int, char> b(a);
|
||||
tuple<int, const char&> c(a);
|
||||
}
|
||||
|
||||
// Tests assigning a tuple to another tuple with the same type.
|
||||
TEST(TupleAssignmentTest, AssignsToSameTupleType) {
|
||||
const tuple<int, long> a(5, 7L);
|
||||
tuple<int, long> b;
|
||||
b = a;
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_EQ(7L, get<1>(b));
|
||||
}
|
||||
|
||||
// Tests assigning a tuple to another tuple with a different but
|
||||
// compatible type.
|
||||
TEST(TupleAssignmentTest, AssignsToDifferentTupleType) {
|
||||
const tuple<int, long, bool> a(1, 7L, true);
|
||||
tuple<long, int, bool> b;
|
||||
b = a;
|
||||
EXPECT_EQ(1L, get<0>(b));
|
||||
EXPECT_EQ(7, get<1>(b));
|
||||
EXPECT_TRUE(get<2>(b));
|
||||
}
|
||||
|
||||
// Tests assigning an std::pair to a 2-tuple.
|
||||
TEST(TupleAssignmentTest, AssignsFromPair) {
|
||||
const ::std::pair<int, bool> a(5, true);
|
||||
tuple<int, bool> b;
|
||||
b = a;
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_TRUE(get<1>(b));
|
||||
|
||||
tuple<long, bool> c;
|
||||
c = a;
|
||||
EXPECT_EQ(5L, get<0>(c));
|
||||
EXPECT_TRUE(get<1>(c));
|
||||
}
|
||||
|
||||
// A fixture for testing big tuples.
|
||||
class BigTupleTest : public testing::Test {
|
||||
protected:
|
||||
typedef tuple<int, int, int, int, int, int, int, int, int, int> BigTuple;
|
||||
|
||||
BigTupleTest() :
|
||||
a_(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
|
||||
b_(1, 0, 0, 0, 0, 0, 0, 0, 0, 3) {}
|
||||
|
||||
BigTuple a_, b_;
|
||||
};
|
||||
|
||||
// Tests constructing big tuples.
|
||||
TEST_F(BigTupleTest, Construction) {
|
||||
BigTuple a;
|
||||
BigTuple b(b_);
|
||||
}
|
||||
|
||||
// Tests that get<N>(t) returns the N-th (0-based) field of tuple t.
|
||||
TEST_F(BigTupleTest, get) {
|
||||
EXPECT_EQ(1, get<0>(a_));
|
||||
EXPECT_EQ(2, get<9>(a_));
|
||||
|
||||
// Tests that get() works on a const tuple too.
|
||||
const BigTuple a(a_);
|
||||
EXPECT_EQ(1, get<0>(a));
|
||||
EXPECT_EQ(2, get<9>(a));
|
||||
}
|
||||
|
||||
// Tests comparing big tuples.
|
||||
TEST_F(BigTupleTest, Comparisons) {
|
||||
EXPECT_TRUE(a_ == a_);
|
||||
EXPECT_FALSE(a_ != a_);
|
||||
|
||||
EXPECT_TRUE(a_ != b_);
|
||||
EXPECT_FALSE(a_ == b_);
|
||||
}
|
||||
|
||||
TEST(MakeTupleTest, WorksForScalarTypes) {
|
||||
tuple<bool, int> a;
|
||||
a = make_tuple(true, 5);
|
||||
EXPECT_TRUE(get<0>(a));
|
||||
EXPECT_EQ(5, get<1>(a));
|
||||
|
||||
tuple<char, int, long> b;
|
||||
b = make_tuple('a', 'b', 5);
|
||||
EXPECT_EQ('a', get<0>(b));
|
||||
EXPECT_EQ('b', get<1>(b));
|
||||
EXPECT_EQ(5, get<2>(b));
|
||||
}
|
||||
|
||||
TEST(MakeTupleTest, WorksForPointers) {
|
||||
int a[] = { 1, 2, 3, 4 };
|
||||
const char* const str = "hi";
|
||||
int* const p = a;
|
||||
|
||||
tuple<const char*, int*> t;
|
||||
t = make_tuple(str, p);
|
||||
EXPECT_EQ(str, get<0>(t));
|
||||
EXPECT_EQ(p, get<1>(t));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -43,8 +43,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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,12 @@
|
|||
#include "test/gtest-typed-test_test.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// Tests that the same type-parameterized test case can be
|
||||
// instantiated in different translation units linked together.
|
||||
// (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest,
|
||||
testing::Types<std::vector<int> >);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Vector, ContainerTest,
|
||||
testing::Types<std::vector<int> >);
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#include "test/gtest-typed-test_test.h"
|
||||
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
|
@ -42,21 +41,21 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */)
|
|||
|
||||
using testing::Test;
|
||||
|
||||
// Used for testing that SetUpTestSuite()/TearDownTestSuite(), fixture
|
||||
// Used for testing that SetUpTestCase()/TearDownTestCase(), fixture
|
||||
// ctor/dtor, and SetUp()/TearDown() work correctly in typed tests and
|
||||
// type-parameterized test.
|
||||
template <typename T>
|
||||
class CommonTest : public Test {
|
||||
// For some technical reason, SetUpTestSuite() and TearDownTestSuite()
|
||||
// For some technical reason, SetUpTestCase() and TearDownTestCase()
|
||||
// must be public.
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
static void SetUpTestCase() {
|
||||
shared_ = new T(5);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
static void TearDownTestCase() {
|
||||
delete shared_;
|
||||
shared_ = nullptr;
|
||||
shared_ = NULL;
|
||||
}
|
||||
|
||||
// This 'protected:' is optional. There's no harm in making all
|
||||
|
|
@ -69,14 +68,14 @@ class CommonTest : public Test {
|
|||
|
||||
CommonTest() : value_(1) {}
|
||||
|
||||
~CommonTest() override { EXPECT_EQ(3, value_); }
|
||||
virtual ~CommonTest() { EXPECT_EQ(3, value_); }
|
||||
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
EXPECT_EQ(1, value_);
|
||||
value_++;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
EXPECT_EQ(2, value_);
|
||||
value_++;
|
||||
}
|
||||
|
|
@ -86,15 +85,18 @@ class CommonTest : public Test {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
T* CommonTest<T>::shared_ = nullptr;
|
||||
T* CommonTest<T>::shared_ = NULL;
|
||||
|
||||
// This #ifdef block tests typed tests.
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
|
||||
using testing::Types;
|
||||
|
||||
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor,
|
||||
// Tests that SetUpTestCase()/TearDownTestCase(), fixture ctor/dtor,
|
||||
// and SetUp()/TearDown() work correctly in typed tests
|
||||
|
||||
typedef Types<char, int> TwoTypes;
|
||||
TYPED_TEST_SUITE(CommonTest, TwoTypes);
|
||||
TYPED_TEST_CASE(CommonTest, TwoTypes);
|
||||
|
||||
TYPED_TEST(CommonTest, ValuesAreCorrect) {
|
||||
// Static members of the fixture class template can be visited via
|
||||
|
|
@ -119,32 +121,32 @@ TYPED_TEST(CommonTest, ValuesAreCorrect) {
|
|||
TYPED_TEST(CommonTest, ValuesAreStillCorrect) {
|
||||
// Static members of the fixture class template can also be visited
|
||||
// via 'this'.
|
||||
ASSERT_TRUE(this->shared_ != nullptr);
|
||||
ASSERT_TRUE(this->shared_ != NULL);
|
||||
EXPECT_EQ(5, *this->shared_);
|
||||
|
||||
// TypeParam can be used to refer to the type parameter.
|
||||
EXPECT_EQ(static_cast<TypeParam>(2), this->value_);
|
||||
}
|
||||
|
||||
// Tests that multiple TYPED_TEST_SUITE's can be defined in the same
|
||||
// Tests that multiple TYPED_TEST_CASE's can be defined in the same
|
||||
// translation unit.
|
||||
|
||||
template <typename T>
|
||||
class TypedTest1 : public Test {
|
||||
};
|
||||
|
||||
// Verifies that the second argument of TYPED_TEST_SUITE can be a
|
||||
// Verifies that the second argument of TYPED_TEST_CASE can be a
|
||||
// single type.
|
||||
TYPED_TEST_SUITE(TypedTest1, int);
|
||||
TYPED_TEST_CASE(TypedTest1, int);
|
||||
TYPED_TEST(TypedTest1, A) {}
|
||||
|
||||
template <typename T>
|
||||
class TypedTest2 : public Test {
|
||||
};
|
||||
|
||||
// Verifies that the second argument of TYPED_TEST_SUITE can be a
|
||||
// Verifies that the second argument of TYPED_TEST_CASE can be a
|
||||
// Types<...> type list.
|
||||
TYPED_TEST_SUITE(TypedTest2, Types<int>);
|
||||
TYPED_TEST_CASE(TypedTest2, Types<int>);
|
||||
|
||||
// This also verifies that tests from different typed test cases can
|
||||
// share the same name.
|
||||
|
|
@ -159,7 +161,7 @@ class NumericTest : public Test {
|
|||
};
|
||||
|
||||
typedef Types<int, long> NumericTypes;
|
||||
TYPED_TEST_SUITE(NumericTest, NumericTypes);
|
||||
TYPED_TEST_CASE(NumericTest, NumericTypes);
|
||||
|
||||
TYPED_TEST(NumericTest, DefaultIsZero) {
|
||||
EXPECT_EQ(0, TypeParam());
|
||||
|
|
@ -175,100 +177,105 @@ class TypedTestNames {
|
|||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (std::is_same<T, char>::value) {
|
||||
if (testing::internal::IsSame<T, char>::value) {
|
||||
return std::string("char") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (std::is_same<T, int>::value) {
|
||||
if (testing::internal::IsSame<T, int>::value) {
|
||||
return std::string("int") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE(TypedTestWithNames, TwoTypes, TypedTestNames);
|
||||
TYPED_TEST_CASE(TypedTestWithNames, TwoTypes, TypedTestNames);
|
||||
|
||||
TYPED_TEST(TypedTestWithNames, TestSuiteName) {
|
||||
if (std::is_same<TypeParam, char>::value) {
|
||||
TYPED_TEST(TypedTestWithNames, TestCaseName) {
|
||||
if (testing::internal::IsSame<TypeParam, char>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_suite_name(),
|
||||
->test_case_name(),
|
||||
"TypedTestWithNames/char0");
|
||||
}
|
||||
if (std::is_same<TypeParam, int>::value) {
|
||||
if (testing::internal::IsSame<TypeParam, int>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_suite_name(),
|
||||
->test_case_name(),
|
||||
"TypedTestWithNames/int1");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// This #ifdef block tests type-parameterized tests.
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
using testing::Types;
|
||||
using testing::internal::TypedTestSuitePState;
|
||||
using testing::internal::TypedTestCasePState;
|
||||
|
||||
// Tests TypedTestSuitePState.
|
||||
// Tests TypedTestCasePState.
|
||||
|
||||
class TypedTestSuitePStateTest : public Test {
|
||||
class TypedTestCasePStateTest : public Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
state_.AddTestName("foo.cc", 0, "FooTest", "A");
|
||||
state_.AddTestName("foo.cc", 0, "FooTest", "B");
|
||||
state_.AddTestName("foo.cc", 0, "FooTest", "C");
|
||||
}
|
||||
|
||||
TypedTestSuitePState state_;
|
||||
TypedTestCasePState state_;
|
||||
};
|
||||
|
||||
TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) {
|
||||
TEST_F(TypedTestCasePStateTest, SucceedsForMatchingList) {
|
||||
const char* tests = "A, B, C";
|
||||
EXPECT_EQ(tests,
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests));
|
||||
}
|
||||
|
||||
// Makes sure that the order of the tests and spaces around the names
|
||||
// don't matter.
|
||||
TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) {
|
||||
TEST_F(TypedTestCasePStateTest, IgnoresOrderAndSpaces) {
|
||||
const char* tests = "A,C, B";
|
||||
EXPECT_EQ(tests,
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests));
|
||||
}
|
||||
|
||||
using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest;
|
||||
typedef TypedTestCasePStateTest TypedTestCasePStateDeathTest;
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) {
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, A, C"),
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"),
|
||||
"foo\\.cc.1.?: Test A is listed more than once\\.");
|
||||
}
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) {
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C, D"),
|
||||
"foo\\.cc.1.?: No test named D can be found in this test suite\\.");
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"),
|
||||
"foo\\.cc.1.?: No test named D can be found in this test case\\.");
|
||||
}
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) {
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, C"),
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"),
|
||||
"foo\\.cc.1.?: You forgot to list test B\\.");
|
||||
}
|
||||
|
||||
// Tests that defining a test for a parameterized test case generates
|
||||
// a run-time error if the test case has been registered.
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) {
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C");
|
||||
TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) {
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C");
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.AddTestName("foo.cc", 2, "FooTest", "D"),
|
||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P"
|
||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_CASE_P"
|
||||
"\\(FooTest, \\.\\.\\.\\)\\.");
|
||||
}
|
||||
|
||||
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor,
|
||||
// Tests that SetUpTestCase()/TearDownTestCase(), fixture ctor/dtor,
|
||||
// and SetUp()/TearDown() work correctly in type-parameterized tests.
|
||||
|
||||
template <typename T>
|
||||
class DerivedTest : public CommonTest<T> {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(DerivedTest);
|
||||
TYPED_TEST_CASE_P(DerivedTest);
|
||||
|
||||
TYPED_TEST_P(DerivedTest, ValuesAreCorrect) {
|
||||
// Static members of the fixture class template can be visited via
|
||||
|
|
@ -285,110 +292,110 @@ TYPED_TEST_P(DerivedTest, ValuesAreCorrect) {
|
|||
TYPED_TEST_P(DerivedTest, ValuesAreStillCorrect) {
|
||||
// Static members of the fixture class template can also be visited
|
||||
// via 'this'.
|
||||
ASSERT_TRUE(this->shared_ != nullptr);
|
||||
ASSERT_TRUE(this->shared_ != NULL);
|
||||
EXPECT_EQ(5, *this->shared_);
|
||||
EXPECT_EQ(2, this->value_);
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(DerivedTest,
|
||||
REGISTER_TYPED_TEST_CASE_P(DerivedTest,
|
||||
ValuesAreCorrect, ValuesAreStillCorrect);
|
||||
|
||||
typedef Types<short, long> MyTwoTypes;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, DerivedTest, MyTwoTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, DerivedTest, MyTwoTypes);
|
||||
|
||||
// Tests that custom names work with type parametrized tests. We reuse the
|
||||
// TwoTypes from above here.
|
||||
template <typename T>
|
||||
class TypeParametrizedTestWithNames : public Test {};
|
||||
|
||||
TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames);
|
||||
TYPED_TEST_CASE_P(TypeParametrizedTestWithNames);
|
||||
|
||||
TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) {
|
||||
if (std::is_same<TypeParam, char>::value) {
|
||||
TYPED_TEST_P(TypeParametrizedTestWithNames, TestCaseName) {
|
||||
if (testing::internal::IsSame<TypeParam, char>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_suite_name(),
|
||||
->test_case_name(),
|
||||
"CustomName/TypeParametrizedTestWithNames/parChar0");
|
||||
}
|
||||
if (std::is_same<TypeParam, int>::value) {
|
||||
if (testing::internal::IsSame<TypeParam, int>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_suite_name(),
|
||||
->test_case_name(),
|
||||
"CustomName/TypeParametrizedTestWithNames/parInt1");
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames, TestSuiteName);
|
||||
REGISTER_TYPED_TEST_CASE_P(TypeParametrizedTestWithNames, TestCaseName);
|
||||
|
||||
class TypeParametrizedTestNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (std::is_same<T, char>::value) {
|
||||
if (testing::internal::IsSame<T, char>::value) {
|
||||
return std::string("parChar") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (std::is_same<T, int>::value) {
|
||||
if (testing::internal::IsSame<T, int>::value) {
|
||||
return std::string("parInt") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(CustomName, TypeParametrizedTestWithNames,
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(CustomName, TypeParametrizedTestWithNames,
|
||||
TwoTypes, TypeParametrizedTestNames);
|
||||
|
||||
// Tests that multiple TYPED_TEST_SUITE_P's can be defined in the same
|
||||
// Tests that multiple TYPED_TEST_CASE_P's can be defined in the same
|
||||
// translation unit.
|
||||
|
||||
template <typename T>
|
||||
class TypedTestP1 : public Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(TypedTestP1);
|
||||
TYPED_TEST_CASE_P(TypedTestP1);
|
||||
|
||||
// For testing that the code between TYPED_TEST_SUITE_P() and
|
||||
// For testing that the code between TYPED_TEST_CASE_P() and
|
||||
// TYPED_TEST_P() is not enclosed in a namespace.
|
||||
using IntAfterTypedTestSuiteP = int;
|
||||
typedef int IntAfterTypedTestCaseP;
|
||||
|
||||
TYPED_TEST_P(TypedTestP1, A) {}
|
||||
TYPED_TEST_P(TypedTestP1, B) {}
|
||||
|
||||
// For testing that the code between TYPED_TEST_P() and
|
||||
// REGISTER_TYPED_TEST_SUITE_P() is not enclosed in a namespace.
|
||||
using IntBeforeRegisterTypedTestSuiteP = int;
|
||||
// REGISTER_TYPED_TEST_CASE_P() is not enclosed in a namespace.
|
||||
typedef int IntBeforeRegisterTypedTestCaseP;
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypedTestP1, A, B);
|
||||
REGISTER_TYPED_TEST_CASE_P(TypedTestP1, A, B);
|
||||
|
||||
template <typename T>
|
||||
class TypedTestP2 : public Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(TypedTestP2);
|
||||
TYPED_TEST_CASE_P(TypedTestP2);
|
||||
|
||||
// This also verifies that tests from different type-parameterized
|
||||
// test cases can share the same name.
|
||||
TYPED_TEST_P(TypedTestP2, A) {}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypedTestP2, A);
|
||||
REGISTER_TYPED_TEST_CASE_P(TypedTestP2, A);
|
||||
|
||||
// Verifies that the code between TYPED_TEST_SUITE_P() and
|
||||
// REGISTER_TYPED_TEST_SUITE_P() is not enclosed in a namespace.
|
||||
IntAfterTypedTestSuiteP after = 0;
|
||||
IntBeforeRegisterTypedTestSuiteP before = 0;
|
||||
// Verifies that the code between TYPED_TEST_CASE_P() and
|
||||
// REGISTER_TYPED_TEST_CASE_P() is not enclosed in a namespace.
|
||||
IntAfterTypedTestCaseP after = 0;
|
||||
IntBeforeRegisterTypedTestCaseP before = 0;
|
||||
|
||||
// Verifies that the last argument of INSTANTIATE_TYPED_TEST_SUITE_P()
|
||||
// Verifies that the last argument of INSTANTIATE_TYPED_TEST_CASE_P()
|
||||
// can be either a single type or a Types<...> type list.
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Int, TypedTestP1, int);
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Int, TypedTestP2, Types<int>);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Int, TypedTestP1, int);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Int, TypedTestP2, Types<int>);
|
||||
|
||||
// Tests that the same type-parameterized test case can be
|
||||
// instantiated more than once in the same translation unit.
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Double, TypedTestP2, Types<double>);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Double, TypedTestP2, Types<double>);
|
||||
|
||||
// Tests that the same type-parameterized test case can be
|
||||
// instantiated in different translation units linked together.
|
||||
// (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
|
||||
typedef Types<std::vector<double>, std::set<char> > MyContainers;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, ContainerTest, MyContainers);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, ContainerTest, MyContainers);
|
||||
|
||||
// Tests that a type-parameterized test case can be defined and
|
||||
// instantiated in a namespace.
|
||||
|
|
@ -399,7 +406,7 @@ template <typename T>
|
|||
class NumericTest : public Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(NumericTest);
|
||||
TYPED_TEST_CASE_P(NumericTest);
|
||||
|
||||
TYPED_TEST_P(NumericTest, DefaultIsZero) {
|
||||
EXPECT_EQ(0, TypeParam());
|
||||
|
|
@ -409,29 +416,46 @@ TYPED_TEST_P(NumericTest, ZeroIsLessThanOne) {
|
|||
EXPECT_LT(TypeParam(0), TypeParam(1));
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(NumericTest,
|
||||
REGISTER_TYPED_TEST_CASE_P(NumericTest,
|
||||
DefaultIsZero, ZeroIsLessThanOne);
|
||||
typedef Types<int, double> NumericTypes;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, NumericTest, NumericTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, NumericTest, NumericTypes);
|
||||
|
||||
static const char* GetTestName() {
|
||||
return testing::UnitTest::GetInstance()->current_test_info()->name();
|
||||
}
|
||||
// Test the stripping of space from test names
|
||||
template <typename T> class TrimmedTest : public Test { };
|
||||
TYPED_TEST_SUITE_P(TrimmedTest);
|
||||
TYPED_TEST_CASE_P(TrimmedTest);
|
||||
TYPED_TEST_P(TrimmedTest, Test1) { EXPECT_STREQ("Test1", GetTestName()); }
|
||||
TYPED_TEST_P(TrimmedTest, Test2) { EXPECT_STREQ("Test2", GetTestName()); }
|
||||
TYPED_TEST_P(TrimmedTest, Test3) { EXPECT_STREQ("Test3", GetTestName()); }
|
||||
TYPED_TEST_P(TrimmedTest, Test4) { EXPECT_STREQ("Test4", GetTestName()); }
|
||||
TYPED_TEST_P(TrimmedTest, Test5) { EXPECT_STREQ("Test5", GetTestName()); }
|
||||
REGISTER_TYPED_TEST_SUITE_P(
|
||||
REGISTER_TYPED_TEST_CASE_P(
|
||||
TrimmedTest,
|
||||
Test1, Test2,Test3 , Test4 ,Test5 ); // NOLINT
|
||||
template <typename T1, typename T2> struct MyPair {};
|
||||
// Be sure to try a type with a comma in its name just in case it matters.
|
||||
typedef Types<int, double, MyPair<int, int> > TrimTypes;
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes);
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(My, TrimmedTest, TrimTypes);
|
||||
|
||||
} // namespace library2
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
|
||||
|
||||
// Google Test may not support type-parameterized tests with some
|
||||
// compilers. If we use conditional compilation to compile out all
|
||||
// code referring to the gtest_main library, MSVC linker will not link
|
||||
// that library at all and consequently complain about missing entry
|
||||
// point defined in that library (fatal error LNK1561: entry point
|
||||
// must be defined). This dummy test keeps gtest_main linked in.
|
||||
TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {}
|
||||
|
||||
#if _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
|
||||
|
|
|
|||
|
|
@ -27,11 +27,14 @@
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#define GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
|
||||
#ifndef GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#define GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
using testing::Test;
|
||||
|
||||
// For testing that the same type-parameterized test case can be
|
||||
|
|
@ -43,7 +46,7 @@ template <typename T>
|
|||
class ContainerTest : public Test {
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(ContainerTest);
|
||||
TYPED_TEST_CASE_P(ContainerTest);
|
||||
|
||||
TYPED_TEST_P(ContainerTest, CanBeDefaultConstructed) {
|
||||
TypeParam container;
|
||||
|
|
@ -54,7 +57,9 @@ TYPED_TEST_P(ContainerTest, InitialSizeIsZero) {
|
|||
EXPECT_EQ(0U, container.size());
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(ContainerTest,
|
||||
CanBeDefaultConstructed, InitialSizeIsZero);
|
||||
REGISTER_TYPED_TEST_CASE_P(ContainerTest,
|
||||
CanBeDefaultConstructed, InitialSizeIsZero);
|
||||
|
||||
#endif // GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
|
|
|
|||
|
|
@ -51,56 +51,61 @@ struct LessByName {
|
|||
|
||||
class UnitTestHelper {
|
||||
public:
|
||||
// Returns the array of pointers to all test suites sorted by the test suite
|
||||
// Returns the array of pointers to all test cases sorted by the test case
|
||||
// name. The caller is responsible for deleting the array.
|
||||
static TestSuite const** GetSortedTestSuites() {
|
||||
static TestCase const** GetSortedTestCases() {
|
||||
UnitTest& unit_test = *UnitTest::GetInstance();
|
||||
auto const** const test_suites = new const TestSuite*[static_cast<size_t>(
|
||||
unit_test.total_test_suite_count())];
|
||||
TestCase const** const test_cases =
|
||||
new const TestCase*[unit_test.total_test_case_count()];
|
||||
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i)
|
||||
test_suites[i] = unit_test.GetTestSuite(i);
|
||||
for (int i = 0; i < unit_test.total_test_case_count(); ++i)
|
||||
test_cases[i] = unit_test.GetTestCase(i);
|
||||
|
||||
std::sort(test_suites,
|
||||
test_suites + unit_test.total_test_suite_count(),
|
||||
LessByName<TestSuite>());
|
||||
return test_suites;
|
||||
std::sort(test_cases,
|
||||
test_cases + unit_test.total_test_case_count(),
|
||||
LessByName<TestCase>());
|
||||
return test_cases;
|
||||
}
|
||||
|
||||
// Returns the test suite by its name. The caller doesn't own the returned
|
||||
// Returns the test case by its name. The caller doesn't own the returned
|
||||
// pointer.
|
||||
static const TestSuite* FindTestSuite(const char* name) {
|
||||
static const TestCase* FindTestCase(const char* name) {
|
||||
UnitTest& unit_test = *UnitTest::GetInstance();
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
|
||||
const TestSuite* test_suite = unit_test.GetTestSuite(i);
|
||||
if (0 == strcmp(test_suite->name(), name))
|
||||
return test_suite;
|
||||
for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
|
||||
const TestCase* test_case = unit_test.GetTestCase(i);
|
||||
if (0 == strcmp(test_case->name(), name))
|
||||
return test_case;
|
||||
}
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns the array of pointers to all tests in a particular test suite
|
||||
// Returns the array of pointers to all tests in a particular test case
|
||||
// sorted by the test name. The caller is responsible for deleting the
|
||||
// array.
|
||||
static TestInfo const** GetSortedTests(const TestSuite* test_suite) {
|
||||
TestInfo const** const tests = new const TestInfo*[static_cast<size_t>(
|
||||
test_suite->total_test_count())];
|
||||
static TestInfo const** GetSortedTests(const TestCase* test_case) {
|
||||
TestInfo const** const tests =
|
||||
new const TestInfo*[test_case->total_test_count()];
|
||||
|
||||
for (int i = 0; i < test_suite->total_test_count(); ++i)
|
||||
tests[i] = test_suite->GetTestInfo(i);
|
||||
for (int i = 0; i < test_case->total_test_count(); ++i)
|
||||
tests[i] = test_case->GetTestInfo(i);
|
||||
|
||||
std::sort(tests, tests + test_suite->total_test_count(),
|
||||
std::sort(tests, tests + test_case->total_test_count(),
|
||||
LessByName<TestInfo>());
|
||||
return tests;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> class TestSuiteWithCommentTest : public Test {};
|
||||
TYPED_TEST_SUITE(TestSuiteWithCommentTest, Types<int>);
|
||||
TYPED_TEST(TestSuiteWithCommentTest, Dummy) {}
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
template <typename T> class TestCaseWithCommentTest : public Test {};
|
||||
TYPED_TEST_CASE(TestCaseWithCommentTest, Types<int>);
|
||||
TYPED_TEST(TestCaseWithCommentTest, Dummy) {}
|
||||
|
||||
const int kTypedTestSuites = 1;
|
||||
const int kTypedTestCases = 1;
|
||||
const int kTypedTests = 1;
|
||||
#else
|
||||
const int kTypedTestCases = 0;
|
||||
const int kTypedTests = 0;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// We can only test the accessors that do not change value while tests run.
|
||||
// Since tests can be run in any order, the values the accessors that track
|
||||
|
|
@ -108,19 +113,21 @@ const int kTypedTests = 1;
|
|||
TEST(ApiTest, UnitTestImmutableAccessorsWork) {
|
||||
UnitTest* unit_test = UnitTest::GetInstance();
|
||||
|
||||
ASSERT_EQ(2 + kTypedTestSuites, unit_test->total_test_suite_count());
|
||||
EXPECT_EQ(1 + kTypedTestSuites, unit_test->test_suite_to_run_count());
|
||||
ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count());
|
||||
EXPECT_EQ(1 + kTypedTestCases, unit_test->test_case_to_run_count());
|
||||
EXPECT_EQ(2, unit_test->disabled_test_count());
|
||||
EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count());
|
||||
EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_count());
|
||||
|
||||
const TestSuite** const test_suites = UnitTestHelper::GetSortedTestSuites();
|
||||
const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases();
|
||||
|
||||
EXPECT_STREQ("ApiTest", test_suites[0]->name());
|
||||
EXPECT_STREQ("DISABLED_Test", test_suites[1]->name());
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
||||
EXPECT_STREQ("ApiTest", test_cases[0]->name());
|
||||
EXPECT_STREQ("DISABLED_Test", test_cases[1]->name());
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name());
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
delete[] test_suites;
|
||||
delete[] test_cases;
|
||||
|
||||
// The following lines initiate actions to verify certain methods in
|
||||
// FinalSuccessChecker::TearDown.
|
||||
|
|
@ -130,157 +137,160 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) {
|
|||
}
|
||||
|
||||
AssertionResult IsNull(const char* str) {
|
||||
if (str != nullptr) {
|
||||
if (str != NULL) {
|
||||
return testing::AssertionFailure() << "argument is " << str;
|
||||
}
|
||||
return AssertionSuccess();
|
||||
}
|
||||
|
||||
TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
|
||||
const TestSuite* test_suite = UnitTestHelper::FindTestSuite("ApiTest");
|
||||
ASSERT_TRUE(test_suite != nullptr);
|
||||
TEST(ApiTest, TestCaseImmutableAccessorsWork) {
|
||||
const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest");
|
||||
ASSERT_TRUE(test_case != NULL);
|
||||
|
||||
EXPECT_STREQ("ApiTest", test_suite->name());
|
||||
EXPECT_TRUE(IsNull(test_suite->type_param()));
|
||||
EXPECT_TRUE(test_suite->should_run());
|
||||
EXPECT_EQ(1, test_suite->disabled_test_count());
|
||||
EXPECT_EQ(3, test_suite->test_to_run_count());
|
||||
ASSERT_EQ(4, test_suite->total_test_count());
|
||||
EXPECT_STREQ("ApiTest", test_case->name());
|
||||
EXPECT_TRUE(IsNull(test_case->type_param()));
|
||||
EXPECT_TRUE(test_case->should_run());
|
||||
EXPECT_EQ(1, test_case->disabled_test_count());
|
||||
EXPECT_EQ(3, test_case->test_to_run_count());
|
||||
ASSERT_EQ(4, test_case->total_test_count());
|
||||
|
||||
const TestInfo** tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case);
|
||||
|
||||
EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[0]->test_suite_name());
|
||||
EXPECT_STREQ("ApiTest", tests[0]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[0]->type_param()));
|
||||
EXPECT_FALSE(tests[0]->should_run());
|
||||
|
||||
EXPECT_STREQ("TestSuiteDisabledAccessorsWork", tests[1]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[1]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[1]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[1]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[1]->type_param()));
|
||||
EXPECT_TRUE(tests[1]->should_run());
|
||||
|
||||
EXPECT_STREQ("TestSuiteImmutableAccessorsWork", tests[2]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[2]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[2]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[2]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[2]->type_param()));
|
||||
EXPECT_TRUE(tests[2]->should_run());
|
||||
|
||||
EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[3]->test_suite_name());
|
||||
EXPECT_STREQ("ApiTest", tests[3]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[3]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[3]->type_param()));
|
||||
EXPECT_TRUE(tests[3]->should_run());
|
||||
|
||||
delete[] tests;
|
||||
tests = nullptr;
|
||||
tests = NULL;
|
||||
|
||||
test_suite = UnitTestHelper::FindTestSuite("TestSuiteWithCommentTest/0");
|
||||
ASSERT_TRUE(test_suite != nullptr);
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0");
|
||||
ASSERT_TRUE(test_case != NULL);
|
||||
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suite->name());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), test_suite->type_param());
|
||||
EXPECT_TRUE(test_suite->should_run());
|
||||
EXPECT_EQ(0, test_suite->disabled_test_count());
|
||||
EXPECT_EQ(1, test_suite->test_to_run_count());
|
||||
ASSERT_EQ(1, test_suite->total_test_count());
|
||||
EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_case->type_param());
|
||||
EXPECT_TRUE(test_case->should_run());
|
||||
EXPECT_EQ(0, test_case->disabled_test_count());
|
||||
EXPECT_EQ(1, test_case->test_to_run_count());
|
||||
ASSERT_EQ(1, test_case->total_test_count());
|
||||
|
||||
tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
tests = UnitTestHelper::GetSortedTests(test_case);
|
||||
|
||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
||||
EXPECT_TRUE(tests[0]->should_run());
|
||||
|
||||
delete[] tests;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
}
|
||||
|
||||
TEST(ApiTest, TestSuiteDisabledAccessorsWork) {
|
||||
const TestSuite* test_suite = UnitTestHelper::FindTestSuite("DISABLED_Test");
|
||||
ASSERT_TRUE(test_suite != nullptr);
|
||||
TEST(ApiTest, TestCaseDisabledAccessorsWork) {
|
||||
const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test");
|
||||
ASSERT_TRUE(test_case != NULL);
|
||||
|
||||
EXPECT_STREQ("DISABLED_Test", test_suite->name());
|
||||
EXPECT_TRUE(IsNull(test_suite->type_param()));
|
||||
EXPECT_FALSE(test_suite->should_run());
|
||||
EXPECT_EQ(1, test_suite->disabled_test_count());
|
||||
EXPECT_EQ(0, test_suite->test_to_run_count());
|
||||
ASSERT_EQ(1, test_suite->total_test_count());
|
||||
EXPECT_STREQ("DISABLED_Test", test_case->name());
|
||||
EXPECT_TRUE(IsNull(test_case->type_param()));
|
||||
EXPECT_FALSE(test_case->should_run());
|
||||
EXPECT_EQ(1, test_case->disabled_test_count());
|
||||
EXPECT_EQ(0, test_case->test_to_run_count());
|
||||
ASSERT_EQ(1, test_case->total_test_count());
|
||||
|
||||
const TestInfo* const test_info = test_suite->GetTestInfo(0);
|
||||
const TestInfo* const test_info = test_case->GetTestInfo(0);
|
||||
EXPECT_STREQ("Dummy2", test_info->name());
|
||||
EXPECT_STREQ("DISABLED_Test", test_info->test_suite_name());
|
||||
EXPECT_STREQ("DISABLED_Test", test_info->test_case_name());
|
||||
EXPECT_TRUE(IsNull(test_info->value_param()));
|
||||
EXPECT_TRUE(IsNull(test_info->type_param()));
|
||||
EXPECT_FALSE(test_info->should_run());
|
||||
}
|
||||
|
||||
// These two tests are here to provide support for testing
|
||||
// test_suite_to_run_count, disabled_test_count, and test_to_run_count.
|
||||
// test_case_to_run_count, disabled_test_count, and test_to_run_count.
|
||||
TEST(ApiTest, DISABLED_Dummy1) {}
|
||||
TEST(DISABLED_Test, Dummy2) {}
|
||||
|
||||
class FinalSuccessChecker : public Environment {
|
||||
protected:
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
UnitTest* unit_test = UnitTest::GetInstance();
|
||||
|
||||
EXPECT_EQ(1 + kTypedTestSuites, unit_test->successful_test_suite_count());
|
||||
EXPECT_EQ(1 + kTypedTestCases, unit_test->successful_test_case_count());
|
||||
EXPECT_EQ(3 + kTypedTests, unit_test->successful_test_count());
|
||||
EXPECT_EQ(0, unit_test->failed_test_suite_count());
|
||||
EXPECT_EQ(0, unit_test->failed_test_case_count());
|
||||
EXPECT_EQ(0, unit_test->failed_test_count());
|
||||
EXPECT_TRUE(unit_test->Passed());
|
||||
EXPECT_FALSE(unit_test->Failed());
|
||||
ASSERT_EQ(2 + kTypedTestSuites, unit_test->total_test_suite_count());
|
||||
ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count());
|
||||
|
||||
const TestSuite** const test_suites = UnitTestHelper::GetSortedTestSuites();
|
||||
const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases();
|
||||
|
||||
EXPECT_STREQ("ApiTest", test_suites[0]->name());
|
||||
EXPECT_TRUE(IsNull(test_suites[0]->type_param()));
|
||||
EXPECT_TRUE(test_suites[0]->should_run());
|
||||
EXPECT_EQ(1, test_suites[0]->disabled_test_count());
|
||||
ASSERT_EQ(4, test_suites[0]->total_test_count());
|
||||
EXPECT_EQ(3, test_suites[0]->successful_test_count());
|
||||
EXPECT_EQ(0, test_suites[0]->failed_test_count());
|
||||
EXPECT_TRUE(test_suites[0]->Passed());
|
||||
EXPECT_FALSE(test_suites[0]->Failed());
|
||||
EXPECT_STREQ("ApiTest", test_cases[0]->name());
|
||||
EXPECT_TRUE(IsNull(test_cases[0]->type_param()));
|
||||
EXPECT_TRUE(test_cases[0]->should_run());
|
||||
EXPECT_EQ(1, test_cases[0]->disabled_test_count());
|
||||
ASSERT_EQ(4, test_cases[0]->total_test_count());
|
||||
EXPECT_EQ(3, test_cases[0]->successful_test_count());
|
||||
EXPECT_EQ(0, test_cases[0]->failed_test_count());
|
||||
EXPECT_TRUE(test_cases[0]->Passed());
|
||||
EXPECT_FALSE(test_cases[0]->Failed());
|
||||
|
||||
EXPECT_STREQ("DISABLED_Test", test_suites[1]->name());
|
||||
EXPECT_TRUE(IsNull(test_suites[1]->type_param()));
|
||||
EXPECT_FALSE(test_suites[1]->should_run());
|
||||
EXPECT_EQ(1, test_suites[1]->disabled_test_count());
|
||||
ASSERT_EQ(1, test_suites[1]->total_test_count());
|
||||
EXPECT_EQ(0, test_suites[1]->successful_test_count());
|
||||
EXPECT_EQ(0, test_suites[1]->failed_test_count());
|
||||
EXPECT_STREQ("DISABLED_Test", test_cases[1]->name());
|
||||
EXPECT_TRUE(IsNull(test_cases[1]->type_param()));
|
||||
EXPECT_FALSE(test_cases[1]->should_run());
|
||||
EXPECT_EQ(1, test_cases[1]->disabled_test_count());
|
||||
ASSERT_EQ(1, test_cases[1]->total_test_count());
|
||||
EXPECT_EQ(0, test_cases[1]->successful_test_count());
|
||||
EXPECT_EQ(0, test_cases[1]->failed_test_count());
|
||||
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(),
|
||||
test_suites[2]->type_param());
|
||||
EXPECT_TRUE(test_suites[2]->should_run());
|
||||
EXPECT_EQ(0, test_suites[2]->disabled_test_count());
|
||||
ASSERT_EQ(1, test_suites[2]->total_test_count());
|
||||
EXPECT_EQ(1, test_suites[2]->successful_test_count());
|
||||
EXPECT_EQ(0, test_suites[2]->failed_test_count());
|
||||
EXPECT_TRUE(test_suites[2]->Passed());
|
||||
EXPECT_FALSE(test_suites[2]->Failed());
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_cases[2]->type_param());
|
||||
EXPECT_TRUE(test_cases[2]->should_run());
|
||||
EXPECT_EQ(0, test_cases[2]->disabled_test_count());
|
||||
ASSERT_EQ(1, test_cases[2]->total_test_count());
|
||||
EXPECT_EQ(1, test_cases[2]->successful_test_count());
|
||||
EXPECT_EQ(0, test_cases[2]->failed_test_count());
|
||||
EXPECT_TRUE(test_cases[2]->Passed());
|
||||
EXPECT_FALSE(test_cases[2]->Failed());
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
const TestSuite* test_suite = UnitTestHelper::FindTestSuite("ApiTest");
|
||||
const TestInfo** tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest");
|
||||
const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case);
|
||||
EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[0]->test_suite_name());
|
||||
EXPECT_STREQ("ApiTest", tests[0]->test_case_name());
|
||||
EXPECT_FALSE(tests[0]->should_run());
|
||||
|
||||
EXPECT_STREQ("TestSuiteDisabledAccessorsWork", tests[1]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[1]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[1]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[1]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[1]->type_param()));
|
||||
EXPECT_TRUE(tests[1]->should_run());
|
||||
EXPECT_TRUE(tests[1]->result()->Passed());
|
||||
EXPECT_EQ(0, tests[1]->result()->test_property_count());
|
||||
|
||||
EXPECT_STREQ("TestSuiteImmutableAccessorsWork", tests[2]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[2]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[2]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[2]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[2]->type_param()));
|
||||
EXPECT_TRUE(tests[2]->should_run());
|
||||
|
|
@ -288,7 +298,7 @@ class FinalSuccessChecker : public Environment {
|
|||
EXPECT_EQ(0, tests[2]->result()->test_property_count());
|
||||
|
||||
EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name());
|
||||
EXPECT_STREQ("ApiTest", tests[3]->test_suite_name());
|
||||
EXPECT_STREQ("ApiTest", tests[3]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[3]->value_param()));
|
||||
EXPECT_TRUE(IsNull(tests[3]->type_param()));
|
||||
EXPECT_TRUE(tests[3]->should_run());
|
||||
|
|
@ -300,19 +310,21 @@ class FinalSuccessChecker : public Environment {
|
|||
|
||||
delete[] tests;
|
||||
|
||||
test_suite = UnitTestHelper::FindTestSuite("TestSuiteWithCommentTest/0");
|
||||
tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0");
|
||||
tests = UnitTestHelper::GetSortedTests(test_case);
|
||||
|
||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||
EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name());
|
||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
||||
EXPECT_TRUE(tests[0]->should_run());
|
||||
EXPECT_TRUE(tests[0]->result()->Passed());
|
||||
EXPECT_EQ(0, tests[0]->result()->test_property_count());
|
||||
|
||||
delete[] tests;
|
||||
delete[] test_suites;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
delete[] test_cases;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -33,14 +33,14 @@
|
|||
// Sometimes it's desirable to build most of Google Test's own tests
|
||||
// by compiling a single file. This file serves this purpose.
|
||||
#include "test/googletest-filepath-test.cc"
|
||||
#include "test/googletest-linked-ptr-test.cc"
|
||||
#include "test/googletest-message-test.cc"
|
||||
#include "test/googletest-options-test.cc"
|
||||
#include "test/googletest-port-test.cc"
|
||||
#include "test/googletest-test-part-test.cc"
|
||||
#include "test/gtest-typed-test2_test.cc"
|
||||
#include "test/gtest-typed-test_test.cc"
|
||||
#include "test/gtest_pred_impl_unittest.cc"
|
||||
#include "test/gtest_prod_test.cc"
|
||||
#include "test/gtest_skip_test.cc"
|
||||
#include "test/googletest-test-part-test.cc"
|
||||
#include "test/gtest-typed-test_test.cc"
|
||||
#include "test/gtest-typed-test2_test.cc"
|
||||
#include "test/gtest_unittest.cc"
|
||||
#include "test/production.cc"
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ TEST(Test, Test) {
|
|||
try {
|
||||
AssertFalse();
|
||||
} catch(const testing::AssertionException& e) {
|
||||
if (strstr(e.what(), "Expected failure") != nullptr) throw;
|
||||
if (strstr(e.what(), "Expected failure") != NULL)
|
||||
throw;
|
||||
|
||||
printf("%s",
|
||||
"A failed assertion did throw an exception of the right type, "
|
||||
|
|
@ -96,6 +97,7 @@ TEST(Test, Test) {
|
|||
int kTestForContinuingTest = 0;
|
||||
|
||||
TEST(Test, Test2) {
|
||||
// FIXME: how to force Test2 to be after Test?
|
||||
kTestForContinuingTest = 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class MyEnvironment : public testing::Environment {
|
|||
// Depending on the value of failure_in_set_up_, SetUp() will
|
||||
// generate a non-fatal failure, generate a fatal failure, or
|
||||
// succeed.
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
set_up_was_run_ = true;
|
||||
|
||||
switch (failure_in_set_up_) {
|
||||
|
|
@ -69,7 +69,7 @@ class MyEnvironment : public testing::Environment {
|
|||
}
|
||||
|
||||
// Generates a non-fatal failure.
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
tear_down_was_run_ = true;
|
||||
ADD_FAILURE() << "Expected non-fatal failure in global tear-down.";
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ void Check(bool condition, const char* msg) {
|
|||
}
|
||||
}
|
||||
|
||||
// Runs the tests. Return true if and only if successful.
|
||||
// Runs the tests. Return true iff successful.
|
||||
//
|
||||
// The 'failure' parameter specifies the type of failure that should
|
||||
// be generated by the global set-up.
|
||||
|
|
|
|||
20
security/nss/gtests/google_test/gtest/test/gtest_help_test.py
Executable file → Normal file
20
security/nss/gtests/google_test/gtest/test/gtest_help_test.py
Executable file → Normal file
|
|
@ -43,7 +43,6 @@ import gtest_test_utils
|
|||
|
||||
|
||||
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
|
||||
IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
|
||||
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
|
||||
|
|
@ -69,7 +68,6 @@ HELP_REGEX = re.compile(
|
|||
FLAG_PREFIX + r'shuffle.*' +
|
||||
FLAG_PREFIX + r'random_seed=.*' +
|
||||
FLAG_PREFIX + r'color=.*' +
|
||||
FLAG_PREFIX + r'brief.*' +
|
||||
FLAG_PREFIX + r'print_time.*' +
|
||||
FLAG_PREFIX + r'output=.*' +
|
||||
FLAG_PREFIX + r'break_on_failure.*' +
|
||||
|
|
@ -109,18 +107,18 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||
"""
|
||||
|
||||
exit_code, output = RunWithFlag(flag)
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertTrue(HELP_REGEX.search(output), output)
|
||||
self.assertEquals(0, exit_code)
|
||||
self.assert_(HELP_REGEX.search(output), output)
|
||||
|
||||
if IS_LINUX or IS_GNUKFREEBSD:
|
||||
self.assertTrue(STREAM_RESULT_TO_FLAG in output, output)
|
||||
if IS_LINUX:
|
||||
self.assert_(STREAM_RESULT_TO_FLAG in output, output)
|
||||
else:
|
||||
self.assertTrue(STREAM_RESULT_TO_FLAG not in output, output)
|
||||
self.assert_(STREAM_RESULT_TO_FLAG not in output, output)
|
||||
|
||||
if SUPPORTS_DEATH_TESTS and not IS_WINDOWS:
|
||||
self.assertTrue(DEATH_TEST_STYLE_FLAG in output, output)
|
||||
self.assert_(DEATH_TEST_STYLE_FLAG in output, output)
|
||||
else:
|
||||
self.assertTrue(DEATH_TEST_STYLE_FLAG not in output, output)
|
||||
self.assert_(DEATH_TEST_STYLE_FLAG not in output, output)
|
||||
|
||||
def TestNonHelpFlag(self, flag):
|
||||
"""Verifies correct behavior when no help flag is specified.
|
||||
|
|
@ -133,8 +131,8 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||
"""
|
||||
|
||||
exit_code, output = RunWithFlag(flag)
|
||||
self.assertTrue(exit_code != 0)
|
||||
self.assertTrue(not HELP_REGEX.search(output), output)
|
||||
self.assert_(exit_code != 0)
|
||||
self.assert_(not HELP_REGEX.search(output), output)
|
||||
|
||||
def testPrintsHelpWithFullFlag(self):
|
||||
self.TestHelpFlag('--help')
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def normalize(obj):
|
|||
else:
|
||||
return normalize(value)
|
||||
if isinstance(obj, dict):
|
||||
return {k: _normalize(k, v) for k, v in list(obj.items())}
|
||||
return {k: _normalize(k, v) for k, v in obj.items()}
|
||||
if isinstance(obj, list):
|
||||
return [normalize(x) for x in obj]
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -46,42 +46,16 @@ GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
|||
GTEST_OUTPUT_FLAG = '--gtest_output'
|
||||
|
||||
EXPECTED_XML = """<\?xml version="1.0" encoding="UTF-8"\?>
|
||||
<testsuites tests="16" name="AllTests">
|
||||
<testsuites tests="2" name="AllTests">
|
||||
<testsuite name="FooTest" tests="2">
|
||||
<testcase name="Test1" file=".*gtest_list_output_unittest_.cc" line="43" />
|
||||
<testcase name="Test2" file=".*gtest_list_output_unittest_.cc" line="45" />
|
||||
</testsuite>
|
||||
<testsuite name="FooTestFixture" tests="2">
|
||||
<testcase name="Test3" file=".*gtest_list_output_unittest_.cc" line="48" />
|
||||
<testcase name="Test4" file=".*gtest_list_output_unittest_.cc" line="49" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/0" tests="2">
|
||||
<testcase name="Test7" type_param="int" file=".*gtest_list_output_unittest_.cc" line="60" />
|
||||
<testcase name="Test8" type_param="int" file=".*gtest_list_output_unittest_.cc" line="61" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/1" tests="2">
|
||||
<testcase name="Test7" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="60" />
|
||||
<testcase name="Test8" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="61" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/0" tests="2">
|
||||
<testcase name="Test9" type_param="int" file=".*gtest_list_output_unittest_.cc" line="66" />
|
||||
<testcase name="Test10" type_param="int" file=".*gtest_list_output_unittest_.cc" line="67" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/1" tests="2">
|
||||
<testcase name="Test9" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="66" />
|
||||
<testcase name="Test10" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="67" />
|
||||
</testsuite>
|
||||
<testsuite name="ValueParam/ValueParamTest" tests="4">
|
||||
<testcase name="Test5/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="52" />
|
||||
<testcase name="Test5/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="52" />
|
||||
<testcase name="Test6/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="53" />
|
||||
<testcase name="Test6/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="53" />
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
"""
|
||||
|
||||
EXPECTED_JSON = """{
|
||||
"tests": 16,
|
||||
"tests": 2,
|
||||
"name": "AllTests",
|
||||
"testsuites": \[
|
||||
{
|
||||
|
|
@ -99,124 +73,6 @@ EXPECTED_JSON = """{
|
|||
"line": 45
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "FooTestFixture",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test3",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 48
|
||||
},
|
||||
{
|
||||
"name": "Test4",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 49
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "TypedTest\\\\/0",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test7",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 60
|
||||
},
|
||||
{
|
||||
"name": "Test8",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 61
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "TypedTest\\\\/1",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test7",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 60
|
||||
},
|
||||
{
|
||||
"name": "Test8",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 61
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "Single\\\\/TypeParameterizedTestSuite\\\\/0",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test9",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 66
|
||||
},
|
||||
{
|
||||
"name": "Test10",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 67
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "Single\\\\/TypeParameterizedTestSuite\\\\/1",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test9",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 66
|
||||
},
|
||||
{
|
||||
"name": "Test10",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 67
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "ValueParam\\\\/ValueParamTest",
|
||||
"tests": 4,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test5\\\\/0",
|
||||
"value_param": "33",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 52
|
||||
},
|
||||
{
|
||||
"name": "Test5\\\\/1",
|
||||
"value_param": "42",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 52
|
||||
},
|
||||
{
|
||||
"name": "Test6\\\\/0",
|
||||
"value_param": "33",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 53
|
||||
},
|
||||
{
|
||||
"name": "Test6\\\\/1",
|
||||
"value_param": "42",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 53
|
||||
}
|
||||
\]
|
||||
}
|
||||
\]
|
||||
}
|
||||
|
|
@ -258,9 +114,8 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
|||
p = gtest_test_utils.Subprocess(
|
||||
command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir())
|
||||
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assertTrue(os.path.isfile(file_path))
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
with open(file_path) as f:
|
||||
result = f.read()
|
||||
return result
|
||||
|
|
@ -273,7 +128,7 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
|||
for actual_line in actual_lines:
|
||||
expected_line = expected_lines[line_count]
|
||||
expected_line_re = re.compile(expected_line.strip())
|
||||
self.assertTrue(
|
||||
self.assert_(
|
||||
expected_line_re.match(actual_line.strip()),
|
||||
('actual output of "%s",\n'
|
||||
'which does not match expected regex of "%s"\n'
|
||||
|
|
|
|||
|
|
@ -44,32 +44,6 @@ TEST(FooTest, Test1) {}
|
|||
|
||||
TEST(FooTest, Test2) {}
|
||||
|
||||
class FooTestFixture : public ::testing::Test {};
|
||||
TEST_F(FooTestFixture, Test3) {}
|
||||
TEST_F(FooTestFixture, Test4) {}
|
||||
|
||||
class ValueParamTest : public ::testing::TestWithParam<int> {};
|
||||
TEST_P(ValueParamTest, Test5) {}
|
||||
TEST_P(ValueParamTest, Test6) {}
|
||||
INSTANTIATE_TEST_SUITE_P(ValueParam, ValueParamTest, ::testing::Values(33, 42));
|
||||
|
||||
template <typename T>
|
||||
class TypedTest : public ::testing::Test {};
|
||||
typedef testing::Types<int, bool> TypedTestTypes;
|
||||
TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
|
||||
TYPED_TEST(TypedTest, Test7) {}
|
||||
TYPED_TEST(TypedTest, Test8) {}
|
||||
|
||||
template <typename T>
|
||||
class TypeParameterizedTestSuite : public ::testing::Test {};
|
||||
TYPED_TEST_SUITE_P(TypeParameterizedTestSuite);
|
||||
TYPED_TEST_P(TypeParameterizedTestSuite, Test9) {}
|
||||
TYPED_TEST_P(TypeParameterizedTestSuite, Test10) {}
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, Test9, Test10);
|
||||
typedef testing::Types<int, bool> TypeParameterizedTestSuiteTypes; // NOLINT
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
|
||||
TypeParameterizedTestSuiteTypes);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 11/05/2019 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
|
||||
// Regression test for gtest_pred_impl.h
|
||||
|
|
@ -78,8 +78,9 @@ bool PredFunction1(T1 v1) {
|
|||
return v1 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
bool PredFunction1Int(int v1) {
|
||||
return v1 > 0;
|
||||
}
|
||||
|
|
@ -121,13 +122,13 @@ struct PredFormatFunctor1 {
|
|||
|
||||
class Predicate1Test : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
expected_to_finish_ = true;
|
||||
finished_ = false;
|
||||
n1_ = 0;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// Verifies that each of the predicate's arguments was evaluated
|
||||
// exactly once.
|
||||
EXPECT_EQ(1, n1_) <<
|
||||
|
|
@ -143,10 +144,10 @@ class Predicate1Test : public testing::Test {
|
|||
}
|
||||
}
|
||||
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
// true iff the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true if and only if the test function did run to finish.
|
||||
// true iff the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
|
@ -464,8 +465,9 @@ bool PredFunction2(T1 v1, T2 v2) {
|
|||
return v1 + v2 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
bool PredFunction2Int(int v1, int v2) {
|
||||
return v1 + v2 > 0;
|
||||
}
|
||||
|
|
@ -512,13 +514,13 @@ struct PredFormatFunctor2 {
|
|||
|
||||
class Predicate2Test : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
expected_to_finish_ = true;
|
||||
finished_ = false;
|
||||
n1_ = n2_ = 0;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// Verifies that each of the predicate's arguments was evaluated
|
||||
// exactly once.
|
||||
EXPECT_EQ(1, n1_) <<
|
||||
|
|
@ -537,10 +539,10 @@ class Predicate2Test : public testing::Test {
|
|||
}
|
||||
}
|
||||
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
// true iff the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true if and only if the test function did run to finish.
|
||||
// true iff the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
|
@ -892,8 +894,9 @@ bool PredFunction3(T1 v1, T2 v2, T3 v3) {
|
|||
return v1 + v2 + v3 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
bool PredFunction3Int(int v1, int v2, int v3) {
|
||||
return v1 + v2 + v3 > 0;
|
||||
}
|
||||
|
|
@ -945,13 +948,13 @@ struct PredFormatFunctor3 {
|
|||
|
||||
class Predicate3Test : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
expected_to_finish_ = true;
|
||||
finished_ = false;
|
||||
n1_ = n2_ = n3_ = 0;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// Verifies that each of the predicate's arguments was evaluated
|
||||
// exactly once.
|
||||
EXPECT_EQ(1, n1_) <<
|
||||
|
|
@ -973,10 +976,10 @@ class Predicate3Test : public testing::Test {
|
|||
}
|
||||
}
|
||||
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
// true iff the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true if and only if the test function did run to finish.
|
||||
// true iff the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
|
@ -1362,8 +1365,9 @@ bool PredFunction4(T1 v1, T2 v2, T3 v3, T4 v4) {
|
|||
return v1 + v2 + v3 + v4 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
bool PredFunction4Int(int v1, int v2, int v3, int v4) {
|
||||
return v1 + v2 + v3 + v4 > 0;
|
||||
}
|
||||
|
|
@ -1420,13 +1424,13 @@ struct PredFormatFunctor4 {
|
|||
|
||||
class Predicate4Test : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
expected_to_finish_ = true;
|
||||
finished_ = false;
|
||||
n1_ = n2_ = n3_ = n4_ = 0;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// Verifies that each of the predicate's arguments was evaluated
|
||||
// exactly once.
|
||||
EXPECT_EQ(1, n1_) <<
|
||||
|
|
@ -1451,10 +1455,10 @@ class Predicate4Test : public testing::Test {
|
|||
}
|
||||
}
|
||||
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
// true iff the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true if and only if the test function did run to finish.
|
||||
// true iff the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
|
@ -1874,8 +1878,9 @@ bool PredFunction5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) {
|
|||
return v1 + v2 + v3 + v4 + v5 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
bool PredFunction5Int(int v1, int v2, int v3, int v4, int v5) {
|
||||
return v1 + v2 + v3 + v4 + v5 > 0;
|
||||
}
|
||||
|
|
@ -1937,13 +1942,13 @@ struct PredFormatFunctor5 {
|
|||
|
||||
class Predicate5Test : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
virtual void SetUp() {
|
||||
expected_to_finish_ = true;
|
||||
finished_ = false;
|
||||
n1_ = n2_ = n3_ = n4_ = n5_ = 0;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
virtual void TearDown() {
|
||||
// Verifies that each of the predicate's arguments was evaluated
|
||||
// exactly once.
|
||||
EXPECT_EQ(1, n1_) <<
|
||||
|
|
@ -1971,10 +1976,10 @@ class Predicate5Test : public testing::Test {
|
|||
}
|
||||
}
|
||||
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
// true iff the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true if and only if the test function did run to finish.
|
||||
// true iff the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace {
|
|||
|
||||
class PrematureExitTest : public Test {
|
||||
public:
|
||||
// Returns true if and only if the given file exists.
|
||||
// Returns true iff the given file exists.
|
||||
static bool FileExists(const char* filepath) {
|
||||
StatStruct stat;
|
||||
return Stat(filepath, &stat) == 0;
|
||||
|
|
@ -56,12 +56,12 @@ class PrematureExitTest : public Test {
|
|||
premature_exit_file_path_ = GetEnv("TEST_PREMATURE_EXIT_FILE");
|
||||
|
||||
// Normalize NULL to "" for ease of handling.
|
||||
if (premature_exit_file_path_ == nullptr) {
|
||||
if (premature_exit_file_path_ == NULL) {
|
||||
premature_exit_file_path_ = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if and only if the premature-exit file exists.
|
||||
// Returns true iff the premature-exit file exists.
|
||||
bool PrematureExitFileExists() const {
|
||||
return FileExists(premature_exit_file_path_);
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ int main(int argc, char **argv) {
|
|||
// Test that the premature-exit file is deleted upon return from
|
||||
// RUN_ALL_TESTS().
|
||||
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE");
|
||||
if (filepath != nullptr && *filepath != '\0') {
|
||||
if (filepath != NULL && *filepath != '\0') {
|
||||
if (PrematureExitTest::FileExists(filepath)) {
|
||||
printf(
|
||||
"File %s shouldn't exist after the test program finishes, but does.",
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ int g_environment_tear_down_count = 0;
|
|||
class MyEnvironment : public testing::Environment {
|
||||
public:
|
||||
MyEnvironment() {}
|
||||
void SetUp() override { g_environment_set_up_count++; }
|
||||
void TearDown() override { g_environment_tear_down_count++; }
|
||||
virtual void SetUp() { g_environment_set_up_count++; }
|
||||
virtual void TearDown() { g_environment_tear_down_count++; }
|
||||
};
|
||||
|
||||
// A test that should fail.
|
||||
|
|
@ -117,12 +117,13 @@ const int kNumberOfParamTests = 10;
|
|||
class MyParamTest : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(MyParamTest, ShouldPass) {
|
||||
// FIXME: Make parameter value checking robust WRT order of tests.
|
||||
GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam());
|
||||
g_param_test_count++;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MyParamSequence,
|
||||
MyParamTest,
|
||||
testing::Range(0, kNumberOfParamTests));
|
||||
INSTANTIATE_TEST_CASE_P(MyParamSequence,
|
||||
MyParamTest,
|
||||
testing::Range(0, kNumberOfParamTests));
|
||||
|
||||
// Resets the count for each test.
|
||||
void ResetCounts() {
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019 Google LLC. 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 Google Test's gtest skip in environment setup behavior.
|
||||
|
||||
This script invokes gtest_skip_in_environment_setup_test_ and verifies its
|
||||
output.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
# Path to the gtest_skip_in_environment_setup_test binary
|
||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_skip_test')
|
||||
|
||||
OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
|
||||
|
||||
|
||||
# Test.
|
||||
class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSkipEntireEnvironmentTest(self):
|
||||
self.assertIn('Skipped\nskipping single test\n', OUTPUT)
|
||||
skip_fixture = 'Skipped\nskipping all tests for this fixture\n'
|
||||
self.assertIsNotNone(
|
||||
re.search(skip_fixture + '.*' + skip_fixture, OUTPUT, flags=re.DOTALL),
|
||||
repr(OUTPUT))
|
||||
self.assertNotIn('FAILED', OUTPUT)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019 Google LLC. 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 Google Test's gtest skip in environment setup behavior.
|
||||
|
||||
This script invokes gtest_skip_in_environment_setup_test_ and verifies its
|
||||
output.
|
||||
"""
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
# Path to the gtest_skip_in_environment_setup_test binary
|
||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||
'gtest_skip_in_environment_setup_test')
|
||||
|
||||
OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
|
||||
|
||||
|
||||
# Test.
|
||||
class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSkipEntireEnvironmentTest(self):
|
||||
self.assertIn('Skipping the entire environment', OUTPUT)
|
||||
self.assertNotIn('FAILED', OUTPUT)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright 2019, Google LLC.
|
||||
// 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 LLC. 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.
|
||||
//
|
||||
// This test verifies that skipping in the environment results in the
|
||||
// testcases being skipped.
|
||||
|
||||
#include <iostream>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
class SetupEnvironment : public testing::Environment {
|
||||
public:
|
||||
void SetUp() override { GTEST_SKIP() << "Skipping the entire environment"; }
|
||||
};
|
||||
|
||||
TEST(Test, AlwaysFails) { EXPECT_EQ(true, false); }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
testing::AddGlobalTestEnvironment(new SetupEnvironment());
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// 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.
|
||||
//
|
||||
// Author: arseny.aprelev@gmail.com (Arseny Aprelev)
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using ::testing::Test;
|
||||
|
||||
TEST(SkipTest, DoesSkip) {
|
||||
GTEST_SKIP() << "skipping single test";
|
||||
EXPECT_EQ(0, 1);
|
||||
}
|
||||
|
||||
class Fixture : public Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
GTEST_SKIP() << "skipping all tests for this fixture";
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Fixture, SkipsOneTest) {
|
||||
EXPECT_EQ(5, 7);
|
||||
}
|
||||
|
||||
TEST_F(Fixture, SkipsAnotherTest) {
|
||||
EXPECT_EQ(99, 100);
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@ namespace {
|
|||
using internal::Notification;
|
||||
using internal::TestPropertyKeyIs;
|
||||
using internal::ThreadWithParam;
|
||||
using internal::scoped_ptr;
|
||||
|
||||
// In order to run tests in this file, for platforms where Google Test is
|
||||
// thread safe, implement ThreadWithParam. See the description of its API
|
||||
|
|
@ -118,7 +119,7 @@ void CheckTestFailureCount(int expected_failures) {
|
|||
// concurrently.
|
||||
TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) {
|
||||
{
|
||||
std::unique_ptr<ThreadWithParam<int> > threads[kThreadCount];
|
||||
scoped_ptr<ThreadWithParam<int> > threads[kThreadCount];
|
||||
Notification threads_can_start;
|
||||
for (int i = 0; i != kThreadCount; i++)
|
||||
threads[i].reset(new ThreadWithParam<int>(&ManyAsserts,
|
||||
|
|
@ -162,7 +163,7 @@ void FailingThread(bool is_fatal) {
|
|||
}
|
||||
|
||||
void GenerateFatalFailureInAnotherThread(bool is_fatal) {
|
||||
ThreadWithParam<bool> thread(&FailingThread, is_fatal, nullptr);
|
||||
ThreadWithParam<bool> thread(&FailingThread, is_fatal, NULL);
|
||||
thread.Join();
|
||||
}
|
||||
|
||||
|
|
|
|||
20
security/nss/gtests/google_test/gtest/test/gtest_test_utils.py
Executable file → Normal file
20
security/nss/gtests/google_test/gtest/test/gtest_test_utils.py
Executable file → Normal file
|
|
@ -36,7 +36,6 @@ import sys
|
|||
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
IS_CYGWIN = os.name == 'posix' and 'CYGWIN' in os.uname()[0]
|
||||
IS_OS2 = os.name == 'os2'
|
||||
|
||||
import atexit
|
||||
import shutil
|
||||
|
|
@ -165,7 +164,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
|
|||
|
||||
path = os.path.abspath(os.path.join(build_dir or GetBuildDir(),
|
||||
executable_name))
|
||||
if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'):
|
||||
if (IS_WINDOWS or IS_CYGWIN) and not path.endswith('.exe'):
|
||||
path += '.exe'
|
||||
|
||||
if not os.path.exists(path):
|
||||
|
|
@ -173,7 +172,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)
|
||||
print(message, file=sys.stderr)
|
||||
print >> sys.stderr, message
|
||||
sys.exit(1)
|
||||
|
||||
return path
|
||||
|
|
@ -215,10 +214,10 @@ class Subprocess:
|
|||
Returns:
|
||||
An object that represents outcome of the executed process. It has the
|
||||
following attributes:
|
||||
terminated_by_signal True if and only if the child process has been
|
||||
terminated by a signal.
|
||||
exited True if and only if the child process exited
|
||||
normally.
|
||||
terminated_by_signal True iff the child process has been terminated
|
||||
by a signal.
|
||||
signal Sygnal that terminated the child process.
|
||||
exited True iff the child process exited normally.
|
||||
exit_code The code with which the child process exited.
|
||||
output Child process's stdout and stderr output
|
||||
combined in a string.
|
||||
|
|
@ -251,7 +250,7 @@ class Subprocess:
|
|||
# Changes made by os.environ.clear are not inheritable by child
|
||||
# processes until Python 2.6. To produce inheritable changes we have
|
||||
# to delete environment items with the del statement.
|
||||
for key in list(dest.keys()):
|
||||
for key in dest.keys():
|
||||
del dest[key]
|
||||
dest.update(src)
|
||||
|
||||
|
|
@ -288,9 +287,10 @@ class Subprocess:
|
|||
else: # os.WIFEXITED(ret_code) should return True here.
|
||||
self._return_code = os.WEXITSTATUS(ret_code)
|
||||
|
||||
if bool(self._return_code & 0x80000000):
|
||||
if self._return_code < 0:
|
||||
self.terminated_by_signal = True
|
||||
self.exited = False
|
||||
self.signal = -self._return_code
|
||||
else:
|
||||
self.terminated_by_signal = False
|
||||
self.exited = True
|
||||
|
|
@ -306,6 +306,8 @@ def Main():
|
|||
_ParseAndStripGTestFlags(sys.argv)
|
||||
# The tested binaries should not be writing XML output files unless the
|
||||
# script explicitly instructs them to.
|
||||
# FIXME: Move this into Subprocess when we implement
|
||||
# passing environment into it as a parameter.
|
||||
if GTEST_OUTPUT_VAR_NAME in os.environ:
|
||||
del os.environ[GTEST_OUTPUT_VAR_NAME]
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class GTestTestFilterTest(gtest_test_utils.TestCase):
|
|||
subprocess_env[TESTBRIDGE_NAME] = '*.TestThatSucceeds'
|
||||
p = gtest_test_utils.Subprocess(COMMAND, env=subprocess_env)
|
||||
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
|
||||
Assert('filter = *.TestThatSucceeds' in p.output)
|
||||
Assert('[ OK ] TestFilterTest.TestThatSucceeds' in p.output)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ void TestFailureThrowsRuntimeError() {
|
|||
try {
|
||||
EXPECT_EQ(2, 3) << "Expected failure";
|
||||
} catch(const std::runtime_error& e) {
|
||||
if (strstr(e.what(), "Expected failure") != nullptr) return;
|
||||
if (strstr(e.what(), "Expected failure") != NULL)
|
||||
return;
|
||||
|
||||
printf("%s",
|
||||
"A failed assertion did throw an exception of the right type, "
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -34,8 +34,12 @@
|
|||
|
||||
class PropertyOne : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override { RecordProperty("SetUpProp", 1); }
|
||||
void TearDown() override { RecordProperty("TearDownProp", 1); }
|
||||
virtual void SetUp() {
|
||||
RecordProperty("SetUpProp", 1);
|
||||
}
|
||||
virtual void TearDown() {
|
||||
RecordProperty("TearDownProp", 1);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PropertyOne, TestSomeProperties) {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,12 @@
|
|||
|
||||
class PropertyTwo : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override { RecordProperty("SetUpProp", 2); }
|
||||
void TearDown() override { RecordProperty("TearDownProp", 2); }
|
||||
virtual void SetUp() {
|
||||
RecordProperty("SetUpProp", 2);
|
||||
}
|
||||
virtual void TearDown() {
|
||||
RecordProperty("TearDownProp", 2);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PropertyTwo, TestSomeProperties) {
|
||||
|
|
|
|||
19
security/nss/gtests/google_test/gtest/test/gtest_xml_outfiles_test.py
Executable file → Normal file
19
security/nss/gtests/google_test/gtest/test/gtest_xml_outfiles_test.py
Executable file → Normal file
|
|
@ -42,8 +42,8 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
|
|||
|
||||
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuite name="PropertyOne" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyOne">
|
||||
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne">
|
||||
<properties>
|
||||
<property name="SetUpProp" value="1"/>
|
||||
<property name="TestSomeProperty" value="1"/>
|
||||
|
|
@ -56,8 +56,8 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
|||
|
||||
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
|
||||
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo">
|
||||
<properties>
|
||||
<property name="SetUpProp" value="2"/>
|
||||
<property name="TestSomeProperty" value="2"/>
|
||||
|
|
@ -108,14 +108,19 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||
command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
|
||||
p = gtest_test_utils.Subprocess(command,
|
||||
working_dir=gtest_test_utils.GetTempDir())
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
|
||||
# FIXME: libtool causes the built test binary to be
|
||||
# named lt-gtest_xml_outfiles_test_ instead of
|
||||
# gtest_xml_outfiles_test_. To account for this possibility, we
|
||||
# allow both names in the following code. We should remove this
|
||||
# when libtool replacement tool is ready.
|
||||
output_file_name1 = test_name + ".xml"
|
||||
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
||||
output_file_name2 = 'lt-' + output_file_name1
|
||||
output_file2 = os.path.join(self.output_dir_, output_file_name2)
|
||||
self.assertTrue(os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
||||
self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
||||
output_file1)
|
||||
|
||||
expected = minidom.parseString(expected_xml)
|
||||
|
|
|
|||
166
security/nss/gtests/google_test/gtest/test/gtest_xml_output_unittest.py
Executable file → Normal file
166
security/nss/gtests/google_test/gtest/test/gtest_xml_output_unittest.py
Executable file → Normal file
|
|
@ -65,21 +65,21 @@ else:
|
|||
sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)
|
||||
|
||||
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="26" failures="5" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
<testsuites tests="23" failures="4" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="FailedTest">
|
||||
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="Fails" status="run" time="*" classname="FailedTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"/>
|
||||
<testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest">
|
||||
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" time="*" classname="MixedResultTest"/>
|
||||
<testcase name="Fails" status="run" time="*" classname="MixedResultTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
|
|
@ -89,147 +89,116 @@ Expected equality of these values:
|
|||
2
|
||||
3%(stack)s]]></failure>
|
||||
</testcase>
|
||||
<testcase name="DISABLED_test" status="notrun" result="suppressed" time="*" timestamp="*" classname="MixedResultTest"/>
|
||||
<testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="OutputsCData" status="run" result="completed" time="*" timestamp="*" classname="XmlQuotingTest">
|
||||
<testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="OutputsCData" status="run" time="*" classname="XmlQuotingTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Failed
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]></top>" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Failed
|
||||
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]><![CDATA[</top>%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="InvalidCharactersInMessage" status="run" result="completed" time="*" timestamp="*" classname="InvalidCharactersTest">
|
||||
<testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="InvalidCharactersInMessage" status="run" time="*" classname="InvalidCharactersTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Failed
Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Failed
|
||||
Invalid characters in brackets []%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="DISABLED_test_not_run" status="notrun" result="suppressed" time="*" timestamp="*" classname="DisabledTest"/>
|
||||
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" errors="0" time="*">
|
||||
<testcase name="DISABLED_test_not_run" status="notrun" time="*" classname="DisabledTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="SkippedTest" tests="3" failures="1" disabled="0" skipped="2" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Skipped" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
"><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
<testcase name="SkippedWithMessage" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
<testcase name="SkippedAfterFailure" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
|
||||
</testsuite>
|
||||
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="OneProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" errors="0" time="*" SetUpTestCase="yes" TearDownTestCase="aye">
|
||||
<testcase name="OneProperty" status="run" time="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<testcase name="IntValuedProperty" status="run" time="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ThreeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<testcase name="ThreeProperties" status="run" time="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="1"/>
|
||||
<property name="key_2" value="2"/>
|
||||
<property name="key_3" value="3"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" time="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="2"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="RecordProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key_for_utility_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key_for_utility_string" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="HasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="HasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/0" />
|
||||
<testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="TypedTest/0" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/1" />
|
||||
<testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="TypedTest/1" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/0" />
|
||||
<testsuite name="Single/TypeParameterizedTestCase/0" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="Single/TypeParameterizedTestCase/0" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/1" />
|
||||
<testsuite name="Single/TypeParameterizedTestCase/1" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="Single/TypeParameterizedTestCase/1" />
|
||||
</testsuite>
|
||||
</testsuites>""" % {
|
||||
'stack': STACK_TRACE_TEMPLATE
|
||||
}
|
||||
</testsuites>""" % {'stack': STACK_TRACE_TEMPLATE}
|
||||
|
||||
EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0"
|
||||
errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0"
|
||||
errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="3" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testsuite name="NoFixtureTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
|
||||
</testsuite>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_NO_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests">
|
||||
<testsuite name="NonTestSuiteFailure" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="" status="run" result="completed" time="*" timestamp="*" classname="">
|
||||
<failure message="gtest_no_test_unittest.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_no_test_unittest.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>""" % {
|
||||
'stack': STACK_TRACE_TEMPLATE
|
||||
}
|
||||
</testsuites>"""
|
||||
|
||||
GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
|
||||
|
||||
|
|
@ -252,14 +221,14 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||
"""
|
||||
self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1)
|
||||
|
||||
def testNoTestXmlOutput(self):
|
||||
def testEmptyXmlOutput(self):
|
||||
"""Verifies XML output for a Google Test binary without actual tests.
|
||||
|
||||
Runs a test program that generates an XML output for a binary without tests,
|
||||
and tests that the XML output is expected.
|
||||
Runs a test program that generates an empty XML output, and
|
||||
tests that the XML output is expected.
|
||||
"""
|
||||
|
||||
self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_NO_TEST_XML, 0)
|
||||
self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_EMPTY_XML, 0)
|
||||
|
||||
def testTimestampValue(self):
|
||||
"""Checks whether the timestamp attribute in the XML output is valid.
|
||||
|
|
@ -297,17 +266,16 @@ 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
|
||||
|
||||
p = gtest_test_utils.Subprocess(
|
||||
[gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
|
||||
working_dir=gtest_test_utils.GetTempDir())
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assertTrue(os.path.isfile(output_file))
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
self.assert_(os.path.isfile(output_file))
|
||||
|
||||
def testSuppressedXmlOutput(self):
|
||||
"""
|
||||
|
|
@ -330,13 +298,13 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||
p.terminated_by_signal,
|
||||
'%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal))
|
||||
else:
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(1, p.exit_code,
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(1, p.exit_code,
|
||||
"'%s' exited with code %s, which doesn't match "
|
||||
'the expected exit code %s.'
|
||||
% (command, p.exit_code, 1))
|
||||
|
||||
self.assertTrue(not os.path.isfile(xml_path))
|
||||
self.assert_(not os.path.isfile(xml_path))
|
||||
|
||||
def testFilteredTestXmlOutput(self):
|
||||
"""Verifies XML output when a filter is applied.
|
||||
|
|
@ -380,11 +348,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||
p = gtest_test_utils.Subprocess(command, env=environ_copy)
|
||||
|
||||
if p.terminated_by_signal:
|
||||
self.assertTrue(False,
|
||||
self.assert_(False,
|
||||
'%s was killed by signal %d' % (gtest_prog_name, p.signal))
|
||||
else:
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(expected_exit_code, p.exit_code,
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(expected_exit_code, p.exit_code,
|
||||
"'%s' exited with code %s, which doesn't match "
|
||||
'the expected exit code %s.'
|
||||
% (command, p.exit_code, expected_exit_code))
|
||||
|
|
|
|||
|
|
@ -67,22 +67,6 @@ TEST_F(DisabledTest, DISABLED_test_not_run) {
|
|||
FAIL() << "Unexpected failure: Disabled test should not be run";
|
||||
}
|
||||
|
||||
class SkippedTest : public Test {
|
||||
};
|
||||
|
||||
TEST_F(SkippedTest, Skipped) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
TEST_F(SkippedTest, SkippedWithMessage) {
|
||||
GTEST_SKIP() << "It is good practice to tell why you skip a test.";
|
||||
}
|
||||
|
||||
TEST_F(SkippedTest, SkippedAfterFailure) {
|
||||
EXPECT_EQ(1, 2);
|
||||
GTEST_SKIP() << "It is good practice to tell why you skip a test.";
|
||||
}
|
||||
|
||||
TEST(MixedResultTest, Succeeds) {
|
||||
EXPECT_EQ(1, 1);
|
||||
ASSERT_EQ(1, 1);
|
||||
|
|
@ -110,10 +94,8 @@ TEST(InvalidCharactersTest, InvalidCharactersInMessage) {
|
|||
|
||||
class PropertyRecordingTest : public Test {
|
||||
public:
|
||||
static void SetUpTestSuite() { RecordProperty("SetUpTestSuite", "yes"); }
|
||||
static void TearDownTestSuite() {
|
||||
RecordProperty("TearDownTestSuite", "aye");
|
||||
}
|
||||
static void SetUpTestCase() { RecordProperty("SetUpTestCase", "yes"); }
|
||||
static void TearDownTestCase() { RecordProperty("TearDownTestCase", "aye"); }
|
||||
};
|
||||
|
||||
TEST_F(PropertyRecordingTest, OneProperty) {
|
||||
|
|
@ -161,25 +143,29 @@ TEST(NoFixtureTest, ExternalUtilityThatCallsRecordStringValuedProperty) {
|
|||
class ValueParamTest : public TestWithParam<int> {};
|
||||
TEST_P(ValueParamTest, HasValueParamAttribute) {}
|
||||
TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {}
|
||||
INSTANTIATE_TEST_SUITE_P(Single, ValueParamTest, Values(33, 42));
|
||||
INSTANTIATE_TEST_CASE_P(Single, ValueParamTest, Values(33, 42));
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
// Verifies that the type parameter name is output in the 'type_param'
|
||||
// XML attribute for typed tests.
|
||||
template <typename T> class TypedTest : public Test {};
|
||||
typedef testing::Types<int, long> TypedTestTypes;
|
||||
TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
|
||||
TYPED_TEST_CASE(TypedTest, TypedTestTypes);
|
||||
TYPED_TEST(TypedTest, HasTypeParamAttribute) {}
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
// Verifies that the type parameter name is output in the 'type_param'
|
||||
// XML attribute for type-parameterized tests.
|
||||
template <typename T>
|
||||
class TypeParameterizedTestSuite : public Test {};
|
||||
TYPED_TEST_SUITE_P(TypeParameterizedTestSuite);
|
||||
TYPED_TEST_P(TypeParameterizedTestSuite, HasTypeParamAttribute) {}
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, HasTypeParamAttribute);
|
||||
typedef testing::Types<int, long> TypeParameterizedTestSuiteTypes; // NOLINT
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
|
||||
TypeParameterizedTestSuiteTypes);
|
||||
template <typename T> class TypeParameterizedTestCase : public Test {};
|
||||
TYPED_TEST_CASE_P(TypeParameterizedTestCase);
|
||||
TYPED_TEST_P(TypeParameterizedTestCase, HasTypeParamAttribute) {}
|
||||
REGISTER_TYPED_TEST_CASE_P(TypeParameterizedTestCase, HasTypeParamAttribute);
|
||||
typedef testing::Types<int, long> TypeParameterizedTestCaseTypes;
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(Single,
|
||||
TypeParameterizedTestCase,
|
||||
TypeParameterizedTestCaseTypes);
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
InitGoogleTest(&argc, argv);
|
||||
|
|
|
|||
43
security/nss/gtests/google_test/gtest/test/gtest_xml_test_utils.py
Executable file → Normal file
43
security/nss/gtests/google_test/gtest/test/gtest_xml_test_utils.py
Executable file → Normal file
|
|
@ -61,29 +61,29 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
"""
|
||||
|
||||
if expected_node.nodeType == Node.CDATA_SECTION_NODE:
|
||||
self.assertEqual(Node.CDATA_SECTION_NODE, actual_node.nodeType)
|
||||
self.assertEqual(expected_node.nodeValue, actual_node.nodeValue)
|
||||
self.assertEquals(Node.CDATA_SECTION_NODE, actual_node.nodeType)
|
||||
self.assertEquals(expected_node.nodeValue, actual_node.nodeValue)
|
||||
return
|
||||
|
||||
self.assertEqual(Node.ELEMENT_NODE, actual_node.nodeType)
|
||||
self.assertEqual(Node.ELEMENT_NODE, expected_node.nodeType)
|
||||
self.assertEqual(expected_node.tagName, actual_node.tagName)
|
||||
self.assertEquals(Node.ELEMENT_NODE, actual_node.nodeType)
|
||||
self.assertEquals(Node.ELEMENT_NODE, expected_node.nodeType)
|
||||
self.assertEquals(expected_node.tagName, actual_node.tagName)
|
||||
|
||||
expected_attributes = expected_node.attributes
|
||||
actual_attributes = actual_node.attributes
|
||||
self.assertEqual(
|
||||
actual_attributes = actual_node .attributes
|
||||
self.assertEquals(
|
||||
expected_attributes.length, actual_attributes.length,
|
||||
'attribute numbers differ in element %s:\nExpected: %r\nActual: %r' % (
|
||||
actual_node.tagName, list(expected_attributes.keys()),
|
||||
list(actual_attributes.keys())))
|
||||
actual_node.tagName, expected_attributes.keys(),
|
||||
actual_attributes.keys()))
|
||||
for i in range(expected_attributes.length):
|
||||
expected_attr = expected_attributes.item(i)
|
||||
actual_attr = actual_attributes.get(expected_attr.name)
|
||||
self.assertTrue(
|
||||
actual_attr = actual_attributes.get(expected_attr.name)
|
||||
self.assert_(
|
||||
actual_attr is not None,
|
||||
'expected attribute %s not found in element %s' %
|
||||
(expected_attr.name, actual_node.tagName))
|
||||
self.assertEqual(
|
||||
self.assertEquals(
|
||||
expected_attr.value, actual_attr.value,
|
||||
' values of attribute %s in element %s differ: %s vs %s' %
|
||||
(expected_attr.name, actual_node.tagName,
|
||||
|
|
@ -91,11 +91,11 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
|
||||
expected_children = self._GetChildren(expected_node)
|
||||
actual_children = self._GetChildren(actual_node)
|
||||
self.assertEqual(
|
||||
self.assertEquals(
|
||||
len(expected_children), len(actual_children),
|
||||
'number of child elements differ in element ' + actual_node.tagName)
|
||||
for child_id, child in list(expected_children.items()):
|
||||
self.assertTrue(child_id in actual_children,
|
||||
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))
|
||||
self.AssertEquivalentNodes(child, actual_children[child_id])
|
||||
|
|
@ -105,7 +105,6 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
'testsuite': 'name',
|
||||
'testcase': 'name',
|
||||
'failure': 'message',
|
||||
'skipped': 'message',
|
||||
'property': 'name',
|
||||
}
|
||||
|
||||
|
|
@ -128,15 +127,15 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
for child in element.childNodes:
|
||||
if child.nodeType == Node.ELEMENT_NODE:
|
||||
if child.tagName == 'properties':
|
||||
self.assertTrue(child.parentNode is not None,
|
||||
self.assert_(child.parentNode is not None,
|
||||
'Encountered <properties> element without a parent')
|
||||
child_id = child.parentNode.getAttribute('name') + '-properties'
|
||||
else:
|
||||
self.assertTrue(child.tagName in self.identifying_attribute,
|
||||
self.assert_(child.tagName in self.identifying_attribute,
|
||||
'Encountered unknown element <%s>' % child.tagName)
|
||||
child_id = child.getAttribute(
|
||||
self.identifying_attribute[child.tagName])
|
||||
self.assertTrue(child_id not in children)
|
||||
self.assert_(child_id not in children)
|
||||
children[child_id] = child
|
||||
elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
|
||||
if 'detail' not in children:
|
||||
|
|
@ -170,9 +169,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
* The stack traces are removed.
|
||||
"""
|
||||
|
||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||
if element.tagName == 'testsuites':
|
||||
timestamp = element.getAttributeNode('timestamp')
|
||||
timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d$',
|
||||
timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d$',
|
||||
'*', timestamp.value)
|
||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||
time = element.getAttributeNode('time')
|
||||
|
|
@ -180,7 +179,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
|||
type_param = element.getAttributeNode('type_param')
|
||||
if type_param and type_param.value:
|
||||
type_param.value = '*'
|
||||
elif element.tagName == 'failure' or element.tagName == 'skipped':
|
||||
elif element.tagName == 'failure':
|
||||
source_line_pat = r'^.*[/\\](.*:)\d+\n'
|
||||
# Replaces the source line information with a normalized form.
|
||||
message = element.getAttributeNode('message')
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@
|
|||
//
|
||||
// This is part of the unit test for gtest_prod.h.
|
||||
|
||||
#ifndef GOOGLETEST_TEST_PRODUCTION_H_
|
||||
#define GOOGLETEST_TEST_PRODUCTION_H_
|
||||
#ifndef GTEST_TEST_PRODUCTION_H_
|
||||
#define GTEST_TEST_PRODUCTION_H_
|
||||
|
||||
#include "gtest/gtest_prod.h"
|
||||
|
||||
|
|
@ -51,4 +51,4 @@ class PrivateCode {
|
|||
int x_;
|
||||
};
|
||||
|
||||
#endif // GOOGLETEST_TEST_PRODUCTION_H_
|
||||
#endif // GTEST_TEST_PRODUCTION_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue