Test/1 clauses included in main test file not being expanded

Term expansion of test/1 clauses doesn’t seem to work when they are included in a main test file through include/1.
I don’t know if this is expected, but I would have guessed that include/1 would not change things regarding the expansion of terms here.

Simple example:

File: main.pl

:- begin_tests(main).

:- include(some_tests).

test(a) :- a == a.

:- end_tests(main).

File: some_tests.pl

test(b) :- b == b. % this is not expanded

Top level

?- plunit_main:listing.

test(b) :-
    b==b.

'unit body'('a@line 5', vars) :-
    !,
    a==a.

'unit test'(a, 5, [true(true)], plunit_main:'unit body'('a@line 5', vars)).
true.

The reason is because we only expand tests when they appear in the same source file as the begin_tests/2. See line 474 of plunit.pl:

system:term_expansion(Term, Expanded) :-
    (   loading_unit(_, _, File, _)
    ->  source_location(File, _),
        expand(Term, Expanded)
    ).

We could expand that to deal with the logic of include/1. Any particular reason why we want this?

1 Like

I’m creating batches of test clauses automatically from data residing in another data source, both to enable collaborators to add test cases without knowing Prolog and to help with refactoring in case some core predicates used in these tests change (in their use or definition).

Apart from my use case, which may be specific, perhaps included files should be dealt with for a matter of consistency/expectation?
Thanks for the answer and confirmation.

I pushed a patch that solves this partially. Including tests works. If the test fails it is reported against the line of the included file but the file is the main file. Fixing that requires getting the right file through the registration and reporting. If anyone cares, please submit a patch. I guess the idea would be to pass in Line a term File:Line, either always or only if the test comes from an included file.

For those wanting to see the details of the patch.