If main has an infinite loop, it'll just keep running as a process in the background even after the test has failed.
This became obvious in Paint Milestone 4 tests when a window was displayed. Here's how I solved it (although in this case I was looking for a timeout):
TEST(PaintProgramTest, StartShowsImage) {
std::chrono::time_pointstd::chrono::system_clock start, end;
start = std::chrono::system_clock::now();
system("timeout 1s ./main");
end = std::chrono::system_clock::now();
std::chrono::duration elapsed_seconds = end - start;
std::chrono::milliseconds ms =
std::chrono::duration_caststd::chrono::milliseconds(elapsed_seconds);
if (ms.count() <= 900) {
FAIL() << " main() should call PaintProgram::Start() which calls "
"Image::ShowUntilClosed().";
}
}