Why does my test calling `abort()` not output anything?

Quoting myself from tests that are meant to abort() - #11 by perlun, but moving this to a separate thread for discoverability:

[P]rocesses raising SIGABRT (e.g. using asserts which call abort()) will cause ctest to print Exception:Subprocess aborted and not show the output from the failing program despite how hard I try to make it: passing --extra-verbose or setting CTEST_OUTPUT_ON_FAILURE=1 in the environment won’t make a single bit of a difference.

Then when I switched the assertion code in my project to use exit(1) instead, it instantly started working.

Is this by design or is this a limitation in ctest/cmake? I’ll readily admit I am (very much) a newbie user of cmake. The versions I’ve tested thus far are 3.24.2 which comes bundled with my CLion and 3.25.1; both seem to exhibit the same behaviour. The exception (in ctest) is typically thrown at this line: https://github.com/Kitware/CMake/blob/v3.25.1/Source/CTest/cmCTestRunTest.cxx#L255, which can be seen when running ctest with --debug.

@craig.scott helped push me in the right direction:

If I had to guess, I’d say what is happening in your case is that your standard output isn’t getting flushed, so you’re losing that output (which would have nothing to do with ctest). Note that exit() does flush all output C streams, whereas I don’t believe abort() does.

Thanks Craig. :pray: You were indeed right. Changing the abort() call to this:

fflush(stdout); // Note: do the same with stderr as well if required
abort();

…made things work so much better. The test output is now visible as it ought to be. :heart:

(In other words, this was a typical XY Problem from my part. :grin:)