Helper unit testing functions in Phobos (possible std.unittests)

Jonathan M Davis jmdavisProg at gmx.com
Sat Nov 6 21:08:49 PDT 2010


On Saturday 06 November 2010 18:35:29 Nick Sabalausky wrote:
> "Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message
> news:mailman.138.1289084125.21107.digitalmars-d at puremagic.com...
> 
> > On Saturday 06 November 2010 12:28:02 Masahiro Nakagawa wrote:
> >> I don't know this module's usability, but is getExcMsg useful?
> >> I can't imagine useful situation.
> >> In addition, I grepped your datetime.d and getExcMsg not found :(
> >> 
> >> If possible, I want the mock, stub and related features.
> > 
> > It's used to test unittests.d itself, but I don't think that I'm using it
> > in
> > datetime.d at the moment. The idea is to use it if you want to verify
> > that an
> > exception says exactly what you want it to say (especially if you could
> > get
> > multiple exceptions of the same type but with different messages from a
> > function). I will grant you, however, that it's one of the less useful
> > functions.
> 
> I'm not suggesting getExcMsg be removed, but if you ever need to verify an
> exception's message is exactly matches a specific string, then you're
> almost certainly using exceptions the wrong way to begin with.

The reason I created it originally IIRC was to verify stuff like the fact that 
passing an invalid hour to TimeOfDay complained about the hour being incorrect 
rather than the minute or the second. It _is_ arguably error-prone, because it's 
testing the _exact_ error message, but if you're trying to verify that the 
correct exception was thrown and multiple exceptions of the same type can be 
thrown from a function, I don't really see any other way to do it. I ended up 
not using it in std.datetime (probably because I consolidated most of the code 
which threw DateTimeExceptions, so there was less need for it), but I do think 
that it's at least potentially useful if you want to verify that your exceptions 
have the correct error messages.

- Jonathan M Davis


More information about the Digitalmars-d mailing list