Did you know ... Search Documentation:
test_util_iso.pl -- ECLiPSe test automation
PublicShow source

Use this library as follows: Write a file with test patterns, using the primitives should_fail/1, should_give/2, and should_throw/2, e.g.

3.0 > 3       should_fail.
X is 3.0+4    should_give  X==7.0.
throw(ball)   should_throw ball.
arg(0,atom,A) should_throw error(type_error(compound,atom),_).

The file name should have a .tst extension, e.g. mytests.tst. Then run all the test in that file by loading this library and calling test('mytests.tst'). This will print a message for every test, and a summary at the end. To write the results to a file, use test/2 (see below).

To temporarily disable a test in a test file, use the fixme prefix, e.g.

fixme X is 0/0 should_throw error(evaluation_error(undefined),_).

The test procedure will skip those and print a count a the end.

The primitives should_fail/1, should_give/2, should_throw/2 and fixme/1 are also predicates that can be called directly.

Goal should_fail
Run the goal Goal and print a message if it doesn't fail.
Goal should_give +CheckGoal
Run the goal Goal and print a message if Goal does not succeed, or if the result doesn't satisfy CheckGoal.

CheckGoal can be an arbitrary user-defined goal. In this case, the first solution of Goal is committed to, and CheckGoal executed with the variable instantiations of this solution.

To allow verification of goals with multiple solutions, one special form of CheckGoal is recognised:

multiple_solutions(SolCountVar, FinalCheck, SolutionCheck)

where SolCountVar should be a fresh variable. With such a CheckGoal, ALL solutions to Goal will be generated. For each solution, SolutionCheck will be executed with the variable instantiations of this solution, and with SolCountVar instantiated to the number of this solution (starting from 1). After all solutions have been found, FinalCheck will be executed, with SolCountVar instantiated to the total number of solutions.

member(X,[a,b,c])  should_give
    multiple_solutions(K, K==3,
        ( K==1 -> X==a
        ; K==2 -> X==b
        ; K==3 -> X==c
    )).
Goal should_throw +Exception
Run the goal Goal and print a message if it doesn't throw Exception. The exception term thrown must be an instance (see subsumes_term/2) of Exception>
fixme +SkippedTest
Skip a test that is known to fail. fixme/1 is a low-precedence prefix operator, and can thus be textually prefixed to any other test. Its effect is that the test is skipped (not executed). When multiple tests are done, the number of skipped tests gets reported at the end. Skipped tests count as neither succeeded or failed.",
Source test(+TestFile) is det
Runs all the test patterns in TestFile.
Source test(+TestFile, +ResultFile) is det
Runs all the test patterns in TestFile, and logs results in ResultFile.