# Testing abnormal exit of programs

**URL:** https://discourse.cmake.org/t/testing-abnormal-exit-of-programs/5903
**Category:** Usage
**Created:** [June 20, 2022, 1:04pm UTC](https://discourse.cmake.org/t/testing-abnormal-exit-of-programs/5903 "2022-06-20T13:04:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)
#### Post date: [June 20, 2022, 1:04pm UTC](https://discourse.cmake.org/t/testing-abnormal-exit-of-programs/5903/1 "2022-06-20T13:04:50Z")

</div>

I want to test with ctest, that an executable fails (e.g. with abort()).

How can i specify this in ctest?  
How can I set ctestto exlicitly exprect an abort (or SEGV or …)?

```auto
:~/cmake_test/Build$ ninja && ctest
[4/4] Linking CXX executable normal
Test project /home/xxx/cmake_test/Build
    Start 1: normal
1/2 Test #1: normal ........................... Passed 0.00 sec
    Start 2: abort
2/2 Test #2: abort ............................Child aborted***Exception: 0.00 sec

50% tests passed, 1 tests failed out of 2

Total Test time (real) = 0.00 sec

The following tests FAILED:
          2 - abort (Child aborted)
Errors while running CTest

```

**Example:**  
CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.10)
project(cmake_test)

enable_testing()

add_executable(normal normal.cpp)
add_executable(abort abort.cpp)

add_test(NAME normal COMMAND normal)
add_test(NAME abort COMMAND abort)
set_tests_properties(abort PROPERTIES WILL_FAIL True) # does not work on abort()

```

normal.cpp

```auto
int main()
{
    return 0;
}

```

abort.cpp

```auto
#include <cstdlib>

int main()
{
    abort();
    return 0;
}

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 20, 2022, 6:08pm UTC](https://discourse.cmake.org/t/testing-abnormal-exit-of-programs/5903/2 "2022-06-20T18:08:37Z")

</div>

You can expect failure, but that’s really about it; not really any specific kind of failure. For things like this, a wrapper script that does the detection and translation into a normal exit (say, `bash` or PowerShell) would be best I think.
