Bug 9625 – assertNotThrown should print exception msg if no msg is provided
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-01T12:33:00Z
Last change time
2013-03-02T13:40:38Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-03-01T12:33:17Z
Note the implementation:
void assertNotThrown(T : Throwable = Exception, E)
(lazy E expression,
string msg = null,
string file = __FILE__,
size_t line = __LINE__)
{
try
expression();
catch(T t)
{
immutable tail = msg.empty ? "." : ": " ~ msg;
throw new AssertError(format("assertNotThrown failed: %s was thrown%s",
T.stringof,
tail),
file,
line,
t);
}
}
Specifically this line:
immutable tail = msg.empty ? "." : ": " ~ msg;
This should rather be:
immutable tail = ": " msg.empty ? t.msg : msg;
That way you get back the exception message if you haven't provided your own.
Comment #1 by andrej.mitrovich — 2013-03-01T12:45:38Z
(In reply to comment #0)
> This should rather be:
> immutable tail = ": " msg.empty ? t.msg : msg;
That exact line wouldn't be correct but I'll implement this properly in a pull now.
Comment #2 by andrej.mitrovich — 2013-03-01T12:52:20Z