Googletest export
Do not attempt to continue running a test suite if it already failed during `SetUpTestSuite`. The suite already failed and running the tests might just add noise to the run, or even crash the process unnecessarily. Fixes #2187 PiperOrigin-RevId: 397770405
This commit is contained in:
parent
de34ef4e4c
commit
0570d97fb6
@ -3033,10 +3033,16 @@ void TestSuite::Run() {
|
||||
internal::HandleExceptionsInMethodIfSupported(
|
||||
this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()");
|
||||
|
||||
const bool skip_all = ad_hoc_test_result().Failed();
|
||||
|
||||
start_timestamp_ = internal::GetTimeInMillis();
|
||||
internal::Timer timer;
|
||||
for (int i = 0; i < total_test_count(); i++) {
|
||||
GetMutableTestInfo(i)->Run();
|
||||
if (skip_all) {
|
||||
GetMutableTestInfo(i)->Skip();
|
||||
} else {
|
||||
GetMutableTestInfo(i)->Run();
|
||||
}
|
||||
if (GTEST_FLAG_GET(fail_fast) &&
|
||||
GetMutableTestInfo(i)->result()->Failed()) {
|
||||
for (int j = i + 1; j < total_test_count(); j++) {
|
||||
|
@ -147,19 +147,19 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
||||
self.assertTrue(
|
||||
'CxxExceptionInConstructorTest::TearDownTestSuite() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
self.assertFalse(
|
||||
'CxxExceptionInSetUpTestSuiteTest constructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
self.assertFalse(
|
||||
'CxxExceptionInSetUpTestSuiteTest destructor '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
self.assertFalse(
|
||||
'CxxExceptionInSetUpTestSuiteTest::SetUp() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
self.assertFalse(
|
||||
'CxxExceptionInSetUpTestSuiteTest::TearDown() '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
self.assertTrue(
|
||||
self.assertFalse(
|
||||
'CxxExceptionInSetUpTestSuiteTest test body '
|
||||
'called as expected.' in EX_BINARY_OUTPUT, EX_BINARY_OUTPUT)
|
||||
|
||||
|
@ -12,7 +12,7 @@ Expected equality of these values:
|
||||
3
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [mRunning 88 tests from 41 test suites.
|
||||
[0;32m[==========] [mRunning 89 tests from 42 test suites.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@ -956,6 +956,17 @@ Stack trace: (omitted)
|
||||
~DynamicFixture()
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
DynamicFixture::TearDownTestSuite
|
||||
[0;32m[----------] [m1 test from TestSuiteThatFailsToSetUp
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Value of: false
|
||||
Actual: false
|
||||
Expected: true
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[ RUN ] [mTestSuiteThatFailsToSetUp.ShouldNotRun
|
||||
googletest-output-test_.cc:#: Skipped
|
||||
|
||||
[0;32m[ SKIPPED ] [mTestSuiteThatFailsToSetUp.ShouldNotRun
|
||||
[0;32m[----------] [m1 test from PrintingFailingParams/FailingParamTest
|
||||
[0;32m[ RUN ] [mPrintingFailingParams/FailingParamTest.Fails/0
|
||||
googletest-output-test_.cc:#: Failure
|
||||
@ -1032,8 +1043,10 @@ Failed
|
||||
Expected fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [m88 tests from 41 test suites ran.
|
||||
[0;32m[==========] [m89 tests from 42 test suites ran.
|
||||
[0;32m[ PASSED ] [m31 tests.
|
||||
[0;32m[ SKIPPED ] [m1 test, listed below:
|
||||
[0;32m[ SKIPPED ] [mTestSuiteThatFailsToSetUp.ShouldNotRun
|
||||
[0;31m[ FAILED ] [m57 tests, listed below:
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
|
||||
@ -1094,6 +1107,9 @@ Stack trace: (omitted)
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
|
||||
57 FAILED TESTS
|
||||
[0;31m[ FAILED ] [mTestSuiteThatFailsToSetUp: SetUpTestSuite or TearDownTestSuite
|
||||
|
||||
1 FAILED TEST SUITE
|
||||
[0;33m YOU HAVE 1 DISABLED TEST
|
||||
|
||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
|
@ -1060,6 +1060,14 @@ class BarEnvironment : public testing::Environment {
|
||||
}
|
||||
};
|
||||
|
||||
class TestSuiteThatFailsToSetUp : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestSuite() { EXPECT_TRUE(false); }
|
||||
};
|
||||
TEST_F(TestSuiteThatFailsToSetUp, ShouldNotRun) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// The main function.
|
||||
//
|
||||
// The idea is to use Google Test to run all the tests we have defined (some
|
||||
|
Loading…
Reference in New Issue
Block a user