CppUnit Question

Yes, this is a bit OT, but I'm doing unit testing for something that'll get embedded, so it _isn't_ OT!!

The default behavior of CPPUNIT seems to be to stop running a test on the first ASSERT. I'd like to be able to tell it to run _all_ the tests, regardless. Is there a way to do this?

TIA.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott
Loading thread data ...

Some compilers provide a hook to the runtime assert handler. The default behavior is, of course, to terminate the program, but if you can replace the handler you should be able to continue the program.

You may have to work a bit to recover the arguments: usually the assert handler is a stdarg function, but there may be several different definitions of the ASSERT macro and these conceal what argument types are expected. You have to make certain which ASSERT definition is in scope at the point of the call.

George

Reply to
George Neuner

Sorry -- a CPPUNIT_ASSERT, or CPPUNIT_FAIL.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

I'm sure you can do this by patching CppUnit. If you use the assert functions, then maybe it is sufficient to change the throw Exception line in Asserter.cpp and use "cout" instead. But why do you want to do this? It would be against the concept of CppUnit.

--
Frank Buss, http://www.frank-buss.de
piano and more: http://www.youtube.com/user/frankbuss
Reply to
Frank Buss

I've never used cppunit, but I glanced at the source. It appears that the messages are output as a side effect of throwing exceptions, however I can't easily find any exception handlers in the source so I am at a loss to figure out any more. Can you provide a small example of how cppunit is used?

In any event, the exception tie-in might make doing what you want between very hard and impossible. C++ exceptions were not designed to be recovered from ... the stack pointer is reset and any automatic objects that were in context below the catch point are destroyed.

Using SEH on Windows it is possible (though not easy) to continue from the point of an exception, but cppunit doesn't appear to use SEH and you may not be on Windows anyway. Without some compiler specific mechanism like SEH, I just don't know how you might go about doing it. Unfortunately I don't know enough about G++'s exception handling to know if its even possible there.

George

Reply to
George Neuner

Use CppUTest instead better for embedded apps

Reply to
Marco

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.