mirror of
https://github.com/google/googletest.git
synced 2024-12-27 10:11:03 +08:00
Fix formatting in subset of Python files
These files were formatted with automated tools. The remaining Python files require some manual fix ups, so they will be fixed separately. PiperOrigin-RevId: 504579820 Change-Id: I3923bd414bffe3ded6163ec496cd09ace3951928
This commit is contained in:
parent
6c65a1ca35
commit
d1ad27e0a4
@ -54,50 +54,59 @@ class GMockLeakTest(gmock_test_utils.TestCase):
|
|||||||
def testCatchesLeakedMockByDefault(self):
|
def testCatchesLeakedMockByDefault(self):
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL,
|
gmock_test_utils.Subprocess(
|
||||||
env=environ).exit_code)
|
TEST_WITH_EXPECT_CALL, env=environ
|
||||||
|
).exit_code,
|
||||||
|
)
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0, gmock_test_utils.Subprocess(TEST_WITH_ON_CALL, env=environ).exit_code
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_ON_CALL,
|
)
|
||||||
env=environ).exit_code)
|
|
||||||
|
|
||||||
def testDoesNotCatchLeakedMockWhenDisabled(self):
|
def testDoesNotCatchLeakedMockWhenDisabled(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks=0'],
|
TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks=0'],
|
||||||
env=environ).exit_code)
|
env=environ,
|
||||||
|
).exit_code,
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks=0'],
|
TEST_WITH_ON_CALL + ['--gmock_catch_leaked_mocks=0'], env=environ
|
||||||
env=environ).exit_code)
|
).exit_code,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesLeakedMockWhenEnabled(self):
|
def testCatchesLeakedMockWhenEnabled(self):
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks'],
|
TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks'], env=environ
|
||||||
env=environ).exit_code)
|
).exit_code,
|
||||||
|
)
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks'],
|
TEST_WITH_ON_CALL + ['--gmock_catch_leaked_mocks'], env=environ
|
||||||
env=environ).exit_code)
|
).exit_code,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self):
|
def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self):
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks=1'],
|
TEST_WITH_EXPECT_CALL + ['--gmock_catch_leaked_mocks=1'],
|
||||||
env=environ).exit_code)
|
env=environ,
|
||||||
|
).exit_code,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesMultipleLeakedMocks(self):
|
def testCatchesMultipleLeakedMocks(self):
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
0,
|
0,
|
||||||
gmock_test_utils.Subprocess(TEST_MULTIPLE_LEAKS +
|
gmock_test_utils.Subprocess(
|
||||||
['--gmock_catch_leaked_mocks'],
|
TEST_MULTIPLE_LEAKS + ['--gmock_catch_leaked_mocks'], env=environ
|
||||||
env=environ).exit_code)
|
).exit_code,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -168,9 +168,13 @@ class GMockOutputTest(gmock_test_utils.TestCase):
|
|||||||
|
|
||||||
# The raw output should contain 2 leaked mock object errors for
|
# The raw output should contain 2 leaked mock object errors for
|
||||||
# test GMockOutputTest.CatchesLeakedMocks.
|
# test GMockOutputTest.CatchesLeakedMocks.
|
||||||
self.assertEqual(['GMockOutputTest.CatchesLeakedMocks',
|
self.assertEqual(
|
||||||
'GMockOutputTest.CatchesLeakedMocks'],
|
[
|
||||||
leaky_tests)
|
'GMockOutputTest.CatchesLeakedMocks',
|
||||||
|
'GMockOutputTest.CatchesLeakedMocks',
|
||||||
|
],
|
||||||
|
leaky_tests,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -59,7 +59,8 @@ CATCH_EXCEPTIONS_ENV_VAR = 'GTEST_CATCH_EXCEPTIONS'
|
|||||||
|
|
||||||
# Path to the googletest-break-on-failure-unittest_ program.
|
# Path to the googletest-break-on-failure-unittest_ program.
|
||||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-break-on-failure-unittest_')
|
'googletest-break-on-failure-unittest_'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
environ = gtest_test_utils.environ
|
environ = gtest_test_utils.environ
|
||||||
@ -99,10 +100,10 @@ class GTestBreakOnFailureUnitTest(gtest_test_utils.TestCase):
|
|||||||
Args:
|
Args:
|
||||||
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
|
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
|
||||||
variable; None if the variable should be unset.
|
variable; None if the variable should be unset.
|
||||||
flag_value: value of the --gtest_break_on_failure flag;
|
flag_value: value of the --gtest_break_on_failure flag; None if the
|
||||||
None if the flag should not be present.
|
flag should not be present.
|
||||||
expect_seg_fault: 1 if the program is expected to generate a seg-fault;
|
expect_seg_fault: 1 if the program is expected to generate a seg-fault; 0
|
||||||
0 otherwise.
|
otherwise.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, env_var_value)
|
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, env_var_value)
|
||||||
@ -132,74 +133,56 @@ class GTestBreakOnFailureUnitTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, None)
|
SetEnvVar(BREAK_ON_FAILURE_ENV_VAR, None)
|
||||||
|
|
||||||
msg = ('when %s%s, an assertion failure in "%s" %s cause a seg-fault.' %
|
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),
|
BREAK_ON_FAILURE_ENV_VAR,
|
||||||
should_or_not))
|
env_var_value_msg,
|
||||||
|
' '.join(command),
|
||||||
|
should_or_not,
|
||||||
|
)
|
||||||
self.assertTrue(has_seg_fault == expect_seg_fault, msg)
|
self.assertTrue(has_seg_fault == expect_seg_fault, msg)
|
||||||
|
|
||||||
def testDefaultBehavior(self):
|
def testDefaultBehavior(self):
|
||||||
"""Tests the behavior of the default mode."""
|
"""Tests the behavior of the default mode."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value=None,
|
self.RunAndVerify(env_var_value=None, flag_value=None, expect_seg_fault=0)
|
||||||
flag_value=None,
|
|
||||||
expect_seg_fault=0)
|
|
||||||
|
|
||||||
def testEnvVar(self):
|
def testEnvVar(self):
|
||||||
"""Tests using the GTEST_BREAK_ON_FAILURE environment variable."""
|
"""Tests using the GTEST_BREAK_ON_FAILURE environment variable."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value=None, expect_seg_fault=0)
|
||||||
flag_value=None,
|
self.RunAndVerify(env_var_value='1', flag_value=None, expect_seg_fault=1)
|
||||||
expect_seg_fault=0)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value=None,
|
|
||||||
expect_seg_fault=1)
|
|
||||||
|
|
||||||
def testFlag(self):
|
def testFlag(self):
|
||||||
"""Tests using the --gtest_break_on_failure flag."""
|
"""Tests using the --gtest_break_on_failure flag."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value=None,
|
self.RunAndVerify(env_var_value=None, flag_value='0', expect_seg_fault=0)
|
||||||
flag_value='0',
|
self.RunAndVerify(env_var_value=None, flag_value='1', expect_seg_fault=1)
|
||||||
expect_seg_fault=0)
|
|
||||||
self.RunAndVerify(env_var_value=None,
|
|
||||||
flag_value='1',
|
|
||||||
expect_seg_fault=1)
|
|
||||||
|
|
||||||
def testFlagOverridesEnvVar(self):
|
def testFlagOverridesEnvVar(self):
|
||||||
"""Tests that the flag overrides the environment variable."""
|
"""Tests that the flag overrides the environment variable."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value='0', expect_seg_fault=0)
|
||||||
flag_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value='1', expect_seg_fault=1)
|
||||||
expect_seg_fault=0)
|
self.RunAndVerify(env_var_value='1', flag_value='0', expect_seg_fault=0)
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='1', flag_value='1', expect_seg_fault=1)
|
||||||
flag_value='1',
|
|
||||||
expect_seg_fault=1)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value='0',
|
|
||||||
expect_seg_fault=0)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value='1',
|
|
||||||
expect_seg_fault=1)
|
|
||||||
|
|
||||||
def testBreakOnFailureOverridesThrowOnFailure(self):
|
def testBreakOnFailureOverridesThrowOnFailure(self):
|
||||||
"""Tests that gtest_break_on_failure overrides gtest_throw_on_failure."""
|
"""Tests that gtest_break_on_failure overrides gtest_throw_on_failure."""
|
||||||
|
|
||||||
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, '1')
|
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, '1')
|
||||||
try:
|
try:
|
||||||
self.RunAndVerify(env_var_value=None,
|
self.RunAndVerify(env_var_value=None, flag_value='1', expect_seg_fault=1)
|
||||||
flag_value='1',
|
|
||||||
expect_seg_fault=1)
|
|
||||||
finally:
|
finally:
|
||||||
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, None)
|
SetEnvVar(THROW_ON_FAILURE_ENV_VAR, None)
|
||||||
|
|
||||||
if IS_WINDOWS:
|
if IS_WINDOWS:
|
||||||
|
|
||||||
def testCatchExceptionsDoesNotInterfere(self):
|
def testCatchExceptionsDoesNotInterfere(self):
|
||||||
"""Tests that gtest_catch_exceptions doesn't interfere."""
|
"""Tests that gtest_catch_exceptions doesn't interfere."""
|
||||||
|
|
||||||
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, '1')
|
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, '1')
|
||||||
try:
|
try:
|
||||||
self.RunAndVerify(env_var_value='1',
|
self.RunAndVerify(env_var_value='1', flag_value='1', expect_seg_fault=1)
|
||||||
flag_value='1',
|
|
||||||
expect_seg_fault=1)
|
|
||||||
finally:
|
finally:
|
||||||
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, None)
|
SetEnvVar(CATCH_EXCEPTIONS_ENV_VAR, None)
|
||||||
|
|
||||||
|
@ -46,12 +46,14 @@ FILTER_FLAG = FLAG_PREFIX + 'filter'
|
|||||||
# Path to the googletest-catch-exceptions-ex-test_ binary, compiled with
|
# Path to the googletest-catch-exceptions-ex-test_ binary, compiled with
|
||||||
# exceptions enabled.
|
# exceptions enabled.
|
||||||
EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-catch-exceptions-ex-test_')
|
'googletest-catch-exceptions-ex-test_'
|
||||||
|
)
|
||||||
|
|
||||||
# Path to the googletest-catch-exceptions-test_ binary, compiled with
|
# Path to the googletest-catch-exceptions-test_ binary, compiled with
|
||||||
# exceptions disabled.
|
# exceptions disabled.
|
||||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-catch-exceptions-no-ex-test_')
|
'googletest-catch-exceptions-no-ex-test_'
|
||||||
|
)
|
||||||
|
|
||||||
environ = gtest_test_utils.environ
|
environ = gtest_test_utils.environ
|
||||||
SetEnvVar = gtest_test_utils.SetEnvVar
|
SetEnvVar = gtest_test_utils.SetEnvVar
|
||||||
@ -64,7 +66,8 @@ SetEnvVar = gtest_test_utils.SetEnvVar
|
|||||||
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
|
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
|
||||||
|
|
||||||
TEST_LIST = gtest_test_utils.Subprocess(
|
TEST_LIST = gtest_test_utils.Subprocess(
|
||||||
[EXE_PATH, LIST_TESTS_FLAG], env=environ).output
|
[EXE_PATH, LIST_TESTS_FLAG], env=environ
|
||||||
|
).output
|
||||||
|
|
||||||
SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST
|
SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST
|
||||||
|
|
||||||
@ -72,7 +75,8 @@ if SUPPORTS_SEH_EXCEPTIONS:
|
|||||||
BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH], env=environ).output
|
BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH], env=environ).output
|
||||||
|
|
||||||
EX_BINARY_OUTPUT = gtest_test_utils.Subprocess(
|
EX_BINARY_OUTPUT = gtest_test_utils.Subprocess(
|
||||||
[EX_EXE_PATH], env=environ).output
|
[EX_EXE_PATH], env=environ
|
||||||
|
).output
|
||||||
|
|
||||||
|
|
||||||
# The tests.
|
# The tests.
|
||||||
@ -133,8 +137,10 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description '
|
'C++ exception with description '
|
||||||
'"Standard C++ exception" thrown '
|
'"Standard C++ exception" thrown '
|
||||||
'in the test fixture\'s constructor' in EX_BINARY_OUTPUT,
|
"in the test fixture's constructor"
|
||||||
EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'unexpected' not in EX_BINARY_OUTPUT,
|
'unexpected' not in EX_BINARY_OUTPUT,
|
||||||
(
|
(
|
||||||
@ -144,60 +150,94 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
|
if (
|
||||||
EX_BINARY_OUTPUT):
|
'CxxExceptionInDestructorTest.ThrowsExceptionInDestructor'
|
||||||
|
in EX_BINARY_OUTPUT
|
||||||
|
):
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInFixtureDestructor(self):
|
def testCatchesCxxExceptionsInFixtureDestructor(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description '
|
'C++ exception with description '
|
||||||
'"Standard C++ exception" thrown '
|
'"Standard C++ exception" thrown '
|
||||||
'in the test fixture\'s destructor' in EX_BINARY_OUTPUT,
|
"in the test fixture's destructor"
|
||||||
EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInDestructorTest::TearDownTestSuite() '
|
'CxxExceptionInDestructorTest::TearDownTestSuite() '
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
'called as expected.'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description "Standard C++ exception"'
|
'C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
' thrown in SetUpTestSuite()'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInConstructorTest::TearDownTestSuite() '
|
'CxxExceptionInConstructorTest::TearDownTestSuite() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
'CxxExceptionInSetUpTestSuiteTest constructor '
|
'CxxExceptionInSetUpTestSuiteTest constructor called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
'CxxExceptionInSetUpTestSuiteTest destructor '
|
'CxxExceptionInSetUpTestSuiteTest destructor called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
'CxxExceptionInSetUpTestSuiteTest::SetUp() '
|
'CxxExceptionInSetUpTestSuiteTest::SetUp() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
'CxxExceptionInSetUpTestSuiteTest::TearDown() '
|
'CxxExceptionInSetUpTestSuiteTest::TearDown() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
'CxxExceptionInSetUpTestSuiteTest test body '
|
'CxxExceptionInSetUpTestSuiteTest test body called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description "Standard C++ exception"'
|
'C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
' thrown in TearDownTestSuite()'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInSetUp(self):
|
def testCatchesCxxExceptionsInSetUp(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description "Standard C++ exception"'
|
'C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in SetUp()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
' thrown in SetUp()'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInSetUpTest::TearDownTestSuite() '
|
'CxxExceptionInSetUpTest::TearDownTestSuite() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInSetUpTest destructor '
|
'CxxExceptionInSetUpTest destructor called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInSetUpTest::TearDown() '
|
'CxxExceptionInSetUpTest::TearDown() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'unexpected' not in EX_BINARY_OUTPUT,
|
'unexpected' not in EX_BINARY_OUTPUT,
|
||||||
(
|
(
|
||||||
@ -210,32 +250,49 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
def testCatchesCxxExceptionsInTearDown(self):
|
def testCatchesCxxExceptionsInTearDown(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description "Standard C++ exception"'
|
'C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in TearDown()' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
' thrown in TearDown()'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInTearDownTest::TearDownTestSuite() '
|
'CxxExceptionInTearDownTest::TearDownTestSuite() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInTearDownTest destructor '
|
'CxxExceptionInTearDownTest destructor called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInTestBody(self):
|
def testCatchesCxxExceptionsInTestBody(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'C++ exception with description "Standard C++ exception"'
|
'C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in the test body' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
' thrown in the test body'
|
||||||
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInTestBodyTest::TearDownTestSuite() '
|
'CxxExceptionInTestBodyTest::TearDownTestSuite() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInTestBodyTest destructor '
|
'CxxExceptionInTestBodyTest destructor called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'CxxExceptionInTestBodyTest::TearDown() '
|
'CxxExceptionInTestBodyTest::TearDown() called as expected.'
|
||||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT,
|
||||||
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testCatchesNonStdCxxExceptions(self):
|
def testCatchesNonStdCxxExceptions(self):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
'Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT,
|
'Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT,
|
||||||
EX_BINARY_OUTPUT)
|
EX_BINARY_OUTPUT,
|
||||||
|
)
|
||||||
|
|
||||||
def testUnhandledCxxExceptionsAbortTheProgram(self):
|
def testUnhandledCxxExceptionsAbortTheProgram(self):
|
||||||
# Filters out SEH exception tests on Windows. Unhandled SEH exceptions
|
# Filters out SEH exception tests on Windows. Unhandled SEH exceptions
|
||||||
@ -243,10 +300,9 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*'
|
FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*'
|
||||||
# By default, Google Test doesn't catch the exceptions.
|
# By default, Google Test doesn't catch the exceptions.
|
||||||
uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess(
|
uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess(
|
||||||
[EX_EXE_PATH,
|
[EX_EXE_PATH, NO_CATCH_EXCEPTIONS_FLAG, FITLER_OUT_SEH_TESTS_FLAG],
|
||||||
NO_CATCH_EXCEPTIONS_FLAG,
|
env=environ,
|
||||||
FITLER_OUT_SEH_TESTS_FLAG],
|
).output
|
||||||
env=environ).output
|
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'Unhandled C++ exception terminating the program',
|
'Unhandled C++ exception terminating the program',
|
||||||
|
@ -65,6 +65,7 @@ def UsesColor(term, color_env_var, color_flag):
|
|||||||
|
|
||||||
|
|
||||||
class GTestColorTest(gtest_test_utils.TestCase):
|
class GTestColorTest(gtest_test_utils.TestCase):
|
||||||
|
|
||||||
def testNoEnvVarNoFlag(self):
|
def testNoEnvVarNoFlag(self):
|
||||||
"""Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
|
"""Tests the case when there's neither GTEST_COLOR nor --gtest_color."""
|
||||||
|
|
||||||
|
@ -101,7 +101,6 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
|||||||
TestFlag('death_test_use_fork', '1', '0')
|
TestFlag('death_test_use_fork', '1', '0')
|
||||||
TestFlag('stack_trace_depth', '0', '100')
|
TestFlag('stack_trace_depth', '0', '100')
|
||||||
|
|
||||||
|
|
||||||
def testXmlOutputFile(self):
|
def testXmlOutputFile(self):
|
||||||
"""Tests that $XML_OUTPUT_FILE affects the output flag."""
|
"""Tests that $XML_OUTPUT_FILE affects the output flag."""
|
||||||
|
|
||||||
@ -116,5 +115,6 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
|||||||
SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml')
|
SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml')
|
||||||
AssertEq('xml:tmp/foo.xml', GetFlag('output'))
|
AssertEq('xml:tmp/foo.xml', GetFlag('output'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
@ -62,15 +62,18 @@ FILTER_FLAG = 'gtest_filter'
|
|||||||
|
|
||||||
# Command to run the googletest-failfast-unittest_ program.
|
# Command to run the googletest-failfast-unittest_ program.
|
||||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-failfast-unittest_')
|
'googletest-failfast-unittest_'
|
||||||
|
)
|
||||||
|
|
||||||
# The command line flag to tell Google Test to output the list of tests it
|
# The command line flag to tell Google Test to output the list of tests it
|
||||||
# will run.
|
# will run.
|
||||||
LIST_TESTS_FLAG = '--gtest_list_tests'
|
LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||||
|
|
||||||
# Indicates whether Google Test supports death tests.
|
# Indicates whether Google Test supports death tests.
|
||||||
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
|
SUPPORTS_DEATH_TESTS = (
|
||||||
[COMMAND, LIST_TESTS_FLAG]).output
|
'HasDeathTest'
|
||||||
|
in gtest_test_utils.Subprocess([COMMAND, LIST_TESTS_FLAG]).output
|
||||||
|
)
|
||||||
|
|
||||||
# Utilities.
|
# Utilities.
|
||||||
|
|
||||||
@ -90,8 +93,9 @@ def RunAndReturnOutput(test_suite=None, fail_fast=None, run_disabled=False):
|
|||||||
"""Runs the test program and returns its output."""
|
"""Runs the test program and returns its output."""
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
xml_path = os.path.join(gtest_test_utils.GetTempDir(),
|
xml_path = os.path.join(
|
||||||
'.GTestFailFastUnitTest.xml')
|
gtest_test_utils.GetTempDir(), '.GTestFailFastUnitTest.xml'
|
||||||
|
)
|
||||||
args += ['--gtest_output=xml:' + xml_path]
|
args += ['--gtest_output=xml:' + xml_path]
|
||||||
if fail_fast is not None:
|
if fail_fast is not None:
|
||||||
if isinstance(fail_fast, str):
|
if isinstance(fail_fast, str):
|
||||||
@ -188,49 +192,63 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=True)
|
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=True)
|
||||||
self.assertIn('1 FAILED TEST', txt)
|
self.assertIn('1 FAILED TEST', txt)
|
||||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
for expected_count, callback in [
|
||||||
|
(1, 'OnTestSuiteStart'),
|
||||||
(5, 'OnTestStart'),
|
(5, 'OnTestStart'),
|
||||||
(5, 'OnTestEnd'),
|
(5, 'OnTestEnd'),
|
||||||
(5, 'OnTestPartResult'),
|
(5, 'OnTestPartResult'),
|
||||||
(1, 'OnTestSuiteEnd')]:
|
(1, 'OnTestSuiteEnd'),
|
||||||
|
]:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expected_count, txt.count(callback),
|
expected_count,
|
||||||
'Expected %d calls to callback %s match count on output: %s ' %
|
txt.count(callback),
|
||||||
(expected_count, callback, txt))
|
'Expected %d calls to callback %s match count on output: %s '
|
||||||
|
% (expected_count, callback, txt),
|
||||||
|
)
|
||||||
|
|
||||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=False)
|
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=False)
|
||||||
self.assertIn('3 FAILED TEST', txt)
|
self.assertIn('3 FAILED TEST', txt)
|
||||||
self.assertIn('[ SKIPPED ] 1 test', txt)
|
self.assertIn('[ SKIPPED ] 1 test', txt)
|
||||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
for expected_count, callback in [
|
||||||
|
(1, 'OnTestSuiteStart'),
|
||||||
(5, 'OnTestStart'),
|
(5, 'OnTestStart'),
|
||||||
(5, 'OnTestEnd'),
|
(5, 'OnTestEnd'),
|
||||||
(5, 'OnTestPartResult'),
|
(5, 'OnTestPartResult'),
|
||||||
(1, 'OnTestSuiteEnd')]:
|
(1, 'OnTestSuiteEnd'),
|
||||||
|
]:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expected_count, txt.count(callback),
|
expected_count,
|
||||||
'Expected %d calls to callback %s match count on output: %s ' %
|
txt.count(callback),
|
||||||
(expected_count, callback, txt))
|
'Expected %d calls to callback %s match count on output: %s '
|
||||||
|
% (expected_count, callback, txt),
|
||||||
|
)
|
||||||
|
|
||||||
def assertXmlResultCount(self, result, count, xml):
|
def assertXmlResultCount(self, result, count, xml):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
count, xml.count('result="%s"' % result),
|
count,
|
||||||
'Expected \'result="%s"\' match count of %s: %s ' %
|
xml.count('result="%s"' % result),
|
||||||
(result, count, xml))
|
'Expected \'result="%s"\' match count of %s: %s '
|
||||||
|
% (result, count, xml),
|
||||||
|
)
|
||||||
|
|
||||||
def assertXmlStatusCount(self, status, count, xml):
|
def assertXmlStatusCount(self, status, count, xml):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
count, xml.count('status="%s"' % status),
|
count,
|
||||||
'Expected \'status="%s"\' match count of %s: %s ' %
|
xml.count('status="%s"' % status),
|
||||||
(status, count, xml))
|
'Expected \'status="%s"\' match count of %s: %s '
|
||||||
|
% (status, count, xml),
|
||||||
|
)
|
||||||
|
|
||||||
def assertFailFastXmlAndTxtOutput(self,
|
def assertFailFastXmlAndTxtOutput(
|
||||||
|
self,
|
||||||
fail_fast,
|
fail_fast,
|
||||||
test_suite,
|
test_suite,
|
||||||
passed_count,
|
passed_count,
|
||||||
failure_count,
|
failure_count,
|
||||||
skipped_count,
|
skipped_count,
|
||||||
suppressed_count,
|
suppressed_count,
|
||||||
run_disabled=False):
|
run_disabled=False,
|
||||||
|
):
|
||||||
"""Assert XML and text output of a test execution."""
|
"""Assert XML and text output of a test execution."""
|
||||||
|
|
||||||
txt, xml = RunAndReturnOutput(test_suite, fail_fast, run_disabled)
|
txt, xml = RunAndReturnOutput(test_suite, fail_fast, run_disabled)
|
||||||
@ -240,40 +258,57 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
self.assertIn('%s DISABLED TEST' % suppressed_count, txt)
|
self.assertIn('%s DISABLED TEST' % suppressed_count, txt)
|
||||||
if skipped_count > 0:
|
if skipped_count > 0:
|
||||||
self.assertIn('[ SKIPPED ] %s tests' % skipped_count, txt)
|
self.assertIn('[ SKIPPED ] %s tests' % skipped_count, txt)
|
||||||
self.assertXmlStatusCount('run',
|
self.assertXmlStatusCount(
|
||||||
passed_count + failure_count + skipped_count, xml)
|
'run', passed_count + failure_count + skipped_count, xml
|
||||||
|
)
|
||||||
self.assertXmlStatusCount('notrun', suppressed_count, xml)
|
self.assertXmlStatusCount('notrun', suppressed_count, xml)
|
||||||
self.assertXmlResultCount('completed', passed_count + failure_count, xml)
|
self.assertXmlResultCount('completed', passed_count + failure_count, xml)
|
||||||
self.assertXmlResultCount('skipped', skipped_count, xml)
|
self.assertXmlResultCount('skipped', skipped_count, xml)
|
||||||
self.assertXmlResultCount('suppressed', suppressed_count, xml)
|
self.assertXmlResultCount('suppressed', suppressed_count, xml)
|
||||||
|
|
||||||
def assertFailFastBehavior(self,
|
def assertFailFastBehavior(
|
||||||
|
self,
|
||||||
test_suite,
|
test_suite,
|
||||||
passed_count,
|
passed_count,
|
||||||
failure_count,
|
failure_count,
|
||||||
skipped_count,
|
skipped_count,
|
||||||
suppressed_count,
|
suppressed_count,
|
||||||
run_disabled=False):
|
run_disabled=False,
|
||||||
|
):
|
||||||
"""Assert --fail_fast via flag."""
|
"""Assert --fail_fast via flag."""
|
||||||
|
|
||||||
for fail_fast in ('true', '1', 't', True):
|
for fail_fast in ('true', '1', 't', True):
|
||||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
self.assertFailFastXmlAndTxtOutput(
|
||||||
failure_count, skipped_count,
|
fail_fast,
|
||||||
suppressed_count, run_disabled)
|
|
||||||
|
|
||||||
def assertNotFailFastBehavior(self,
|
|
||||||
test_suite,
|
test_suite,
|
||||||
passed_count,
|
passed_count,
|
||||||
failure_count,
|
failure_count,
|
||||||
skipped_count,
|
skipped_count,
|
||||||
suppressed_count,
|
suppressed_count,
|
||||||
run_disabled=False):
|
run_disabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
def assertNotFailFastBehavior(
|
||||||
|
self,
|
||||||
|
test_suite,
|
||||||
|
passed_count,
|
||||||
|
failure_count,
|
||||||
|
skipped_count,
|
||||||
|
suppressed_count,
|
||||||
|
run_disabled=False,
|
||||||
|
):
|
||||||
"""Assert --nofail_fast via flag."""
|
"""Assert --nofail_fast via flag."""
|
||||||
|
|
||||||
for fail_fast in ('false', '0', 'f', False):
|
for fail_fast in ('false', '0', 'f', False):
|
||||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
self.assertFailFastXmlAndTxtOutput(
|
||||||
failure_count, skipped_count,
|
fail_fast,
|
||||||
suppressed_count, run_disabled)
|
test_suite,
|
||||||
|
passed_count,
|
||||||
|
failure_count,
|
||||||
|
skipped_count,
|
||||||
|
suppressed_count,
|
||||||
|
run_disabled,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasFixtureTest(self):
|
def testFlag_HasFixtureTest(self):
|
||||||
"""Tests the behavior of fail_fast and TEST_F."""
|
"""Tests the behavior of fail_fast and TEST_F."""
|
||||||
@ -282,13 +317,15 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasFixtureTest',
|
test_suite='HasFixtureTest',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasSimpleTest(self):
|
def testFlag_HasSimpleTest(self):
|
||||||
"""Tests the behavior of fail_fast and TEST."""
|
"""Tests the behavior of fail_fast and TEST."""
|
||||||
@ -297,13 +334,15 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasSimpleTest',
|
test_suite='HasSimpleTest',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasParametersTest(self):
|
def testFlag_HasParametersTest(self):
|
||||||
"""Tests the behavior of fail_fast and TEST_P."""
|
"""Tests the behavior of fail_fast and TEST_P."""
|
||||||
@ -312,13 +351,15 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
passed_count=0,
|
passed_count=0,
|
||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasParametersSuite/HasParametersTest',
|
test_suite='HasParametersSuite/HasParametersTest',
|
||||||
passed_count=0,
|
passed_count=0,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasDisabledTest(self):
|
def testFlag_HasDisabledTest(self):
|
||||||
"""Tests the behavior of fail_fast and Disabled test cases."""
|
"""Tests the behavior of fail_fast and Disabled test cases."""
|
||||||
@ -328,14 +369,16 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=2,
|
skipped_count=2,
|
||||||
suppressed_count=1,
|
suppressed_count=1,
|
||||||
run_disabled=False)
|
run_disabled=False,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasDisabledTest',
|
test_suite='HasDisabledTest',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=3,
|
failure_count=3,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=1,
|
suppressed_count=1,
|
||||||
run_disabled=False)
|
run_disabled=False,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasDisabledRunDisabledTest(self):
|
def testFlag_HasDisabledRunDisabledTest(self):
|
||||||
"""Tests the behavior of fail_fast and Disabled test cases enabled."""
|
"""Tests the behavior of fail_fast and Disabled test cases enabled."""
|
||||||
@ -345,14 +388,16 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0,
|
suppressed_count=0,
|
||||||
run_disabled=True)
|
run_disabled=True,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasDisabledTest',
|
test_suite='HasDisabledTest',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0,
|
suppressed_count=0,
|
||||||
run_disabled=True)
|
run_disabled=True,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasDisabledSuiteTest(self):
|
def testFlag_HasDisabledSuiteTest(self):
|
||||||
"""Tests the behavior of fail_fast and Disabled test suites."""
|
"""Tests the behavior of fail_fast and Disabled test suites."""
|
||||||
@ -362,14 +407,16 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
failure_count=0,
|
failure_count=0,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=5,
|
suppressed_count=5,
|
||||||
run_disabled=False)
|
run_disabled=False,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='DISABLED_HasDisabledSuite',
|
test_suite='DISABLED_HasDisabledSuite',
|
||||||
passed_count=0,
|
passed_count=0,
|
||||||
failure_count=0,
|
failure_count=0,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=5,
|
suppressed_count=5,
|
||||||
run_disabled=False)
|
run_disabled=False,
|
||||||
|
)
|
||||||
|
|
||||||
def testFlag_HasDisabledSuiteRunDisabledTest(self):
|
def testFlag_HasDisabledSuiteRunDisabledTest(self):
|
||||||
"""Tests the behavior of fail_fast and Disabled test suites enabled."""
|
"""Tests the behavior of fail_fast and Disabled test suites enabled."""
|
||||||
@ -379,14 +426,16 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0,
|
suppressed_count=0,
|
||||||
run_disabled=True)
|
run_disabled=True,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='DISABLED_HasDisabledSuite',
|
test_suite='DISABLED_HasDisabledSuite',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0,
|
suppressed_count=0,
|
||||||
run_disabled=True)
|
run_disabled=True,
|
||||||
|
)
|
||||||
|
|
||||||
if SUPPORTS_DEATH_TESTS:
|
if SUPPORTS_DEATH_TESTS:
|
||||||
|
|
||||||
@ -397,13 +446,15 @@ class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
|||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=1,
|
failure_count=1,
|
||||||
skipped_count=3,
|
skipped_count=3,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
self.assertNotFailFastBehavior(
|
self.assertNotFailFastBehavior(
|
||||||
test_suite='HasDeathTest',
|
test_suite='HasDeathTest',
|
||||||
passed_count=1,
|
passed_count=1,
|
||||||
failure_count=4,
|
failure_count=4,
|
||||||
skipped_count=0,
|
skipped_count=0,
|
||||||
suppressed_count=0)
|
suppressed_count=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -42,6 +42,7 @@ we test that here also.
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sets import Set as set # For Python 2.3 compatibility
|
from sets import Set as set # For Python 2.3 compatibility
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -60,7 +61,8 @@ CAN_PASS_EMPTY_ENV = False
|
|||||||
if sys.executable:
|
if sys.executable:
|
||||||
os.environ['EMPTY_VAR'] = ''
|
os.environ['EMPTY_VAR'] = ''
|
||||||
child = gtest_test_utils.Subprocess(
|
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)
|
CAN_PASS_EMPTY_ENV = eval(child.output)
|
||||||
|
|
||||||
|
|
||||||
@ -75,8 +77,8 @@ if sys.executable:
|
|||||||
os.environ['UNSET_VAR'] = 'X'
|
os.environ['UNSET_VAR'] = 'X'
|
||||||
del os.environ['UNSET_VAR']
|
del os.environ['UNSET_VAR']
|
||||||
child = gtest_test_utils.Subprocess(
|
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)
|
CAN_UNSET_ENV = eval(child.output)
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ if sys.executable:
|
|||||||
# make sense on platforms that cannot pass empty env variables (Win32)
|
# make sense on platforms that cannot pass empty env variables (Win32)
|
||||||
# and on platforms that cannot unset variables (since we cannot tell
|
# and on platforms that cannot unset variables (since we cannot tell
|
||||||
# the difference between "" and NULL -- Borland and Solaris < 5.10)
|
# the difference between "" and NULL -- Borland and Solaris < 5.10)
|
||||||
CAN_TEST_EMPTY_FILTER = (CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV)
|
CAN_TEST_EMPTY_FILTER = CAN_PASS_EMPTY_ENV and CAN_UNSET_ENV
|
||||||
|
|
||||||
|
|
||||||
# The environment variable for specifying the test filters.
|
# The environment variable for specifying the test filters.
|
||||||
@ -121,8 +123,10 @@ DISABLED_BANNER_REGEX = re.compile(r'^\[\s*DISABLED\s*\] (.*)')
|
|||||||
LIST_TESTS_FLAG = '--gtest_list_tests'
|
LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||||
|
|
||||||
# Indicates whether Google Test supports death tests.
|
# Indicates whether Google Test supports death tests.
|
||||||
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
|
SUPPORTS_DEATH_TESTS = (
|
||||||
[COMMAND, LIST_TESTS_FLAG]).output
|
'HasDeathTest'
|
||||||
|
in gtest_test_utils.Subprocess([COMMAND, LIST_TESTS_FLAG]).output
|
||||||
|
)
|
||||||
|
|
||||||
# Full names of all tests in googletest-filter-unittests_.
|
# Full names of all tests in googletest-filter-unittests_.
|
||||||
PARAM_TESTS = [
|
PARAM_TESTS = [
|
||||||
@ -154,18 +158,20 @@ else:
|
|||||||
DEATH_TESTS = []
|
DEATH_TESTS = []
|
||||||
|
|
||||||
# All the non-disabled tests.
|
# All the non-disabled tests.
|
||||||
ACTIVE_TESTS = [
|
ACTIVE_TESTS = (
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
|
|
||||||
'BazTest.TestOne',
|
'BazTest.TestOne',
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
'BazTest.TestB',
|
'BazTest.TestB',
|
||||||
] + DEATH_TESTS + PARAM_TESTS
|
]
|
||||||
|
+ DEATH_TESTS
|
||||||
|
+ PARAM_TESTS
|
||||||
|
)
|
||||||
|
|
||||||
param_tests_present = None
|
param_tests_present = None
|
||||||
|
|
||||||
@ -186,8 +192,9 @@ def SetEnvVar(env_var, value):
|
|||||||
def RunAndReturnOutput(args=None):
|
def RunAndReturnOutput(args=None):
|
||||||
"""Runs the test program and returns its output."""
|
"""Runs the test program and returns its output."""
|
||||||
|
|
||||||
return gtest_test_utils.Subprocess([COMMAND] + (args or []),
|
return gtest_test_utils.Subprocess(
|
||||||
env=environ).output
|
[COMMAND] + (args or []), env=environ
|
||||||
|
).output
|
||||||
|
|
||||||
|
|
||||||
def RunAndExtractTestList(args=None):
|
def RunAndExtractTestList(args=None):
|
||||||
@ -234,10 +241,13 @@ def InvokeWithModifiedEnv(extra_env, function, *args, **kwargs):
|
|||||||
def RunWithSharding(total_shards, shard_index, command):
|
def RunWithSharding(total_shards, shard_index, command):
|
||||||
"""Runs a test program shard and returns exit code and a list of tests run."""
|
"""Runs a test program shard and returns exit code and a list of tests run."""
|
||||||
|
|
||||||
extra_env = {SHARD_INDEX_ENV_VAR: str(shard_index),
|
extra_env = {
|
||||||
TOTAL_SHARDS_ENV_VAR: str(total_shards)}
|
SHARD_INDEX_ENV_VAR: str(shard_index),
|
||||||
|
TOTAL_SHARDS_ENV_VAR: str(total_shards),
|
||||||
|
}
|
||||||
return InvokeWithModifiedEnv(extra_env, RunAndExtractTestList, command)
|
return InvokeWithModifiedEnv(extra_env, RunAndExtractTestList, command)
|
||||||
|
|
||||||
|
|
||||||
# The unit test.
|
# The unit test.
|
||||||
|
|
||||||
|
|
||||||
@ -303,8 +313,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
tests_run = RunAndExtractTestList(args)[0]
|
tests_run = RunAndExtractTestList(args)[0]
|
||||||
self.AssertSetEqual(tests_run, tests_to_run)
|
self.AssertSetEqual(tests_run, tests_to_run)
|
||||||
|
|
||||||
def RunAndVerifyWithSharding(self, gtest_filter, total_shards, tests_to_run,
|
def RunAndVerifyWithSharding(
|
||||||
args=None, check_exit_0=False):
|
self,
|
||||||
|
gtest_filter,
|
||||||
|
total_shards,
|
||||||
|
tests_to_run,
|
||||||
|
args=None,
|
||||||
|
check_exit_0=False,
|
||||||
|
):
|
||||||
"""Checks that binary runs correct tests for the given filter and shard.
|
"""Checks that binary runs correct tests for the given filter and shard.
|
||||||
|
|
||||||
Runs all shards of googletest-filter-unittest_ with the given filter, and
|
Runs all shards of googletest-filter-unittest_ with the given filter, and
|
||||||
@ -317,8 +333,8 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
total_shards: A total number of shards to split test run into.
|
total_shards: A total number of shards to split test run into.
|
||||||
tests_to_run: A set of tests expected to run.
|
tests_to_run: A set of tests expected to run.
|
||||||
args: Arguments to pass to the to the test binary.
|
args: Arguments to pass to the to the test binary.
|
||||||
check_exit_0: When set to a true value, make sure that all shards
|
check_exit_0: When set to a true value, make sure that all shards return
|
||||||
return 0.
|
0.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
|
tests_to_run = self.AdjustForParameterizedTests(tests_to_run)
|
||||||
@ -372,8 +388,9 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
global param_tests_present
|
global param_tests_present
|
||||||
if param_tests_present is None:
|
if param_tests_present is None:
|
||||||
param_tests_present = PARAM_TEST_REGEX.search(
|
param_tests_present = (
|
||||||
RunAndReturnOutput()) is not None
|
PARAM_TEST_REGEX.search(RunAndReturnOutput()) is not None
|
||||||
|
)
|
||||||
|
|
||||||
def testDefaultBehavior(self):
|
def testDefaultBehavior(self):
|
||||||
"""Tests the behavior of not specifying the filter."""
|
"""Tests the behavior of not specifying the filter."""
|
||||||
@ -425,8 +442,9 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
BAZ_TESTS = ['BazTest.TestOne', 'BazTest.TestA', 'BazTest.TestB']
|
BAZ_TESTS = ['BazTest.TestOne', 'BazTest.TestA', 'BazTest.TestB']
|
||||||
self.RunAndVerify('BazTest.*', BAZ_TESTS)
|
self.RunAndVerify('BazTest.*', BAZ_TESTS)
|
||||||
self.RunAndVerifyAllowingDisabled('BazTest.*',
|
self.RunAndVerifyAllowingDisabled(
|
||||||
BAZ_TESTS + ['BazTest.DISABLED_TestC'])
|
'BazTest.*', BAZ_TESTS + ['BazTest.DISABLED_TestC']
|
||||||
|
)
|
||||||
|
|
||||||
def testFilterByTest(self):
|
def testFilterByTest(self):
|
||||||
"""Tests filtering by test name."""
|
"""Tests filtering by test name."""
|
||||||
@ -437,38 +455,50 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
"""Select only the disabled tests to run."""
|
"""Select only the disabled tests to run."""
|
||||||
|
|
||||||
self.RunAndVerify('DISABLED_FoobarTest.Test1', [])
|
self.RunAndVerify('DISABLED_FoobarTest.Test1', [])
|
||||||
self.RunAndVerifyAllowingDisabled('DISABLED_FoobarTest.Test1',
|
self.RunAndVerifyAllowingDisabled(
|
||||||
['DISABLED_FoobarTest.Test1'])
|
'DISABLED_FoobarTest.Test1', ['DISABLED_FoobarTest.Test1']
|
||||||
|
)
|
||||||
|
|
||||||
self.RunAndVerify('*DISABLED_*', [])
|
self.RunAndVerify('*DISABLED_*', [])
|
||||||
self.RunAndVerifyAllowingDisabled('*DISABLED_*', DISABLED_TESTS)
|
self.RunAndVerifyAllowingDisabled('*DISABLED_*', DISABLED_TESTS)
|
||||||
|
|
||||||
self.RunAndVerify('*.DISABLED_*', [])
|
self.RunAndVerify('*.DISABLED_*', [])
|
||||||
self.RunAndVerifyAllowingDisabled('*.DISABLED_*', [
|
self.RunAndVerifyAllowingDisabled(
|
||||||
|
'*.DISABLED_*',
|
||||||
|
[
|
||||||
'BarTest.DISABLED_TestFour',
|
'BarTest.DISABLED_TestFour',
|
||||||
'BarTest.DISABLED_TestFive',
|
'BarTest.DISABLED_TestFive',
|
||||||
'BazTest.DISABLED_TestC',
|
'BazTest.DISABLED_TestC',
|
||||||
'DISABLED_FoobarTest.DISABLED_Test2',
|
'DISABLED_FoobarTest.DISABLED_Test2',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
self.RunAndVerify('DISABLED_*', [])
|
self.RunAndVerify('DISABLED_*', [])
|
||||||
self.RunAndVerifyAllowingDisabled('DISABLED_*', [
|
self.RunAndVerifyAllowingDisabled(
|
||||||
|
'DISABLED_*',
|
||||||
|
[
|
||||||
'DISABLED_FoobarTest.Test1',
|
'DISABLED_FoobarTest.Test1',
|
||||||
'DISABLED_FoobarTest.DISABLED_Test2',
|
'DISABLED_FoobarTest.DISABLED_Test2',
|
||||||
'DISABLED_FoobarbazTest.TestA',
|
'DISABLED_FoobarbazTest.TestA',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def testWildcardInTestCaseName(self):
|
def testWildcardInTestCaseName(self):
|
||||||
"""Tests using wildcard in the test case name."""
|
"""Tests using wildcard in the test case name."""
|
||||||
|
|
||||||
self.RunAndVerify('*a*.*', [
|
self.RunAndVerify(
|
||||||
|
'*a*.*',
|
||||||
|
[
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
|
|
||||||
'BazTest.TestOne',
|
'BazTest.TestOne',
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
'BazTest.TestB', ] + DEATH_TESTS + PARAM_TESTS)
|
'BazTest.TestB',
|
||||||
|
]
|
||||||
|
+ DEATH_TESTS
|
||||||
|
+ PARAM_TESTS,
|
||||||
|
)
|
||||||
|
|
||||||
def testWildcardInTestName(self):
|
def testWildcardInTestName(self):
|
||||||
"""Tests using wildcard in the test name."""
|
"""Tests using wildcard in the test name."""
|
||||||
@ -478,23 +508,27 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
def testFilterWithoutDot(self):
|
def testFilterWithoutDot(self):
|
||||||
"""Tests a filter that has no '.' in it."""
|
"""Tests a filter that has no '.' in it."""
|
||||||
|
|
||||||
self.RunAndVerify('*z*', [
|
self.RunAndVerify(
|
||||||
|
'*z*',
|
||||||
|
[
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BazTest.TestOne',
|
'BazTest.TestOne',
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
'BazTest.TestB',
|
'BazTest.TestB',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def testTwoPatterns(self):
|
def testTwoPatterns(self):
|
||||||
"""Tests filters that consist of two patterns."""
|
"""Tests filters that consist of two patterns."""
|
||||||
|
|
||||||
self.RunAndVerify('Foo*.*:*A*', [
|
self.RunAndVerify(
|
||||||
|
'Foo*.*:*A*',
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# An empty pattern + a non-empty one
|
# An empty pattern + a non-empty one
|
||||||
self.RunAndVerify(':*A*', ['FooTest.Abc', 'BazTest.TestA'])
|
self.RunAndVerify(':*A*', ['FooTest.Abc', 'BazTest.TestA'])
|
||||||
@ -502,83 +536,109 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
def testThreePatterns(self):
|
def testThreePatterns(self):
|
||||||
"""Tests filters that consist of three patterns."""
|
"""Tests filters that consist of three patterns."""
|
||||||
|
|
||||||
self.RunAndVerify('*oo*:*A*:*One', [
|
self.RunAndVerify(
|
||||||
|
'*oo*:*A*:*One',
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
|
|
||||||
'BazTest.TestOne',
|
'BazTest.TestOne',
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# The 2nd pattern is empty.
|
# The 2nd pattern is empty.
|
||||||
self.RunAndVerify('*oo*::*One', [
|
self.RunAndVerify(
|
||||||
|
'*oo*::*One',
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
|
|
||||||
'BazTest.TestOne',
|
'BazTest.TestOne',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# The last 2 patterns are empty.
|
# The last 2 patterns are empty.
|
||||||
self.RunAndVerify('*oo*::', [
|
self.RunAndVerify(
|
||||||
|
'*oo*::',
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def testNegativeFilters(self):
|
def testNegativeFilters(self):
|
||||||
self.RunAndVerify('*-BazTest.TestOne', [
|
self.RunAndVerify(
|
||||||
|
'*-BazTest.TestOne',
|
||||||
|
[
|
||||||
'FooTest.Abc',
|
'FooTest.Abc',
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
|
|
||||||
'BazTest.TestA',
|
'BazTest.TestA',
|
||||||
'BazTest.TestB',
|
'BazTest.TestB',
|
||||||
] + DEATH_TESTS + PARAM_TESTS)
|
]
|
||||||
|
+ DEATH_TESTS
|
||||||
|
+ PARAM_TESTS,
|
||||||
|
)
|
||||||
|
|
||||||
self.RunAndVerify('*-FooTest.Abc:BazTest.*', [
|
self.RunAndVerify(
|
||||||
|
'*-FooTest.Abc:BazTest.*',
|
||||||
|
[
|
||||||
'FooTest.Xyz',
|
'FooTest.Xyz',
|
||||||
|
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
] + DEATH_TESTS + PARAM_TESTS)
|
]
|
||||||
|
+ DEATH_TESTS
|
||||||
|
+ PARAM_TESTS,
|
||||||
|
)
|
||||||
|
|
||||||
self.RunAndVerify('BarTest.*-BarTest.TestOne', [
|
self.RunAndVerify(
|
||||||
|
'BarTest.*-BarTest.TestOne',
|
||||||
|
[
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Tests without leading '*'.
|
# Tests without leading '*'.
|
||||||
self.RunAndVerify('-FooTest.Abc:FooTest.Xyz:BazTest.*', [
|
self.RunAndVerify(
|
||||||
|
'-FooTest.Abc:FooTest.Xyz:BazTest.*',
|
||||||
|
[
|
||||||
'BarTest.TestOne',
|
'BarTest.TestOne',
|
||||||
'BarTest.TestTwo',
|
'BarTest.TestTwo',
|
||||||
'BarTest.TestThree',
|
'BarTest.TestThree',
|
||||||
] + DEATH_TESTS + PARAM_TESTS)
|
]
|
||||||
|
+ DEATH_TESTS
|
||||||
|
+ PARAM_TESTS,
|
||||||
|
)
|
||||||
|
|
||||||
# Value parameterized tests.
|
# Value parameterized tests.
|
||||||
self.RunAndVerify('*/*', PARAM_TESTS)
|
self.RunAndVerify('*/*', PARAM_TESTS)
|
||||||
|
|
||||||
# Value parameterized tests filtering by the sequence name.
|
# Value parameterized tests filtering by the sequence name.
|
||||||
self.RunAndVerify('SeqP/*', [
|
self.RunAndVerify(
|
||||||
|
'SeqP/*',
|
||||||
|
[
|
||||||
'SeqP/ParamTest.TestX/0',
|
'SeqP/ParamTest.TestX/0',
|
||||||
'SeqP/ParamTest.TestX/1',
|
'SeqP/ParamTest.TestX/1',
|
||||||
'SeqP/ParamTest.TestY/0',
|
'SeqP/ParamTest.TestY/0',
|
||||||
'SeqP/ParamTest.TestY/1',
|
'SeqP/ParamTest.TestY/1',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Value parameterized tests filtering by the test name.
|
# Value parameterized tests filtering by the test name.
|
||||||
self.RunAndVerify('*/0', [
|
self.RunAndVerify(
|
||||||
|
'*/0',
|
||||||
|
[
|
||||||
'SeqP/ParamTest.TestX/0',
|
'SeqP/ParamTest.TestX/0',
|
||||||
'SeqP/ParamTest.TestY/0',
|
'SeqP/ParamTest.TestY/0',
|
||||||
'SeqQ/ParamTest.TestX/0',
|
'SeqQ/ParamTest.TestX/0',
|
||||||
'SeqQ/ParamTest.TestY/0',
|
'SeqQ/ParamTest.TestY/0',
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def testFlagOverridesEnvVar(self):
|
def testFlagOverridesEnvVar(self):
|
||||||
"""Tests that the filter flag overrides the filtering env. variable."""
|
"""Tests that the filter flag overrides the filtering env. variable."""
|
||||||
@ -593,8 +653,9 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
def testShardStatusFileIsCreated(self):
|
def testShardStatusFileIsCreated(self):
|
||||||
"""Tests that the shard file is created if specified in the environment."""
|
"""Tests that the shard file is created if specified in the environment."""
|
||||||
|
|
||||||
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
|
shard_status_file = os.path.join(
|
||||||
'shard_status_file')
|
gtest_test_utils.GetTempDir(), 'shard_status_file'
|
||||||
|
)
|
||||||
self.assertTrue(not os.path.exists(shard_status_file))
|
self.assertTrue(not os.path.exists(shard_status_file))
|
||||||
|
|
||||||
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
||||||
@ -607,15 +668,16 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
def testShardStatusFileIsCreatedWithListTests(self):
|
def testShardStatusFileIsCreatedWithListTests(self):
|
||||||
"""Tests that the shard file is created with the "list_tests" flag."""
|
"""Tests that the shard file is created with the "list_tests" flag."""
|
||||||
|
|
||||||
shard_status_file = os.path.join(gtest_test_utils.GetTempDir(),
|
shard_status_file = os.path.join(
|
||||||
'shard_status_file2')
|
gtest_test_utils.GetTempDir(), 'shard_status_file2'
|
||||||
|
)
|
||||||
self.assertTrue(not os.path.exists(shard_status_file))
|
self.assertTrue(not os.path.exists(shard_status_file))
|
||||||
|
|
||||||
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
extra_env = {SHARD_STATUS_FILE_ENV_VAR: shard_status_file}
|
||||||
try:
|
try:
|
||||||
output = InvokeWithModifiedEnv(extra_env,
|
output = InvokeWithModifiedEnv(
|
||||||
RunAndReturnOutput,
|
extra_env, RunAndReturnOutput, [LIST_TESTS_FLAG]
|
||||||
[LIST_TESTS_FLAG])
|
)
|
||||||
finally:
|
finally:
|
||||||
# This assertion ensures that Google Test enumerated the tests as
|
# This assertion ensures that Google Test enumerated the tests as
|
||||||
# opposed to running them.
|
# opposed to running them.
|
||||||
@ -636,19 +698,25 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
make_filter = lambda s: ['--%s=%s' % (FILTER_FLAG, s)]
|
make_filter = lambda s: ['--%s=%s' % (FILTER_FLAG, s)]
|
||||||
|
|
||||||
banners = RunAndExtractDisabledBannerList(make_filter('*'))
|
banners = RunAndExtractDisabledBannerList(make_filter('*'))
|
||||||
self.AssertSetEqual(banners, [
|
self.AssertSetEqual(
|
||||||
'BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive',
|
banners,
|
||||||
'BazTest.DISABLED_TestC'
|
[
|
||||||
])
|
'BarTest.DISABLED_TestFour',
|
||||||
|
'BarTest.DISABLED_TestFive',
|
||||||
|
'BazTest.DISABLED_TestC',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
banners = RunAndExtractDisabledBannerList(make_filter('Bar*'))
|
banners = RunAndExtractDisabledBannerList(make_filter('Bar*'))
|
||||||
self.AssertSetEqual(
|
self.AssertSetEqual(
|
||||||
banners, ['BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive'])
|
banners, ['BarTest.DISABLED_TestFour', 'BarTest.DISABLED_TestFive']
|
||||||
|
)
|
||||||
|
|
||||||
banners = RunAndExtractDisabledBannerList(make_filter('*-Bar*'))
|
banners = RunAndExtractDisabledBannerList(make_filter('*-Bar*'))
|
||||||
self.AssertSetEqual(banners, ['BazTest.DISABLED_TestC'])
|
self.AssertSetEqual(banners, ['BazTest.DISABLED_TestC'])
|
||||||
|
|
||||||
if SUPPORTS_DEATH_TESTS:
|
if SUPPORTS_DEATH_TESTS:
|
||||||
|
|
||||||
def testShardingWorksWithDeathTests(self):
|
def testShardingWorksWithDeathTests(self):
|
||||||
"""Tests integration with death tests and sharding."""
|
"""Tests integration with death tests and sharding."""
|
||||||
|
|
||||||
@ -656,19 +724,23 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
|
|||||||
expected_tests = [
|
expected_tests = [
|
||||||
'HasDeathTest.Test1',
|
'HasDeathTest.Test1',
|
||||||
'HasDeathTest.Test2',
|
'HasDeathTest.Test2',
|
||||||
|
|
||||||
'SeqP/ParamTest.TestX/0',
|
'SeqP/ParamTest.TestX/0',
|
||||||
'SeqP/ParamTest.TestX/1',
|
'SeqP/ParamTest.TestX/1',
|
||||||
'SeqP/ParamTest.TestY/0',
|
'SeqP/ParamTest.TestY/0',
|
||||||
'SeqP/ParamTest.TestY/1',
|
'SeqP/ParamTest.TestY/1',
|
||||||
]
|
]
|
||||||
|
|
||||||
for flag in ['--gtest_death_test_style=threadsafe',
|
for flag in [
|
||||||
'--gtest_death_test_style=fast']:
|
'--gtest_death_test_style=threadsafe',
|
||||||
self.RunAndVerifyWithSharding(gtest_filter, 3, expected_tests,
|
'--gtest_death_test_style=fast',
|
||||||
check_exit_0=True, args=[flag])
|
]:
|
||||||
self.RunAndVerifyWithSharding(gtest_filter, 5, expected_tests,
|
self.RunAndVerifyWithSharding(
|
||||||
check_exit_0=True, args=[flag])
|
gtest_filter, 3, expected_tests, check_exit_0=True, args=[flag]
|
||||||
|
)
|
||||||
|
self.RunAndVerifyWithSharding(
|
||||||
|
gtest_filter, 5, expected_tests, check_exit_0=True, args=[flag]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
@ -42,10 +42,14 @@ from googletest.test import gtest_test_utils
|
|||||||
def RunAndReturnOutput(args=None):
|
def RunAndReturnOutput(args=None):
|
||||||
"""Runs the test program and returns its output."""
|
"""Runs the test program and returns its output."""
|
||||||
|
|
||||||
return gtest_test_utils.Subprocess([
|
return gtest_test_utils.Subprocess(
|
||||||
|
[
|
||||||
gtest_test_utils.GetTestExecutablePath(
|
gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-global-environment-unittest_')
|
'googletest-global-environment-unittest_'
|
||||||
] + (args or [])).output
|
)
|
||||||
|
]
|
||||||
|
+ (args or [])
|
||||||
|
).output
|
||||||
|
|
||||||
|
|
||||||
class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
||||||
@ -78,7 +82,8 @@ class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
|||||||
'--gtest_recreate_environments_when_repeating=true',
|
'--gtest_recreate_environments_when_repeating=true',
|
||||||
])
|
])
|
||||||
|
|
||||||
expected_pattern = ('(.|\n)*'
|
expected_pattern = (
|
||||||
|
'(.|\n)*'
|
||||||
r'Repeating all tests \(iteration 1\)'
|
r'Repeating all tests \(iteration 1\)'
|
||||||
'(.|\n)*'
|
'(.|\n)*'
|
||||||
'Global test environment set-up.'
|
'Global test environment set-up.'
|
||||||
@ -94,7 +99,8 @@ class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
|||||||
'SomeTest.DoesFoo'
|
'SomeTest.DoesFoo'
|
||||||
'(.|\n)*'
|
'(.|\n)*'
|
||||||
'Global test environment tear-down'
|
'Global test environment tear-down'
|
||||||
'(.|\n)*')
|
'(.|\n)*'
|
||||||
|
)
|
||||||
self.assertRegex(txt, expected_pattern)
|
self.assertRegex(txt, expected_pattern)
|
||||||
|
|
||||||
def testEnvironmentSetUpAndTornDownOnce(self):
|
def testEnvironmentSetUpAndTornDownOnce(self):
|
||||||
@ -102,11 +108,14 @@ class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
# By default the environment should only be set up and torn down once, at
|
# By default the environment should only be set up and torn down once, at
|
||||||
# the start and end of the test respectively.
|
# the start and end of the test respectively.
|
||||||
txt = RunAndReturnOutput([
|
txt = RunAndReturnOutput(
|
||||||
|
[
|
||||||
'--gtest_repeat=2',
|
'--gtest_repeat=2',
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
expected_pattern = ('(.|\n)*'
|
expected_pattern = (
|
||||||
|
'(.|\n)*'
|
||||||
r'Repeating all tests \(iteration 1\)'
|
r'Repeating all tests \(iteration 1\)'
|
||||||
'(.|\n)*'
|
'(.|\n)*'
|
||||||
'Global test environment set-up.'
|
'Global test environment set-up.'
|
||||||
@ -118,12 +127,14 @@ class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
|||||||
'SomeTest.DoesFoo'
|
'SomeTest.DoesFoo'
|
||||||
'(.|\n)*'
|
'(.|\n)*'
|
||||||
'Global test environment tear-down'
|
'Global test environment tear-down'
|
||||||
'(.|\n)*')
|
'(.|\n)*'
|
||||||
|
)
|
||||||
self.assertRegex(txt, expected_pattern)
|
self.assertRegex(txt, expected_pattern)
|
||||||
|
|
||||||
self.assertEqual(len(re.findall('Global test environment set-up', txt)), 1)
|
self.assertEqual(len(re.findall('Global test environment set-up', txt)), 1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(re.findall('Global test environment tear-down', txt)), 1)
|
len(re.findall('Global test environment tear-down', txt)), 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -40,93 +40,65 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_'
|
|||||||
GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_'
|
GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_'
|
||||||
|
|
||||||
EXPECTED_1 = {
|
EXPECTED_1 = {
|
||||||
u'tests':
|
'tests': 1,
|
||||||
1,
|
'failures': 0,
|
||||||
u'failures':
|
'disabled': 0,
|
||||||
0,
|
'errors': 0,
|
||||||
u'disabled':
|
'time': '*',
|
||||||
0,
|
'timestamp': '*',
|
||||||
u'errors':
|
'name': 'AllTests',
|
||||||
0,
|
'testsuites': [{
|
||||||
u'time':
|
'name': 'PropertyOne',
|
||||||
u'*',
|
'tests': 1,
|
||||||
u'timestamp':
|
'failures': 0,
|
||||||
u'*',
|
'disabled': 0,
|
||||||
u'name':
|
'errors': 0,
|
||||||
u'AllTests',
|
'time': '*',
|
||||||
u'testsuites': [{
|
'timestamp': '*',
|
||||||
u'name':
|
'testsuite': [{
|
||||||
u'PropertyOne',
|
'name': 'TestSomeProperties',
|
||||||
u'tests':
|
'file': 'gtest_xml_outfile1_test_.cc',
|
||||||
1,
|
'line': 41,
|
||||||
u'failures':
|
'status': 'RUN',
|
||||||
0,
|
'result': 'COMPLETED',
|
||||||
u'disabled':
|
'time': '*',
|
||||||
0,
|
'timestamp': '*',
|
||||||
u'errors':
|
'classname': 'PropertyOne',
|
||||||
0,
|
'SetUpProp': '1',
|
||||||
u'time':
|
'TestSomeProperty': '1',
|
||||||
u'*',
|
'TearDownProp': '1',
|
||||||
u'timestamp':
|
|
||||||
u'*',
|
|
||||||
u'testsuite': [{
|
|
||||||
u'name': u'TestSomeProperties',
|
|
||||||
u'file': u'gtest_xml_outfile1_test_.cc',
|
|
||||||
u'line': 41,
|
|
||||||
u'status': u'RUN',
|
|
||||||
u'result': u'COMPLETED',
|
|
||||||
u'time': u'*',
|
|
||||||
u'timestamp': u'*',
|
|
||||||
u'classname': u'PropertyOne',
|
|
||||||
u'SetUpProp': u'1',
|
|
||||||
u'TestSomeProperty': u'1',
|
|
||||||
u'TearDownProp': u'1',
|
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECTED_2 = {
|
EXPECTED_2 = {
|
||||||
u'tests':
|
'tests': 1,
|
||||||
1,
|
'failures': 0,
|
||||||
u'failures':
|
'disabled': 0,
|
||||||
0,
|
'errors': 0,
|
||||||
u'disabled':
|
'time': '*',
|
||||||
0,
|
'timestamp': '*',
|
||||||
u'errors':
|
'name': 'AllTests',
|
||||||
0,
|
'testsuites': [{
|
||||||
u'time':
|
'name': 'PropertyTwo',
|
||||||
u'*',
|
'tests': 1,
|
||||||
u'timestamp':
|
'failures': 0,
|
||||||
u'*',
|
'disabled': 0,
|
||||||
u'name':
|
'errors': 0,
|
||||||
u'AllTests',
|
'time': '*',
|
||||||
u'testsuites': [{
|
'timestamp': '*',
|
||||||
u'name':
|
'testsuite': [{
|
||||||
u'PropertyTwo',
|
'name': 'TestSomeProperties',
|
||||||
u'tests':
|
'file': 'gtest_xml_outfile2_test_.cc',
|
||||||
1,
|
'line': 41,
|
||||||
u'failures':
|
'status': 'RUN',
|
||||||
0,
|
'result': 'COMPLETED',
|
||||||
u'disabled':
|
'timestamp': '*',
|
||||||
0,
|
'time': '*',
|
||||||
u'errors':
|
'classname': 'PropertyTwo',
|
||||||
0,
|
'SetUpProp': '2',
|
||||||
u'time':
|
'TestSomeProperty': '2',
|
||||||
u'*',
|
'TearDownProp': '2',
|
||||||
u'timestamp':
|
|
||||||
u'*',
|
|
||||||
u'testsuite': [{
|
|
||||||
u'name': u'TestSomeProperties',
|
|
||||||
u'file': u'gtest_xml_outfile2_test_.cc',
|
|
||||||
u'line': 41,
|
|
||||||
u'status': u'RUN',
|
|
||||||
u'result': u'COMPLETED',
|
|
||||||
u'timestamp': u'*',
|
|
||||||
u'time': u'*',
|
|
||||||
u'classname': u'PropertyTwo',
|
|
||||||
u'SetUpProp': u'2',
|
|
||||||
u'TestSomeProperty': u'2',
|
|
||||||
u'TearDownProp': u'2',
|
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
@ -139,8 +111,9 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
|
|||||||
# We want the trailing '/' that the last "" provides in os.path.join, for
|
# We want the trailing '/' that the last "" provides in os.path.join, for
|
||||||
# telling Google Test to create an output directory instead of a single file
|
# telling Google Test to create an output directory instead of a single file
|
||||||
# for xml output.
|
# for xml output.
|
||||||
self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(),
|
self.output_dir_ = os.path.join(
|
||||||
GTEST_OUTPUT_SUBDIR, '')
|
gtest_test_utils.GetTempDir(), GTEST_OUTPUT_SUBDIR, ''
|
||||||
|
)
|
||||||
self.DeleteFilesAndDir()
|
self.DeleteFilesAndDir()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -169,8 +142,9 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
|
|||||||
def _TestOutFile(self, test_name, expected):
|
def _TestOutFile(self, test_name, expected):
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
|
||||||
command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_]
|
command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_]
|
||||||
p = gtest_test_utils.Subprocess(command,
|
p = gtest_test_utils.Subprocess(
|
||||||
working_dir=gtest_test_utils.GetTempDir())
|
command, working_dir=gtest_test_utils.GetTempDir()
|
||||||
|
)
|
||||||
self.assertTrue(p.exited)
|
self.assertTrue(p.exited)
|
||||||
self.assertEqual(0, p.exit_code)
|
self.assertEqual(0, p.exit_code)
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -46,11 +46,14 @@ from googletest.test import gtest_test_utils
|
|||||||
LIST_TESTS_FLAG = 'gtest_list_tests'
|
LIST_TESTS_FLAG = 'gtest_list_tests'
|
||||||
|
|
||||||
# Path to the googletest-list-tests-unittest_ program.
|
# Path to the googletest-list-tests-unittest_ program.
|
||||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath('googletest-list-tests-unittest_')
|
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
|
'googletest-list-tests-unittest_'
|
||||||
|
)
|
||||||
|
|
||||||
# The expected output when running googletest-list-tests-unittest_ with
|
# The expected output when running googletest-list-tests-unittest_ with
|
||||||
# --gtest_list_tests
|
# --gtest_list_tests
|
||||||
EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(r"""FooDeathTest\.
|
EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(
|
||||||
|
r"""FooDeathTest\.
|
||||||
Test1
|
Test1
|
||||||
Foo\.
|
Foo\.
|
||||||
Bar1
|
Bar1
|
||||||
@ -90,11 +93,13 @@ MyInstantiation/ValueParamTest\.
|
|||||||
TestB/0 # GetParam\(\) = one line
|
TestB/0 # GetParam\(\) = one line
|
||||||
TestB/1 # GetParam\(\) = two\\nlines
|
TestB/1 # GetParam\(\) = two\\nlines
|
||||||
TestB/2 # GetParam\(\) = a very\\nlo{241}\.\.\.
|
TestB/2 # GetParam\(\) = a very\\nlo{241}\.\.\.
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
# The expected output when running googletest-list-tests-unittest_ with
|
# The expected output when running googletest-list-tests-unittest_ with
|
||||||
# --gtest_list_tests and --gtest_filter=Foo*.
|
# --gtest_list_tests and --gtest_filter=Foo*.
|
||||||
EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(r"""FooDeathTest\.
|
EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(
|
||||||
|
r"""FooDeathTest\.
|
||||||
Test1
|
Test1
|
||||||
Foo\.
|
Foo\.
|
||||||
Bar1
|
Bar1
|
||||||
@ -106,7 +111,8 @@ FooTest\.
|
|||||||
Test1
|
Test1
|
||||||
DISABLED_Test2
|
DISABLED_Test2
|
||||||
Test3
|
Test3
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
# Utilities.
|
# Utilities.
|
||||||
|
|
||||||
@ -114,8 +120,9 @@ FooTest\.
|
|||||||
def Run(args):
|
def Run(args):
|
||||||
"""Runs googletest-list-tests-unittest_ and returns the list of tests printed."""
|
"""Runs googletest-list-tests-unittest_ and returns the list of tests printed."""
|
||||||
|
|
||||||
return gtest_test_utils.Subprocess([EXE_PATH] + args,
|
return gtest_test_utils.Subprocess(
|
||||||
capture_stderr=False).output
|
[EXE_PATH] + args, capture_stderr=False
|
||||||
|
).output
|
||||||
|
|
||||||
|
|
||||||
# The unit test.
|
# The unit test.
|
||||||
@ -129,13 +136,12 @@ class GTestListTestsUnitTest(gtest_test_utils.TestCase):
|
|||||||
the correct tests.
|
the correct tests.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
flag_value: value of the --gtest_list_tests flag;
|
flag_value: value of the --gtest_list_tests flag; None if the flag
|
||||||
None if the flag should not be present.
|
should not be present.
|
||||||
expected_output_re: regular expression that matches the expected
|
expected_output_re: regular expression that matches the expected output
|
||||||
output after running command;
|
after running command;
|
||||||
other_flag: a different flag to be passed to command
|
other_flag: a different flag to be passed to command along with
|
||||||
along with gtest_list_tests;
|
gtest_list_tests; None if the flag should not be present.
|
||||||
None if the flag should not be present.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if flag_value is None:
|
if flag_value is None:
|
||||||
@ -178,34 +184,37 @@ class GTestListTestsUnitTest(gtest_test_utils.TestCase):
|
|||||||
def testDefaultBehavior(self):
|
def testDefaultBehavior(self):
|
||||||
"""Tests the behavior of the default mode."""
|
"""Tests the behavior of the default mode."""
|
||||||
|
|
||||||
self.RunAndVerify(flag_value=None,
|
self.RunAndVerify(flag_value=None, expected_output_re=None, other_flag=None)
|
||||||
expected_output_re=None,
|
|
||||||
other_flag=None)
|
|
||||||
|
|
||||||
def testFlag(self):
|
def testFlag(self):
|
||||||
"""Tests using the --gtest_list_tests flag."""
|
"""Tests using the --gtest_list_tests flag."""
|
||||||
|
|
||||||
self.RunAndVerify(flag_value='0',
|
self.RunAndVerify(flag_value='0', expected_output_re=None, other_flag=None)
|
||||||
expected_output_re=None,
|
self.RunAndVerify(
|
||||||
other_flag=None)
|
flag_value='1',
|
||||||
self.RunAndVerify(flag_value='1',
|
|
||||||
expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
|
expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
|
||||||
other_flag=None)
|
other_flag=None,
|
||||||
|
)
|
||||||
|
|
||||||
def testOverrideNonFilterFlags(self):
|
def testOverrideNonFilterFlags(self):
|
||||||
"""Tests that --gtest_list_tests overrides the non-filter flags."""
|
"""Tests that --gtest_list_tests overrides the non-filter flags."""
|
||||||
|
|
||||||
self.RunAndVerify(flag_value='1',
|
self.RunAndVerify(
|
||||||
|
flag_value='1',
|
||||||
expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
|
expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
|
||||||
other_flag='--gtest_break_on_failure')
|
other_flag='--gtest_break_on_failure',
|
||||||
|
)
|
||||||
|
|
||||||
def testWithFilterFlags(self):
|
def testWithFilterFlags(self):
|
||||||
"""Tests that --gtest_list_tests takes into account the
|
"""Tests that --gtest_list_tests takes into account the
|
||||||
--gtest_filter flag."""
|
--gtest_filter flag.
|
||||||
|
"""
|
||||||
|
|
||||||
self.RunAndVerify(flag_value='1',
|
self.RunAndVerify(
|
||||||
|
flag_value='1',
|
||||||
expected_output_re=EXPECTED_OUTPUT_FILTER_FOO_RE,
|
expected_output_re=EXPECTED_OUTPUT_FILTER_FOO_RE,
|
||||||
other_flag='--gtest_filter=Foo*')
|
other_flag='--gtest_filter=Foo*',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -63,20 +63,32 @@ PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('googletest-output-test_')
|
|||||||
# 'internal_skip_environment_and_ad_hoc_tests' argument.
|
# 'internal_skip_environment_and_ad_hoc_tests' argument.
|
||||||
COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])
|
COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])
|
||||||
COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes'])
|
COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes'])
|
||||||
COMMAND_WITH_TIME = ({}, [PROGRAM_PATH,
|
COMMAND_WITH_TIME = (
|
||||||
|
{},
|
||||||
|
[
|
||||||
|
PROGRAM_PATH,
|
||||||
'--gtest_print_time',
|
'--gtest_print_time',
|
||||||
'internal_skip_environment_and_ad_hoc_tests',
|
'internal_skip_environment_and_ad_hoc_tests',
|
||||||
'--gtest_filter=FatalFailureTest.*:LoggingTest.*'])
|
'--gtest_filter=FatalFailureTest.*:LoggingTest.*',
|
||||||
|
],
|
||||||
|
)
|
||||||
COMMAND_WITH_DISABLED = (
|
COMMAND_WITH_DISABLED = (
|
||||||
{}, [PROGRAM_PATH,
|
{},
|
||||||
|
[
|
||||||
|
PROGRAM_PATH,
|
||||||
'--gtest_also_run_disabled_tests',
|
'--gtest_also_run_disabled_tests',
|
||||||
'internal_skip_environment_and_ad_hoc_tests',
|
'internal_skip_environment_and_ad_hoc_tests',
|
||||||
'--gtest_filter=*DISABLED_*'])
|
'--gtest_filter=*DISABLED_*',
|
||||||
|
],
|
||||||
|
)
|
||||||
COMMAND_WITH_SHARDING = (
|
COMMAND_WITH_SHARDING = (
|
||||||
{'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'},
|
{'GTEST_SHARD_INDEX': '1', 'GTEST_TOTAL_SHARDS': '2'},
|
||||||
[PROGRAM_PATH,
|
[
|
||||||
|
PROGRAM_PATH,
|
||||||
'internal_skip_environment_and_ad_hoc_tests',
|
'internal_skip_environment_and_ad_hoc_tests',
|
||||||
'--gtest_filter=PassingTest.*'])
|
'--gtest_filter=PassingTest.*',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)
|
GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)
|
||||||
|
|
||||||
@ -100,16 +112,20 @@ def RemoveLocations(test_output):
|
|||||||
'FILE_NAME:#: '.
|
'FILE_NAME:#: '.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return re.sub(r'.*[/\\]((googletest-output-test_|gtest).cc)(\:\d+|\(\d+\))\: ',
|
return re.sub(
|
||||||
r'\1:#: ', test_output)
|
r'.*[/\\]((googletest-output-test_|gtest).cc)(\:\d+|\(\d+\))\: ',
|
||||||
|
r'\1:#: ',
|
||||||
|
test_output,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def RemoveStackTraceDetails(output):
|
def RemoveStackTraceDetails(output):
|
||||||
"""Removes all stack traces from a Google Test program's output."""
|
"""Removes all stack traces from a Google Test program's output."""
|
||||||
|
|
||||||
# *? means "find the shortest string that matches".
|
# *? means "find the shortest string that matches".
|
||||||
return re.sub(r'Stack trace:(.|\n)*?\n\n',
|
return re.sub(
|
||||||
'Stack trace: (omitted)\n\n', output)
|
r'Stack trace:(.|\n)*?\n\n', 'Stack trace: (omitted)\n\n', output
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def RemoveStackTraces(output):
|
def RemoveStackTraces(output):
|
||||||
@ -156,14 +172,12 @@ def NormalizeToCurrentPlatform(test_output):
|
|||||||
def RemoveTestCounts(output):
|
def RemoveTestCounts(output):
|
||||||
"""Removes test counts from a Google Test program's output."""
|
"""Removes test counts from a Google Test program's output."""
|
||||||
|
|
||||||
output = re.sub(r'\d+ tests?, listed below',
|
output = re.sub(r'\d+ tests?, listed below', '? tests, listed below', output)
|
||||||
'? tests, listed below', output)
|
output = re.sub(r'\d+ FAILED TESTS', '? FAILED TESTS', output)
|
||||||
output = re.sub(r'\d+ FAILED TESTS',
|
output = re.sub(
|
||||||
'? FAILED TESTS', output)
|
r'\d+ tests? from \d+ test cases?', '? tests from ? test cases', output
|
||||||
output = re.sub(r'\d+ tests? from \d+ test cases?',
|
)
|
||||||
'? tests from ? test cases', output)
|
output = re.sub(r'\d+ tests? from ([a-zA-Z_])', r'? tests from \1', output)
|
||||||
output = re.sub(r'\d+ tests? from ([a-zA-Z_])',
|
|
||||||
r'? tests from \1', output)
|
|
||||||
return re.sub(r'\d+ tests?\.', '? tests.', output)
|
return re.sub(r'\d+ tests?\.', '? tests.', output)
|
||||||
|
|
||||||
|
|
||||||
@ -175,18 +189,19 @@ def RemoveMatchingTests(test_output, pattern):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
test_output: A string containing the test output.
|
test_output: A string containing the test output.
|
||||||
pattern: A regex string that matches names of test cases or
|
pattern: A regex string that matches names of test cases or tests
|
||||||
tests to remove.
|
to remove.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Contents of test_output with tests whose names match pattern removed.
|
Contents of test_output with tests whose names match pattern removed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
test_output = re.sub(
|
test_output = re.sub(
|
||||||
r'.*\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n' % (
|
r'.*\[ RUN \] .*%s(.|\n)*?\[( FAILED | OK )\] .*%s.*\n'
|
||||||
pattern, pattern),
|
% (pattern, pattern),
|
||||||
'',
|
'',
|
||||||
test_output)
|
test_output,
|
||||||
|
)
|
||||||
return re.sub(r'.*%s.*\n' % pattern, '', test_output)
|
return re.sub(r'.*%s.*\n' % pattern, '', test_output)
|
||||||
|
|
||||||
|
|
||||||
@ -205,8 +220,8 @@ def GetShellCommandOutput(env_cmd):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
|
env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
|
||||||
environment variables to set, and element 1 is a string with
|
environment variables to set, and element 1 is a string with the command
|
||||||
the command and any flags.
|
and any flags.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A string with the command's combined standard and diagnostic output.
|
A string with the command's combined standard and diagnostic output.
|
||||||
@ -227,8 +242,8 @@ def GetCommandOutput(env_cmd):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
|
env_cmd: The shell command. A 2-tuple where element 0 is a dict of extra
|
||||||
environment variables to set, and element 1 is a string with
|
environment variables to set, and element 1 is a string with the command
|
||||||
the command and any flags.
|
and any flags.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Disables exception pop-ups on Windows.
|
# Disables exception pop-ups on Windows.
|
||||||
@ -241,10 +256,12 @@ def GetCommandOutput(env_cmd):
|
|||||||
def GetOutputOfAllCommands():
|
def GetOutputOfAllCommands():
|
||||||
"""Returns concatenated output from several representative commands."""
|
"""Returns concatenated output from several representative commands."""
|
||||||
|
|
||||||
return (GetCommandOutput(COMMAND_WITH_COLOR) +
|
return (
|
||||||
GetCommandOutput(COMMAND_WITH_TIME) +
|
GetCommandOutput(COMMAND_WITH_COLOR)
|
||||||
GetCommandOutput(COMMAND_WITH_DISABLED) +
|
+ GetCommandOutput(COMMAND_WITH_TIME)
|
||||||
GetCommandOutput(COMMAND_WITH_SHARDING))
|
+ GetCommandOutput(COMMAND_WITH_DISABLED)
|
||||||
|
+ GetCommandOutput(COMMAND_WITH_SHARDING)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
|
test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
|
||||||
@ -253,12 +270,16 @@ SUPPORTS_TYPED_TESTS = 'TypedTest' in test_list
|
|||||||
SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list
|
SUPPORTS_THREADS = 'ExpectFailureWithThreadsTest' in test_list
|
||||||
SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
|
SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv
|
||||||
|
|
||||||
CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and
|
CAN_GENERATE_GOLDEN_FILE = (
|
||||||
SUPPORTS_TYPED_TESTS and
|
SUPPORTS_DEATH_TESTS
|
||||||
SUPPORTS_THREADS and
|
and SUPPORTS_TYPED_TESTS
|
||||||
SUPPORTS_STACK_TRACES)
|
and SUPPORTS_THREADS
|
||||||
|
and SUPPORTS_STACK_TRACES
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GTestOutputTest(gtest_test_utils.TestCase):
|
class GTestOutputTest(gtest_test_utils.TestCase):
|
||||||
|
|
||||||
def RemoveUnsupportedTests(self, test_output):
|
def RemoveUnsupportedTests(self, test_output):
|
||||||
if not SUPPORTS_DEATH_TESTS:
|
if not SUPPORTS_DEATH_TESTS:
|
||||||
test_output = RemoveMatchingTests(test_output, 'DeathTest')
|
test_output = RemoveMatchingTests(test_output, 'DeathTest')
|
||||||
@ -267,12 +288,13 @@ class GTestOutputTest(gtest_test_utils.TestCase):
|
|||||||
test_output = RemoveMatchingTests(test_output, 'TypedDeathTest')
|
test_output = RemoveMatchingTests(test_output, 'TypedDeathTest')
|
||||||
test_output = RemoveMatchingTests(test_output, 'TypeParamDeathTest')
|
test_output = RemoveMatchingTests(test_output, 'TypeParamDeathTest')
|
||||||
if not SUPPORTS_THREADS:
|
if not SUPPORTS_THREADS:
|
||||||
test_output = RemoveMatchingTests(test_output,
|
test_output = RemoveMatchingTests(
|
||||||
'ExpectFailureWithThreadsTest')
|
test_output, 'ExpectFailureWithThreadsTest'
|
||||||
test_output = RemoveMatchingTests(test_output,
|
)
|
||||||
'ScopedFakeTestPartResultReporterTest')
|
test_output = RemoveMatchingTests(
|
||||||
test_output = RemoveMatchingTests(test_output,
|
test_output, 'ScopedFakeTestPartResultReporterTest'
|
||||||
'WorksConcurrently')
|
)
|
||||||
|
test_output = RemoveMatchingTests(test_output, 'WorksConcurrently')
|
||||||
if not SUPPORTS_STACK_TRACES:
|
if not SUPPORTS_STACK_TRACES:
|
||||||
test_output = RemoveStackTraces(test_output)
|
test_output = RemoveStackTraces(test_output)
|
||||||
|
|
||||||
@ -297,27 +319,42 @@ class GTestOutputTest(gtest_test_utils.TestCase):
|
|||||||
normalized_golden = RemoveTypeInfoDetails(golden)
|
normalized_golden = RemoveTypeInfoDetails(golden)
|
||||||
|
|
||||||
if CAN_GENERATE_GOLDEN_FILE:
|
if CAN_GENERATE_GOLDEN_FILE:
|
||||||
self.assertEqual(normalized_golden, normalized_actual,
|
self.assertEqual(
|
||||||
'\n'.join(difflib.unified_diff(
|
normalized_golden,
|
||||||
|
normalized_actual,
|
||||||
|
'\n'.join(
|
||||||
|
difflib.unified_diff(
|
||||||
normalized_golden.split('\n'),
|
normalized_golden.split('\n'),
|
||||||
normalized_actual.split('\n'),
|
normalized_actual.split('\n'),
|
||||||
'golden', 'actual')))
|
'golden',
|
||||||
|
'actual',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
normalized_actual = NormalizeToCurrentPlatform(
|
normalized_actual = NormalizeToCurrentPlatform(
|
||||||
RemoveTestCounts(normalized_actual))
|
RemoveTestCounts(normalized_actual)
|
||||||
|
)
|
||||||
normalized_golden = NormalizeToCurrentPlatform(
|
normalized_golden = NormalizeToCurrentPlatform(
|
||||||
RemoveTestCounts(self.RemoveUnsupportedTests(normalized_golden)))
|
RemoveTestCounts(self.RemoveUnsupportedTests(normalized_golden))
|
||||||
|
)
|
||||||
|
|
||||||
# This code is very handy when debugging golden file differences:
|
# This code is very handy when debugging golden file differences:
|
||||||
if os.getenv('DEBUG_GTEST_OUTPUT_TEST'):
|
if os.getenv('DEBUG_GTEST_OUTPUT_TEST'):
|
||||||
open(os.path.join(
|
open(
|
||||||
|
os.path.join(
|
||||||
gtest_test_utils.GetSourceDir(),
|
gtest_test_utils.GetSourceDir(),
|
||||||
'_googletest-output-test_normalized_actual.txt'), 'wb').write(
|
'_googletest-output-test_normalized_actual.txt',
|
||||||
normalized_actual)
|
),
|
||||||
open(os.path.join(
|
'wb',
|
||||||
|
).write(normalized_actual)
|
||||||
|
open(
|
||||||
|
os.path.join(
|
||||||
gtest_test_utils.GetSourceDir(),
|
gtest_test_utils.GetSourceDir(),
|
||||||
'_googletest-output-test_normalized_golden.txt'), 'wb').write(
|
'_googletest-output-test_normalized_golden.txt',
|
||||||
normalized_golden)
|
),
|
||||||
|
'wb',
|
||||||
|
).write(normalized_golden)
|
||||||
|
|
||||||
self.assertEqual(normalized_golden, normalized_actual)
|
self.assertEqual(normalized_golden, normalized_actual)
|
||||||
|
|
||||||
@ -334,11 +371,10 @@ if __name__ == '__main__':
|
|||||||
golden_file.write(output.encode())
|
golden_file.write(output.encode())
|
||||||
golden_file.close()
|
golden_file.close()
|
||||||
else:
|
else:
|
||||||
message = (
|
message = """Unable to write a golden file when compiled in an environment
|
||||||
"""Unable to write a golden file when compiled in an environment
|
|
||||||
that does not support all the required features (death tests,
|
that does not support all the required features (death tests,
|
||||||
typed tests, stack traces, and multiple threads).
|
typed tests, stack traces, and multiple threads).
|
||||||
Please build this test and generate the golden file using Blaze on Linux.""")
|
Please build this test and generate the golden file using Blaze on Linux."""
|
||||||
|
|
||||||
sys.stderr.write(message)
|
sys.stderr.write(message)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -44,7 +44,7 @@ def Assert(condition):
|
|||||||
def TestExitCodeAndOutput(command):
|
def TestExitCodeAndOutput(command):
|
||||||
"""Runs the given command and verifies its exit code and output."""
|
"""Runs the given command and verifies its exit code and output."""
|
||||||
|
|
||||||
err = ('Parameterized test name \'"InvalidWithQuotes"\' is invalid')
|
err = 'Parameterized test name \'"InvalidWithQuotes"\' is invalid'
|
||||||
|
|
||||||
p = gtest_test_utils.Subprocess(command)
|
p = gtest_test_utils.Subprocess(command)
|
||||||
Assert(p.terminated_by_signal)
|
Assert(p.terminated_by_signal)
|
||||||
|
@ -44,7 +44,7 @@ def Assert(condition):
|
|||||||
def TestExitCodeAndOutput(command):
|
def TestExitCodeAndOutput(command):
|
||||||
"""Runs the given command and verifies its exit code and output."""
|
"""Runs the given command and verifies its exit code and output."""
|
||||||
|
|
||||||
err = ('Duplicate parameterized test name \'a\'')
|
err = "Duplicate parameterized test name 'a'"
|
||||||
|
|
||||||
p = gtest_test_utils.Subprocess(command)
|
p = gtest_test_utils.Subprocess(command)
|
||||||
Assert(p.terminated_by_signal)
|
Assert(p.terminated_by_signal)
|
||||||
@ -58,5 +58,6 @@ class GTestParamTestInvalidName2Test(gtest_test_utils.TestCase):
|
|||||||
def testExitCodeAndOutput(self):
|
def testExitCodeAndOutput(self):
|
||||||
TestExitCodeAndOutput(COMMAND)
|
TestExitCodeAndOutput(COMMAND)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
from googletest.test import gtest_test_utils
|
from googletest.test import gtest_test_utils
|
||||||
|
|
||||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-setuptestsuite-test_')
|
'googletest-setuptestsuite-test_'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
||||||
@ -44,11 +45,14 @@ class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
|||||||
self.assertNotEqual(p.exit_code, 0, msg=p.output)
|
self.assertNotEqual(p.exit_code, 0, msg=p.output)
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
(
|
||||||
'[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n['
|
||||||
'\n'
|
' FAILED ] TearDownFailTest: SetUpTestSuite or'
|
||||||
' 2 FAILED TEST SUITES\n',
|
' TearDownTestSuite\n\n 2 FAILED TEST SUITES\n'
|
||||||
p.output)
|
),
|
||||||
|
p.output,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
gtest_test_utils.Main()
|
gtest_test_utils.Main()
|
||||||
|
@ -47,7 +47,8 @@ THROW_ON_FAILURE = 'gtest_throw_on_failure'
|
|||||||
# Path to the googletest-throw-on-failure-test_ program, compiled with
|
# Path to the googletest-throw-on-failure-test_ program, compiled with
|
||||||
# exceptions disabled.
|
# exceptions disabled.
|
||||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
'googletest-throw-on-failure-test_')
|
'googletest-throw-on-failure-test_'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Utilities.
|
# Utilities.
|
||||||
@ -84,8 +85,8 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
|||||||
Args:
|
Args:
|
||||||
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
|
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
|
||||||
variable; None if the variable should be unset.
|
variable; None if the variable should be unset.
|
||||||
flag_value: value of the --gtest_break_on_failure flag;
|
flag_value: value of the --gtest_break_on_failure flag; None if the
|
||||||
None if the flag should not be present.
|
flag should not be present.
|
||||||
should_fail: True if and only if the program is expected to fail.
|
should_fail: True if and only if the program is expected to fail.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -116,10 +117,15 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
SetEnvVar(THROW_ON_FAILURE, None)
|
SetEnvVar(THROW_ON_FAILURE, None)
|
||||||
|
|
||||||
msg = ('when %s%s, an assertion failure in "%s" %s cause a non-zero '
|
msg = (
|
||||||
'exit code.' %
|
'when %s%s, an assertion failure in "%s" %s cause a non-zero exit code.'
|
||||||
(THROW_ON_FAILURE, env_var_value_msg, ' '.join(command),
|
% (
|
||||||
should_or_not))
|
THROW_ON_FAILURE,
|
||||||
|
env_var_value_msg,
|
||||||
|
' '.join(command),
|
||||||
|
should_or_not,
|
||||||
|
)
|
||||||
|
)
|
||||||
self.assertTrue(failed == should_fail, msg)
|
self.assertTrue(failed == should_fail, msg)
|
||||||
|
|
||||||
def testDefaultBehavior(self):
|
def testDefaultBehavior(self):
|
||||||
@ -130,38 +136,22 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
|||||||
def testThrowOnFailureEnvVar(self):
|
def testThrowOnFailureEnvVar(self):
|
||||||
"""Tests using the GTEST_THROW_ON_FAILURE environment variable."""
|
"""Tests using the GTEST_THROW_ON_FAILURE environment variable."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value=None, should_fail=False)
|
||||||
flag_value=None,
|
self.RunAndVerify(env_var_value='1', flag_value=None, should_fail=True)
|
||||||
should_fail=False)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value=None,
|
|
||||||
should_fail=True)
|
|
||||||
|
|
||||||
def testThrowOnFailureFlag(self):
|
def testThrowOnFailureFlag(self):
|
||||||
"""Tests using the --gtest_throw_on_failure flag."""
|
"""Tests using the --gtest_throw_on_failure flag."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value=None,
|
self.RunAndVerify(env_var_value=None, flag_value='0', should_fail=False)
|
||||||
flag_value='0',
|
self.RunAndVerify(env_var_value=None, flag_value='1', should_fail=True)
|
||||||
should_fail=False)
|
|
||||||
self.RunAndVerify(env_var_value=None,
|
|
||||||
flag_value='1',
|
|
||||||
should_fail=True)
|
|
||||||
|
|
||||||
def testThrowOnFailureFlagOverridesEnvVar(self):
|
def testThrowOnFailureFlagOverridesEnvVar(self):
|
||||||
"""Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE."""
|
"""Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE."""
|
||||||
|
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value='0', should_fail=False)
|
||||||
flag_value='0',
|
self.RunAndVerify(env_var_value='0', flag_value='1', should_fail=True)
|
||||||
should_fail=False)
|
self.RunAndVerify(env_var_value='1', flag_value='0', should_fail=False)
|
||||||
self.RunAndVerify(env_var_value='0',
|
self.RunAndVerify(env_var_value='1', flag_value='1', should_fail=True)
|
||||||
flag_value='1',
|
|
||||||
should_fail=True)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value='0',
|
|
||||||
should_fail=False)
|
|
||||||
self.RunAndVerify(env_var_value='1',
|
|
||||||
flag_value='1',
|
|
||||||
should_fail=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -33,7 +33,9 @@
|
|||||||
|
|
||||||
from googletest.test import gtest_test_utils
|
from googletest.test import gtest_test_utils
|
||||||
|
|
||||||
COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-uninitialized-test_')
|
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||||
|
'googletest-uninitialized-test_'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def Assert(condition):
|
def Assert(condition):
|
||||||
@ -54,11 +56,12 @@ def TestExitCodeAndOutput(command):
|
|||||||
# Verifies that 'command' exits with code 1.
|
# Verifies that 'command' exits with code 1.
|
||||||
p = gtest_test_utils.Subprocess(command)
|
p = gtest_test_utils.Subprocess(command)
|
||||||
if p.exited and p.exit_code == 0:
|
if p.exited and p.exit_code == 0:
|
||||||
Assert('IMPORTANT NOTICE' in p.output);
|
Assert('IMPORTANT NOTICE' in p.output)
|
||||||
Assert('InitGoogleTest' in p.output)
|
Assert('InitGoogleTest' in p.output)
|
||||||
|
|
||||||
|
|
||||||
class GTestUninitializedTest(gtest_test_utils.TestCase):
|
class GTestUninitializedTest(gtest_test_utils.TestCase):
|
||||||
|
|
||||||
def testExitCodeAndOutput(self):
|
def testExitCodeAndOutput(self):
|
||||||
TestExitCodeAndOutput(COMMAND)
|
TestExitCodeAndOutput(COMMAND)
|
||||||
|
|
||||||
|
@ -57,27 +57,43 @@ UNKNOWN_GTEST_PREFIXED_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing'
|
|||||||
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
|
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
|
||||||
INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing'
|
INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing'
|
||||||
|
|
||||||
SUPPORTS_DEATH_TESTS = "DeathTest" in gtest_test_utils.Subprocess(
|
SUPPORTS_DEATH_TESTS = (
|
||||||
[PROGRAM_PATH, LIST_TESTS_FLAG]).output
|
'DeathTest'
|
||||||
|
in gtest_test_utils.Subprocess([PROGRAM_PATH, LIST_TESTS_FLAG]).output
|
||||||
|
)
|
||||||
|
|
||||||
HAS_ABSL_FLAGS = '--has_absl_flags' in sys.argv
|
HAS_ABSL_FLAGS = '--has_absl_flags' in sys.argv
|
||||||
|
|
||||||
# The help message must match this regex.
|
# The help message must match this regex.
|
||||||
HELP_REGEX = re.compile(
|
HELP_REGEX = re.compile(
|
||||||
FLAG_PREFIX + r'list_tests.*' +
|
FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'filter=.*' +
|
+ r'list_tests.*'
|
||||||
FLAG_PREFIX + r'also_run_disabled_tests.*' +
|
+ FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'repeat=.*' +
|
+ r'filter=.*'
|
||||||
FLAG_PREFIX + r'shuffle.*' +
|
+ FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'random_seed=.*' +
|
+ r'also_run_disabled_tests.*'
|
||||||
FLAG_PREFIX + r'color=.*' +
|
+ FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'brief.*' +
|
+ r'repeat=.*'
|
||||||
FLAG_PREFIX + r'print_time.*' +
|
+ FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'output=.*' +
|
+ r'shuffle.*'
|
||||||
FLAG_PREFIX + r'break_on_failure.*' +
|
+ FLAG_PREFIX
|
||||||
FLAG_PREFIX + r'throw_on_failure.*' +
|
+ r'random_seed=.*'
|
||||||
FLAG_PREFIX + r'catch_exceptions=0.*',
|
+ FLAG_PREFIX
|
||||||
re.DOTALL)
|
+ r'color=.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'brief.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'print_time.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'output=.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'break_on_failure.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'throw_on_failure.*'
|
||||||
|
+ FLAG_PREFIX
|
||||||
|
+ r'catch_exceptions=0.*',
|
||||||
|
re.DOTALL,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def RunWithFlag(flag):
|
def RunWithFlag(flag):
|
||||||
@ -172,13 +188,15 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
def testRunsTestsWithoutHelpFlag(self):
|
def testRunsTestsWithoutHelpFlag(self):
|
||||||
"""Verifies that when no help flag is specified, the tests are run
|
"""Verifies that when no help flag is specified, the tests are run
|
||||||
and the help message is not printed."""
|
and the help message is not printed.
|
||||||
|
"""
|
||||||
|
|
||||||
self.TestNonHelpFlag(None)
|
self.TestNonHelpFlag(None)
|
||||||
|
|
||||||
def testRunsTestsWithGtestInternalFlag(self):
|
def testRunsTestsWithGtestInternalFlag(self):
|
||||||
"""Verifies that the tests are run and no help message is printed when
|
"""Verifies that the tests are run and no help message is printed when
|
||||||
a flag starting with Google Test prefix and 'internal_' is supplied."""
|
a flag starting with Google Test prefix and 'internal_' is supplied.
|
||||||
|
"""
|
||||||
|
|
||||||
self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING)
|
self.TestNonHelpFlag(INTERNAL_FLAG_FOR_TESTING)
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ def normalize(obj):
|
|||||||
Normalized output without any references to transient information that may
|
Normalized output without any references to transient information that may
|
||||||
change from run to run.
|
change from run to run.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _normalize(key, value):
|
def _normalize(key, value):
|
||||||
if key == 'time':
|
if key == 'time':
|
||||||
return re.sub(r'^\d+(\.\d+)?s$', '*', value)
|
return re.sub(r'^\d+(\.\d+)?s$', '*', value)
|
||||||
@ -54,6 +55,7 @@ def normalize(obj):
|
|||||||
return re.sub(r'^.*[/\\](.*)', '\\1', value)
|
return re.sub(r'^.*[/\\](.*)', '\\1', value)
|
||||||
else:
|
else:
|
||||||
return normalize(value)
|
return normalize(value)
|
||||||
|
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return {k: _normalize(k, v) for k, v in obj.items()}
|
return {k: _normalize(k, v) for k, v in obj.items()}
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
|
@ -224,8 +224,7 @@ EXPECTED_JSON = """{
|
|||||||
|
|
||||||
|
|
||||||
class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||||
"""Unit test for Google Test's list tests with output to file functionality.
|
"""Unit test for Google Test's list tests with output to file functionality."""
|
||||||
"""
|
|
||||||
|
|
||||||
def testXml(self):
|
def testXml(self):
|
||||||
"""Verifies XML output for listing tests in a Google Test binary.
|
"""Verifies XML output for listing tests in a Google Test binary.
|
||||||
@ -244,19 +243,22 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
|||||||
self._TestOutput('json', EXPECTED_JSON)
|
self._TestOutput('json', EXPECTED_JSON)
|
||||||
|
|
||||||
def _GetOutput(self, out_format):
|
def _GetOutput(self, out_format):
|
||||||
file_path = os.path.join(gtest_test_utils.GetTempDir(),
|
file_path = os.path.join(
|
||||||
'test_out.' + out_format)
|
gtest_test_utils.GetTempDir(), 'test_out.' + out_format
|
||||||
|
)
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
|
||||||
'gtest_list_output_unittest_')
|
'gtest_list_output_unittest_'
|
||||||
|
)
|
||||||
|
|
||||||
command = ([
|
command = [
|
||||||
gtest_prog_path,
|
gtest_prog_path,
|
||||||
'%s=%s:%s' % (GTEST_OUTPUT_FLAG, out_format, file_path),
|
'%s=%s:%s' % (GTEST_OUTPUT_FLAG, out_format, file_path),
|
||||||
'--gtest_list_tests'
|
'--gtest_list_tests',
|
||||||
])
|
]
|
||||||
environ_copy = os.environ.copy()
|
environ_copy = os.environ.copy()
|
||||||
p = gtest_test_utils.Subprocess(
|
p = gtest_test_utils.Subprocess(
|
||||||
command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir())
|
command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir()
|
||||||
|
)
|
||||||
|
|
||||||
self.assertTrue(p.exited)
|
self.assertTrue(p.exited)
|
||||||
self.assertEqual(0, p.exit_code)
|
self.assertEqual(0, p.exit_code)
|
||||||
@ -275,9 +277,10 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
|||||||
expected_line_re = re.compile(expected_line.strip())
|
expected_line_re = re.compile(expected_line.strip())
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
expected_line_re.match(actual_line.strip()),
|
expected_line_re.match(actual_line.strip()),
|
||||||
('actual output of "%s",\n'
|
'actual output of "%s",\n'
|
||||||
'which does not match expected regex of "%s"\n'
|
'which does not match expected regex of "%s"\n'
|
||||||
'on line %d' % (actual, expected_output, line_count)))
|
'on line %d' % (actual, expected_output, line_count),
|
||||||
|
)
|
||||||
line_count = line_count + 1
|
line_count = line_count + 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
|
|||||||
skip_fixture = 'Skipped\nskipping all tests for this fixture\n'
|
skip_fixture = 'Skipped\nskipping all tests for this fixture\n'
|
||||||
self.assertIsNotNone(
|
self.assertIsNotNone(
|
||||||
re.search(skip_fixture + '.*' + skip_fixture, OUTPUT, flags=re.DOTALL),
|
re.search(skip_fixture + '.*' + skip_fixture, OUTPUT, flags=re.DOTALL),
|
||||||
repr(OUTPUT))
|
repr(OUTPUT),
|
||||||
|
)
|
||||||
self.assertNotIn('FAILED', OUTPUT)
|
self.assertNotIn('FAILED', OUTPUT)
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,8 @@ from googletest.test import gtest_test_utils
|
|||||||
|
|
||||||
# Path to the gtest_skip_in_environment_setup_test binary
|
# Path to the gtest_skip_in_environment_setup_test binary
|
||||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
|
||||||
'gtest_skip_in_environment_setup_test')
|
'gtest_skip_in_environment_setup_test'
|
||||||
|
)
|
||||||
|
|
||||||
OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
|
OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
|
||||||
|
|
||||||
|
@ -76,8 +76,9 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
# We want the trailing '/' that the last "" provides in os.path.join, for
|
# We want the trailing '/' that the last "" provides in os.path.join, for
|
||||||
# telling Google Test to create an output directory instead of a single file
|
# telling Google Test to create an output directory instead of a single file
|
||||||
# for xml output.
|
# for xml output.
|
||||||
self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(),
|
self.output_dir_ = os.path.join(
|
||||||
GTEST_OUTPUT_SUBDIR, "")
|
gtest_test_utils.GetTempDir(), GTEST_OUTPUT_SUBDIR, ""
|
||||||
|
)
|
||||||
self.DeleteFilesAndDir()
|
self.DeleteFilesAndDir()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -106,14 +107,15 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
def _TestOutFile(self, test_name, expected_xml):
|
def _TestOutFile(self, test_name, expected_xml):
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
|
||||||
command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
|
command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
|
||||||
p = gtest_test_utils.Subprocess(command,
|
p = gtest_test_utils.Subprocess(
|
||||||
working_dir=gtest_test_utils.GetTempDir())
|
command, working_dir=gtest_test_utils.GetTempDir()
|
||||||
|
)
|
||||||
self.assertTrue(p.exited)
|
self.assertTrue(p.exited)
|
||||||
self.assertEqual(0, p.exit_code)
|
self.assertEqual(0, p.exit_code)
|
||||||
|
|
||||||
output_file_name1 = test_name + ".xml"
|
output_file_name1 = test_name + ".xml"
|
||||||
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
output_file1 = os.path.join(self.output_dir_, output_file_name1)
|
||||||
output_file_name2 = 'lt-' + output_file_name1
|
output_file_name2 = "lt-" + output_file_name1
|
||||||
output_file2 = os.path.join(self.output_dir_, output_file_name2)
|
output_file2 = os.path.join(self.output_dir_, output_file_name2)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
os.path.isfile(output_file1) or os.path.isfile(output_file2),
|
||||||
@ -126,8 +128,7 @@ class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
|
|||||||
else:
|
else:
|
||||||
actual = minidom.parse(output_file2)
|
actual = minidom.parse(output_file2)
|
||||||
self.NormalizeXml(actual.documentElement)
|
self.NormalizeXml(actual.documentElement)
|
||||||
self.AssertEquivalentNodes(expected.documentElement,
|
self.AssertEquivalentNodes(expected.documentElement, actual.documentElement)
|
||||||
actual.documentElement)
|
|
||||||
expected.unlink()
|
expected.unlink()
|
||||||
actual.unlink()
|
actual.unlink()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user