Philippe Fremy sez:
> Hi,
>
> in the first version of cppunit, IIRC, one could write something like that
> :
>
> CPPUNIT_ASSERT_EQUALS( a, 2 )
>
> and get an error message like
>
> " 'a' was expected to be 2 but was actually 3"
>
> Now the error message is more along
>
> " expected: 2
> but was: 3
> "
>
> There is a loss of information, the name of what was being tested. And I
> like to have it back.
>
> Was it removed because getting a string for this argument was dependant on
> a macro trick ?
Just to fan some flames here, but that's not a macro "trick", it's a very
healthy established practice called "Stringerization". There's no reason not
to do it. I have often gone to great lengths to reproduce the trick in
interpretive languages.
This CppUnit knock-off uses it (and puts it in the Output window of VC++):
http://c2.com/cgi/wiki?VisualCeePlusPlus
#define CPPUNIT_SQUEAK(q) { std::ostringstream z;
z << __FILE__ << '(' << __LINE__ << ") : Failed; " << q << '\n';
cout << z.str() << std::flush;
::OutputDebugString?(z.str().c_str()); worked = false; }
#define CPPUNIT_ASSERT_EQUAL(alpha, omega) if
((alpha) != (omega))
CPPUNIT_SQUEAK(#alpha " != " #omega << "; " << alpha << " != " << omega)
Observe those lines output in "file(#): message" format, meaning VC++ will
navigate to the line that failed the test on an <F4>.
Putting the \ back on the lines is left as an exercize for the user.
I'm not sure if CppUnit has these features either. My minimal implementation
turns VC++ into the test window, and permits very easy round-trip navigation.
--
Phlip
http://www.greencheese.org/EvolutionaryPsychology
-- I'l have my Web site call your Web site... --
|