Re: [Cppunit-devel] toString() v.s. getName()
Brought to you by:
blep
From: Steve M. R. <ste...@vi...> - 2001-07-14 06:01:08
|
On Tue, Jul 10, 2001 at 05:25:51PM +0200, Baptiste Lepilleur wrote: > Quoting "Steve M. Robbins" <ste...@vi...>: > > > Hi, > > > > With respect to the toString/getName controversy: I realized yesterday > > that the "assertion_traits" class also has a toString() method. In > > this case one is converting an arbitrary type T to a string > > representation, so "toString()" fits better than "getName()". > > > > I'm starting to wonder whether it is better to eliminate getName() > > on the Test classes, and stick with toString() universally. Or, > > we could go ahead with the initial plan, and leave assertion_traits > > to be an exception. > > > > I'm leaning towards the first option. > > Thoughts? > > toString() and getName() have very different semantic. > > * getName(): give me the name of that test so I can identify it. > > * toString(): dump this object as a string so I can diagnose the problem (why > is not equal to that other one) without running the debugger. > > So, I would exterminate toString() from CppUnit, with the exception of > assertion_traits. Mmm. Upon closer examination still, I find that all the exception classes *also* have a toString() method. I understand that one can make the semantic distinction between getName() and toString(), as you say. On the other hand, if a number of the classes use getName() (roughly, the Test hierarchy), and another good fraction use toString() (roughly, the test result classes: assertions and exceptions), folks are likely to be confused. I, for one, will be unable to keep things straight. Why not move to "toString()" across the board? One could say that the semantic of toString() is, as you say, to "dump the object as a string ... for diagnosis". The name of a simple test --- e.g. a TestCase object --- *is* the best textual description of the object. For compounds and composed tests, we are not using the naked name. TestSuite::toString() returns "suite " + name, and RepeatedTest::toString() returns name + " (repeated)". The diagnostic routines, e.g. TestFailure currently use Test::toString(), not Test::getName(), so it is the latter that we can safely discard. -Steve -- by Rocket to the Moon, by Airplane to the Rocket, by Taxi to the Airport, by Frontdoor to the Taxi, by throwing back the blanket and laying down the legs ... - They Might Be Giants |