Sean - 2006-02-16

I've just started using CppUnit, and I'm very happy with it.

One thing I've noticed is that the documentation doesn't say which gets evaluated first in the CPPUNIT_ASSERT*_MESSAGE macros, the message or the condition.

I have found through use, that the message (in CPPUNIT_ASSERT_MESSAGE at least) gets evaluated first (which, I think is implicitly communicated since it is the first parameter for the macro), and I think this should go in the documentation.

I have found knowing this useful for the following at least:

given the diagnostic function:

//! prints out the contents of a GOrderedList
//!
//! \param gol the list whose values we want to print
//! \param str the string to store the representation in using the format:
//!        \n "val1 val2 ... valn"
//! \return a reference to str for easy use of this fn in expressions
template <class tKey, class tKey_ord, class tKey_cmp>
std::string& ordered_list_contents
(const guymast::GOrderedList<tKey, tKey_ord, tKey_cmp>& gol, std::string& str);

I can do the following:

CPPUNIT_ASSERT_MESSAGE(ordered_list_contents(*rlistp, stat), "1 2 3 6 9" == stat);

instead of having to call ordered_list_contents() twice.  Having the message in this case is very helpful for resolving problems.

Maybe this is not a normal use of the macro, and so this shouldn't be documented so that people expect this behaviour, but otherwise, I think it would be good to know this.