title: How to unit-test for assert() failing?
body: <p>I want to unit-test some code which uses <code>assert()</code> occasionally. Specifically, I want to make sure that certain commands do indeed trigger an assert. But - I don't actually want the program to be aborted. (If that happened I would need both to ensure program abortion from outside the program and have a different program for each such testcase.)</p>
  
  <p>I also know that <code>assert()</code> is a macro, so if the code I'm testing is header-only, I could theoretically write some kind of replacement macro to trigger a failure using my unit-testing library (<a href="https://github.com/onqtam/doctest/" rel="nofollow noreferrer">doctest</a>).</p>
  
  <p>My question:</p>
  
  <ul>
  <li>Perhaps doctest already has some facility for this kind of testing?</li>
  <li>If not, is there some idiomatic way of implementing assert-firing-tests? Perhaps with other testing frameworks/libraries, which I could adapt?</li>
  </ul>
  
  <p>Note: I've noticed <a href="https://stackoverflow.com/a/1116045/1593077">here on SO</a> that Google Test has some kind of related facility, <a href="https://github.com/google/googletest/blob/8b4817e3df3746a20502a84580f661ac448821be/googletest/docs/advanced.md" rel="nofollow noreferrer">ASSERT_DEATH</a>, but it's not clear to me that it does what I want to do.</p>