I would like to have both lines 06 and 02 reported in the output somehow. Right now I either get only 06, or only 02 reported (based on whether or not I use CPPUNIT_ASSERT_ASSERTION_PASS). Is this possible?
Thanks so much in advance!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When writing ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER, I started off by copying CPPUNIT_ASSERT_NO_THROW_MESSAGE. So you might also want to take a look at that one. I used CppUnit::StringTools::toString, so you'd have to #include <cppunit/tools/StringTools.h> before calling ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER.
If you think you can further improve ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER, please post your version here as well :-)
Hi again. Sorry I didn't respond earlier; I've had a very hectic month working a different shift & all.. Anyway, I want to say thank you _very_ much. That was a huge help, and it definitely solves my problems.
If I do end up improving it somehow, I will definitely copy it here.
Thanks again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Say I have the following
01. void testSub() {
02. CPPUNIT_FAIL("Intentional");
03. }
04.
05. void TestFrameWork:testCase() {
06. CPPUNIT_ASSERT_ASSERTION_PASS(testSub());
07. }
I would like to have both lines 06 and 02 reported in the output somehow. Right now I either get only 06, or only 02 reported (based on whether or not I use CPPUNIT_ASSERT_ASSERTION_PASS). Is this possible?
Thanks so much in advance!
Hi Michael,
Would the following handmade macro be helpful to you?
#define ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER( expression ) \ do { \ CppUnit::Message cpputMsg_( "unexpected exception caught" ); \ cpputMsg_.addDetail( CppUnit::AdditionalMessage() ); \ try { \ expression; \ } catch ( const CppUnit::Exception &e ) { \ cpputMsg_.addDetail( "Caught: CppUnit::exception"); \ cpputMsg_.addDetail( "Line number: " + \ CppUnit::StringTools::toString( e.sourceLine().lineNumber() ) ); \ cpputMsg_.addDetail( std::string("What(): ") + e.what() ); \ CppUnit::Asserter::fail( cpputMsg_, CPPUNIT_SOURCELINE() ); \ } \ } while ( false ) \
To be used as follows:
01. void testSub() {
02. CPPUNIT_FAIL("Intentional");
03. }
04.
05. void TestFrameWork:testCase() {
06. ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER(testSub());
07. }
When writing ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER, I started off by copying CPPUNIT_ASSERT_NO_THROW_MESSAGE. So you might also want to take a look at that one. I used CppUnit::StringTools::toString, so you'd have to #include <cppunit/tools/StringTools.h> before calling ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER.
If you think you can further improve ASSERT_ASSERTION_PASS_WITH_LINE_NUMBER, please post your version here as well :-)
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
Hi again. Sorry I didn't respond earlier; I've had a very hectic month working a different shift & all.. Anyway, I want to say thank you _very_ much. That was a huge help, and it definitely solves my problems.
If I do end up improving it somehow, I will definitely copy it here.
Thanks again!