2.2 Writing the test body
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Prolog Unit Tests
        • A Unit Test box
          • Writing the test body
            • Testing deterministic predicates
            • Testing semi-deterministic predicates
            • Testing non-deterministic predicates
            • Testing error conditions
            • One body with multiple tests using assertions

2.2.4 Testing error conditions

Error-conditions are tested using the option throws(Error) or by wrapping the test in a catch/3. The following tests are equivalent:

test(div0) :-
     catch(A is 1/0, error(E, _), true),
     E =@= evaluation_error(zero_divisor).

test(div0, [error(evaluation_error(zero_divisor))]) :-
     A is 1/0.