[Issue 4644] New: assertExceptionThrown to assert that a particular exception was thrown

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 14 21:11:39 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4644

           Summary: assertExceptionThrown to assert that a particular
                    exception was thrown
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmail.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmail.com> 2010-08-14 21:11:36 PDT ---
I would love a function in std.exception which could be used with unit tests to
verify that a particular exception was thrown rather than verify the return
value of a function. So, instead of writing

try
{
    func(/*...*/);
    assert(0, "Exception not thrown");
}
catch(Exception e)
{
}


you'd write something like

assertExceptionThrown(func(/*...*/), Exception);


where you give it the function call and the exception type to catch, which
would then translate to the code above. Now, I'm not sure that you can get
quite that syntax, since you'd be passing a function call with arguments and
all rather a function pointer or delegate with arguments, but there might be a
way to do it more like

assertExceptionThrown(Exception, &func, /*...*/);


and give it a function pointer or delegate with arguments. I'm not enough of a
template wiz to know the best way to build assertExceptionThrown() (I'm not
even sure that I know enough yet to build it all), so I don't know the best way
to do it, but it seems like it should be possible one way or another. And it
would certainly be useful.

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


More information about the Digitalmars-d-bugs mailing list