[ Reference Manual | Alphabetic Index ]

# library(test_util)

Utilities for automated program tests [more]

## Predicates

> fixme +SkippedTest
>   Skip a test that is known to fail.
> get_failed_test_count(-N)
>   Returns the number of tests that failed.
> implies_that(?, ?)
>   No description available
> make_atom(?)
>   No description available
> make_bignum(?)
>   No description available
> make_float(?)
>   No description available
> make_integer(?)
>   No description available
> make_interval(?)
>   No description available
> make_list(?)
>   No description available
> make_negbignum(?)
>   No description available
> make_negfloat(?)
>   No description available
> make_neginteger(?)
>   No description available
> make_neginterval(?)
>   No description available
> make_negrational(?)
>   No description available
> make_nil(?)
>   No description available
> make_rational(?)
>   No description available
> make_string(?)
>   No description available
> make_struct(?)
>   No description available
> make_var(?)
>   No description available
> +Goal should_fail
>   Run the goal Goal and print a message if it doesn't fail
> should_fail(+Goal,+TestName)
>   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 and CheckGoal don't succeed
> should_give(+Goal,+CheckGoal,+TestName)
>   Run the goal Goal and print a message if the result doesn't satisfy CheckGoal
> +Goal should_raise +Event
>   Run the goal Goal and print a message if it doesn't raise Event.
> should_raise(+Goal,+Event,+TestName)
>   Run the goal Goal and print a message if it doesn't raise Event.
> +Goal should_throw +Exception
>   Run the goal Goal and print a message if it doesn't throw Exception
> should_throw(+Goal,+Exception,+TestName)
>   Run the goal Goal and print a message if it doesn't throw Exception
> test(+File)
>   Runs all the test patterns in File.
> test(+File, +Option)
>   Runs all the test patterns in File.
> test_info(+File,+Info)
>   Runs all the test patterns in File, printing the Info string in test_csv_log.

## Other Exports

> export op(1200, fy, fixme)
> export op(1190, xfx, implies_that)
> export op(1110, xfx, should_give)
> export op(1110, xf, should_fail)
> export op(1110, xfx, should_throw)
> export op(1110, xfx, should_raise)

## Description

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

        3.0 > 3 should_fail.
        X is 3.0+4 should_give X=7.0.
        throw(ball) should_throw ball.
        number_string(hello,_) should_raise 5.

The file name should have a .tst extension, e.g. mytests.tst. Then run all the test in the file by calling test(mytests). This will print a message for every test pattern that does not behave as expected. The messages go to a stream called testlog (which defaults to output).

Alternatively, you can write a file with test patterns, using the primitives should_fail/2, should_give/3, should_throw/3 and should_raise/3, e.g.

        should_fail(3.0 > 3, test_float_not_greater_than_integer).
        should_give(X is 3.0+4, X=7.0, test_float_plus_integer_equals_float).
        should_throw(throw(ball),ball,test_throw).
        should_raise(number_string(hello,_),5,test_raises_5).

Here the extra last argument serves as a name for the test (or a short description). It can be an atom or a string and it is used to output results in comma separated format to a stream called test_csv_log (defaults to null), e.g. test(mytest) should output the following to test_csv_log:

        test_float_not_greater_than_integer,pass,2001-10-29,16:59:20,0.00
        test_float_plus_integer_equals_float,pass,2001-10-29,16:59:20,0.01
        test_throw,pass,2001-10-29,16:59:20,0.00
        test_raises_5,pass,2001-10-29,16:59:20,0.00

The first value is the name of the test (last argument in test pattern). The second value is either `pass' or `fail' indicating whether the particular test was successful or not. The third and fourth values show the date and time (UTC) the test was run (in ISO 8601 format). The last value shows the CPU time taken to run the test. Extra values can be appended at the head of the comma separated values by using test_info/2, e.g. test_info(mytest,test_result) would change the output to test_csv_log as follows:

        test_result,test_float_not_greater_than_integer,pass,2001-10-29,16:59:20,0.00
        test_result,test_float_plus_integer_equals_float,pass,2001-10-29,16:59:20,0.01
        test_result,test_throw,pass,2001-10-29,16:59:20,0.00
        test_result,test_raises_5,pass,2001-10-29,16:59:20,0.00

This can be extremely useful, as useful information as the name of the module tested, the directory where it is located, the name of the host, etc. can be added to the log.

## About

- Author: Joachim Schimpf, IC-Parc
- Copyright © Cisco Systems, Inc
- Date: $Date: 2017/09/28 23:49:53 $

Generated from test_util.eci on 2020-02-26 22:26