views:

213

answers:

1
+1  A: 

The CppUnit documentation suggests that runner.addTest takes ownership of whatever test it's given. By giving runner.addTest only part of your myTest instance, you're not providing any way for the entire myTest instance to get cleaned up on deletion. Manually delete'ing myTest after running probably won't work either, since runner will also try to delete the portion of myTest that it's been given.

If you're interested in only running a particular test or subset of tests, you should instead try using the testName parameter of TextRunner::run.

(And if you have the time and inclination, you might want to look into a different unit test framework. UnitTest++ and Google Test are newer, easier to use, and more featureful than CppUnit.)

Josh Kelley
TextRunner::run doesn't work if I do not register the suite for the test I want to run.
Gaetano Mendola
Yes, but your problem is that you allocate an entire suite (myTest) and then only register a part of it. TextRunner cleans up that part but doesn't know to clean up the entire suite.
Josh Kelley
Even if I do runner.addTest(myTest); then I have the same behave, lot of suites not destroyed.
Gaetano Mendola
I'm not sure what else to tell you; sorry. I get correct behavior when I run a very simple CppUnit program through Valgrind; maybe there's a bug in the version of CppUnit you're using, or maybe the leak is in code you haven't posted. It's been a little while since I've used CppUnit; we switched everything to Google Test.
Josh Kelley
I had a quick look at Google Test, it should not be hard to migrate our tests, the hardest stuff is the fact that we use our own TextOutputter (extends CppUnit::TextOutputter) and our own TestListener (extends CppUnit::TestListener ). Thank you for the hint.
Gaetano Mendola