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
Comment #3 by andrej.mitrovich — 2013-03-02T11:02:46Z
Comment #4 by andrej.mitrovich — 2013-03-02T13:40:38Z
(In reply to comment #3) > Hmm github bot hasn't posted here. It's fixed though: > https://github.com/D-Programming-Language/phobos/commit/ba4095de5f2c6c62dbec45b71ec3e4ba3d802f90 It was due to a bad commit message, here's gitbot: > https://github.com/D-Programming-Language/phobos/commit/e2831a5f2a7f3a8b0df4e475ff4f79fea2ff5c0f > Fixes Issue 9265 - assertNotThrown should emit msg from thrown exception if > available. > > https://github.com/D-Programming-Language/phobos/commit/ba4095de5f2c6c62dbec45b71ec3e4ba3d802f90 > Merge pull request #1185 from AndrejMitrovic/Fix9625 > > Issue 9265 - assertNotThrown should emit msg from thrown exception if > available.