catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.46k stars 3.02k forks source link

Getting support for fork() tests #644

Closed Qix- closed 7 years ago

Qix- commented 8 years ago

So I have a few projects where I'm using Catch, and one or both of them require me to do some sort of operation that fork()'s the current process.

Needless to say, it's messy.

Since Catch is now running in two processes, two sets of output occur, which usually always results in one of them failing due to the child process getting signaled or something (especially if we try to exit()). The current fix is to close(1); to silence catch in the forked process, but that's not ideal.

What would be great is to see catch detect when it's being run inside of a fork and act accordingly - perhaps this means just silencing itself or not responding to signals. Or, better yet, format output accordingly.

Even better would be to have the parent process detect that it has forked and force the child process to open up a new file descriptor (FIFO or pipe or something) to write error messages to that the parent process can parse and use.

I know this would require a lot of work but by golly this would make Catch absolutely perfect. Even being able to detect if a forked process hasn't quit when we've reached the end of a SECTION() {} would be damn amazing.

Just a thought.

horenmar commented 7 years ago

Since this will not be added to Catch Classic, but might be added to Catch 2 at some point, I opened #853 instead.