I would like to create unit tests, where the function is expected to generate
$Aborted, e.g. because it was given wrong input. However, I don't see a way how to make MUnit accept such an outcome. In Workbench, what I get is
Test Failure Message: Aborted during evaluation
A simple example for the frontend would be
ClearAll[Foo];
Foo::msg = "Error! `1` must be an integer!";
Foo[x_] :=
If[ Head[x] =!= Integer,
Message[Foo::msg, x];
Abort[],
x^2
];
Then I tried the following, which apparently doesn't work
<< MUnit`
TestRun[{Test[Foo[1], 1], Test[Foo[2], 4], Test[Foo["d"], $Aborted]}]
since I get
Starting test run "Automatic"
..
Stopping test run on TestTerminate: Aborted during evaluation
!
** Aborted during evaluation **
Tests run: 3
Failures: 0
Messages Failures: 0
Skipped Tests: 0
Errors: 1
Fatal: False
Is there a way to tell MUnit that I want the function to return $Aborted, so that the last test actually succeeds and not fails?
CheckAbort– ilian Jun 10 '15 at 17:35Test[CheckAbort[Foo["d"], "Aborted"], "Aborted", Foo::msg]and it all works fine. Can you please write your comment as an answer, so that I can accept it? – vsht Jun 10 '15 at 20:55