Skip to content

Macros to execute compiled program don't force it to quit when test exits #40

@dektar

Description

@dektar

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().";
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions