gtest_premature_exit_test.cc (googletest-release-1.11.0) | : | gtest_premature_exit_test.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 84 | skipping to change at line 84 | |||
// Tests that: | // Tests that: | |||
// - the premature-exit file exists during the execution of a | // - the premature-exit file exists during the execution of a | |||
// death test (EXPECT_DEATH*), and | // death test (EXPECT_DEATH*), and | |||
// - a death test doesn't interfere with the main test process's | // - a death test doesn't interfere with the main test process's | |||
// handling of the premature-exit file. | // handling of the premature-exit file. | |||
TEST_F(PrematureExitDeathTest, FileExistsDuringExecutionOfDeathTest) { | TEST_F(PrematureExitDeathTest, FileExistsDuringExecutionOfDeathTest) { | |||
if (*premature_exit_file_path_ == '\0') { | if (*premature_exit_file_path_ == '\0') { | |||
return; | return; | |||
} | } | |||
EXPECT_DEATH_IF_SUPPORTED({ | EXPECT_DEATH_IF_SUPPORTED( | |||
// If the file exists, crash the process such that the main test | { | |||
// process will catch the (expected) crash and report a success; | // If the file exists, crash the process such that the main test | |||
// otherwise don't crash, which will cause the main test process | // process will catch the (expected) crash and report a success; | |||
// to report that the death test has failed. | // otherwise don't crash, which will cause the main test process | |||
if (PrematureExitFileExists()) { | // to report that the death test has failed. | |||
exit(1); | if (PrematureExitFileExists()) { | |||
} | exit(1); | |||
}, ""); | } | |||
}, | ||||
""); | ||||
} | } | |||
// Tests that the premature-exit file exists during the execution of a | // Tests that the premature-exit file exists during the execution of a | |||
// normal (non-death) test. | // normal (non-death) test. | |||
TEST_F(PrematureExitTest, PrematureExitFileExistsDuringTestExecution) { | TEST_F(PrematureExitTest, PrematureExitFileExistsDuringTestExecution) { | |||
if (*premature_exit_file_path_ == '\0') { | if (*premature_exit_file_path_ == '\0') { | |||
return; | return; | |||
} | } | |||
EXPECT_TRUE(PrematureExitFileExists()) | EXPECT_TRUE(PrematureExitFileExists()) | |||
<< " file " << premature_exit_file_path_ | << " file " << premature_exit_file_path_ | |||
<< " should exist during test execution, but doesn't."; | << " should exist during test execution, but doesn't."; | |||
} | } | |||
} // namespace | } // namespace | |||
int main(int argc, char **argv) { | int main(int argc, char** argv) { | |||
InitGoogleTest(&argc, argv); | InitGoogleTest(&argc, argv); | |||
const int exit_code = RUN_ALL_TESTS(); | const int exit_code = RUN_ALL_TESTS(); | |||
// Test that the premature-exit file is deleted upon return from | // Test that the premature-exit file is deleted upon return from | |||
// RUN_ALL_TESTS(). | // RUN_ALL_TESTS(). | |||
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE"); | const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE"); | |||
if (filepath != nullptr && *filepath != '\0') { | if (filepath != nullptr && *filepath != '\0') { | |||
if (PrematureExitTest::FileExists(filepath)) { | if (PrematureExitTest::FileExists(filepath)) { | |||
printf( | printf( | |||
"File %s shouldn't exist after the test program finishes, but does.", | "File %s shouldn't exist after the test program finishes, but does.", | |||
End of changes. 2 change blocks. | ||||
10 lines changed or deleted | 12 lines changed or added |