% The test suite of the array pack: every test/*.plt.
%
% swipl -g test_array -t halt test/test_array.pl         all the units
% swipl -g "test_array(compile_basics)" -t halt test/test_array.pl
%
% ARRAY_TEST=fast swipl -g test_array -t halt test/test_array.pl
%
% The suite is full by default: the tests that run kernels run on every OpenCL device. A
% fast one, the environment variable ARRAY_TEST=fast or set_prolog_flag(array_test, fast)
% before a run, leaves out the Intel CPU runtime, whose kernel builds are half the time of
% a full suite, where another CPU device is there; see test_devices.pl, whose
% test_device/2 the device loops enumerate and whose test_size/5 gives a test of several
% concrete sizes all of them on one device and a few on the others.
%
% The checkout's prolog/ and lib/<arch>/ come before any installed copy of the pack, so the
% suite tests the sources next to it; build the foreign libraries first (see README.md).

:- module(test_array, [test_array/0, test_array/1]).
:- use_module(library(plunit)).

% The suite runs on the options the devices' properties call for, not on those a tuning of
% this machine kept, see library(array/tuned): its kernels are the same on every machine.
:- create_prolog_flag(array_tuning, false, [type(boolean), keep(true)]).

:- multifile user:file_search_path/2.
:- dynamic user:file_search_path/2.

:- prolog_load_context(directory, Test),
   file_directory_name(Test, Root),
   directory_file_path(Root, prolog, Library),
   current_prolog_flag(arch, Arch),
   atomic_list_concat([Root, lib, Arch], /, Foreign),
   asserta(user:file_search_path(library, Library)),
   asserta(user:file_search_path(foreign, Foreign)).

:- prolog_load_context(directory, Test),
   directory_file_path(Test, '*.plt', Pattern),
   expand_file_name(Pattern, Files),
   load_files(Files, [if(not_loaded)]).

%! test_array is semidet.
%! test_array(+Spec) is semidet.
%
%  Run every unit, or the units and tests of Spec as run_tests/1 takes them; fail if a
%  test fails.
test_array :-
   run_tests.

test_array(Spec) :-
   run_tests(Spec).
