I am almost out of ideas and horridly frustrated at my inability to once again understand the docs. I’ve read the text regarding the user modules, load_test_files, and yet none of it makes any sense.
How does one write an application in traditional (no modules) and then unit test that applications predicates using begin_test ? I have tried ensure_loaded and all other things, even this page didn’t provide an answer;
https://www.swi-prolog.org/pldoc/man?predicate=load_test_files/1
If I prefix the predicate under test with user:
then it works but I really don’t want to have to do that. I tried adding :-module(user)
just after the begin_test but that had no effect.
My project structure is:
root/
load.pl
src/
*.pl and *.plt files
In my load file I have this set as the initialisation predicate but Eclipse PDT seems not to run it so I have to manually run setup/0
each time,
:- initialization(setup).
setup :-
set_prolog_flag(encoding, utf8),
expand_file_name('src/*.pl', Sources),
load_files(Sources),
load_test_files([]),
module(user),
% This makes PDT in Eclipse better!
working_directory(_, '/Users/sean/Documents/code/prolog/f2').
A typical testing scenario:
:- begin_tests(buffer_location).
test(line_update_resets_col_bumps_line,
[true(Out == (1001, 101, 0))]) :-
movepos(0'\n, (1000, 100, 200), Out).
:- end_tests(buffer_location).
This FAILS unless I put user:movepos
as that’s where the predicate lives now rather than the module it used to be in…
plunit_buffer_location:'unit body'/2: Unknown procedure: plunit_buffer_location:movepos/3
I’ve tried adding :-ensure_loaded(tokeniser)
,
Once again I find myself fighting the environment instead of doing something within it.
Maybe I am too dumb after all, I mean if you can’t figure out something this simple, writing tests, then really, ought you to be in the game at all ?