External Issue: Method for asserting Errors in UnitTest

17277, "souris-dev", "Method for asserting Errors in UnitTest", "2021-02-26T08:49:08Z"

The current UnitTest library in Chapel does not have any function to assert the throwing of errors (to check which error is thrown) presently.

This is a feature request to have a function called assertError() or assertThrows() that can take in a function as the first argument, and the class type (an error class type) as the second argument. It checks whether the function given as an argument throws the given type of Error or not; assertion fails if it does not throw that error during execution of the function.

So, for example, we could have something like this (since Chapel supports first-class functions):

use UnitTest;

proc doTestThatThrowsError() {
    // test logic here

proc runTestThatThrowsError(test: borrowed Test) {
    test.assertThrows(doTestThatThrowsError, ErrorType); // ErrorType is a subclass of Error


I think this would be a great addition to have to the current UnitTest library in Chapel, though I am a bit unsure about how exactly this should be implemented.