[Exceptional C++ Style] Item 12: Exception Safety: Is it Wort hit?

Ric Parkin ric.parkin at ntlworld.com
Fri Dec 3 04:31:40 EST 2004


 
From: "Paul Grenyer" <paul at paulgrenyer.co.uk>
> This is a matter of opinion. I personally like to clean up properly, even 
> when an application has failed. Kevlin and I had a disagreement a few weeks 
> back (on accu-general I think??) about whether failed unit tests should 
> clear up properly. I think they should...

That reminds me of a really tricky problem with unit testing under C++....

...crashes. 

How do people's test harness cope with the code you're testing having a bug that provokes an access violation/core dump?

I came across this when using my unit test library on both linux and windows and there was a crash (lets say a dereference of a null pointer). The test runner just stopped with nothing to indicate what had gone wrong. 

Unfortunately, the code being tested wasn't being done in TDD mode, but retrofitting tests, so I couldn't just go the the last thing I did.

The partial solution I found was on windows to get the test harness to set the structured exception handler so that OS exceptions were turned into test failures, and everything could carry on (apart from the possibility that the bug had just written over something important)

I never found how to do something similar in linux, which led to the windows build being easier to work on. I assume there mut be a way.

I think boost.test does something rather clever too - runs the test under a seperate thread (process?) so if that test crashes/deadlocks/goes into an infinite loop then it can kill it and carry on.

Ric


-----------------------------------------
Email provided by http://www.ntlhome.com/





More information about the Effective-cpp mailing list