Thread overview
[Issue 9625] New: assertNotThrown should print exception msg if no msg is provided
Mar 01, 2013
Andrej Mitrovic
Mar 01, 2013
Andrej Mitrovic
Mar 01, 2013
Andrej Mitrovic
Mar 02, 2013
Andrej Mitrovic
Mar 02, 2013
Andrej Mitrovic
March 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9625

           Summary: assertNotThrown should print exception msg if no msg
                    is provided
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: andrej.mitrovich@gmail.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-01 12:33:17 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9625



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-01 12:45:38 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9625


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-01 12:52:20 PST ---
https://github.com/D-Programming-Language/phobos/pull/1185

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9625


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-02 11:02:46 PST ---
Hmm github bot hasn't posted here. It's fixed though: https://github.com/D-Programming-Language/phobos/commit/ba4095de5f2c6c62dbec45b71ec3e4ba3d802f90

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9625



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-02 13:40:38 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------