Note the two ways to do this via a declaration in the test/2
options list:
Either
For generic terms Error
thrown by throw/1 (i.e. generally not an ISO exception term):
throws(Error)
Body must throw Error
. The thrown error term is matched against term Error
using subsumes_term(Error, ThrownError)
. I.e., the thrown error must be more specific than the specified Error
. See subsumes_term/2.
So you get code like:
test("member, element nonground",throws(error(check(not_ground,_,_,_),_))) :- check_that(_,[lenient(member([a,b,c]))]).
although because the above follows the general error(Explainer,Context)
convention even though it's not a valid ISO exception term, you can still write:
test("member, element nonground",error(check(not_ground,_,_,_))) :- check_that(_,[lenient(member([a,b,c]))]).
Or
For terms error/2
thrown by throw/1
All the ISO exception terms are structured like this: error(Explainer,Context)
where argument 1 carries error information and argument 2 may hold the stacktrace. You just put this into the test head:
error(Explainer)
See keyword throws
(as well as predicate throw/1
and library(error)
) for details.
So you get things like:
test("member, not a proper list",error(domain_error(_,_))) :- check_that(a,[lenient(member([a,b,c|_]))]).
for ISO "domain error" where the Explainer
is domain_error(Expected,Culprit)
.
Don't go crazy
You generally don't want to care about the arguments of the Explainer
(unless you really want to go crazy with detail work), so just use the anonymous variable liberally
error(domain_error(_,_)))