Last active
August 29, 2015 14:06
-
-
Save Yoplitein/3b07090caadff0d20f36 to your computer and use it in GitHub Desktop.
D unittesting helper to ensure certain exceptions are thrown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ensure_throws(ExceptionType = Exception)(void delegate() callable, string message = "") | |
{ | |
import core.exception: AssertError; | |
try | |
{ | |
callable(); | |
assert(false, message); | |
} | |
catch(ExceptionType err) {} | |
catch(AssertError err) | |
throw err; | |
catch(Throwable err) | |
assert(false, "callable threw an unexpected exception"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment