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

**URL:** https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803
**Category:** Code
**Tags:** os:linux, tool:ctest
**Created:** [August 22, 2023, 6:53pm UTC](https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803 "2023-08-22T18:53:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![perlun](https://discourse.cmake.org/user_avatar/discourse.cmake.org/perlun/32/3744_2.png) [@perlun](https://discourse.cmake.org/u/perlun)
#### Post date: [August 22, 2023, 6:53pm UTC](https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803/1 "2023-08-22T18:53:33Z")

</div>

Quoting myself from [tests that are meant to abort() - #11 by perlun](https://discourse.cmake.org/t/tests-that-are-meant-to-abort/537/11), 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: [CMake/Source/CTest/cmCTestRunTest.cxx at v3.25.1 · Kitware/CMake · GitHub](https://github.com/Kitware/CMake/blob/v3.25.1/Source/CTest/cmCTestRunTest.cxx#L255), which can be seen when running ctest with `--debug`.

---

<div class="post-metadata">

### Author: ![perlun](https://discourse.cmake.org/user_avatar/discourse.cmake.org/perlun/32/3744_2.png) [@perlun](https://discourse.cmake.org/u/perlun)
#### Post date: [August 22, 2023, 6:56pm UTC](https://discourse.cmake.org/t/why-does-my-test-calling-abort-not-output-anything/8803/2 "2023-08-22T18:56:04Z")

</div>

@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. 🙏 You were indeed right. Changing the `abort()` call to this:

```c
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. ❤

(In other words, this was a typical [XY Problem](https://xyproblem.info/) from my part. 😁)
