With SWI-Prolog unit testing using test options forall, setup and cleanup, forall is done before setup

With SWI-Prolog unit testing each test has a few options.

The option foral(:Generator) is useful for creating multiple test examples for a single test.

The options setup(:Goal) and cleanup(:Goal) are nice when working with test that use resources such as streams.

Since forall/1 will acquire the values of a test example item before the test calls setup/1, values needed for setup/1 can be placed in the test example item.


File: example_module.pl

:- module(example_module,[]).
:- load_test_files([]).

File: example_module.plt

:- begin_tests(example_tests).

goal_check :-
setup_check(Values) :-
    format('~nsetup - Values: ~w~n',[Values]).
cleanup_check(Values) :-
    format('cleanup - Values: ~w~n',[Values]).

% The following line is the test example item as noted in the dialog.

test(setup_cleanup_with_options,[forall(setup_cleanup_with_options_case(_,success,Values)),setup(setup_check(Values)),cleanup(cleanup_check(Values))]) :-

:- end_tests(example_tests).

Example run.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.27-20-gd7b1d9a0b)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- working_directory(_,'C:/Users/Groot').

?- [example_module].

?- run_tests.
% PL-Unit: example_tests 
setup - Values: [a,b,c]
cleanup - Values: [a,b,c]
. done
% test passed