interpl

Experiments with intepreters in Prolog
git clone https://ccx.te2000.cz/git/interpl
Log | Files | Refs | README

commit ad49f09993ef3c417559ce69de157c87dc68c5a6
parent bdb00d284bb614ecc44457b6c3ed053305725338
Author: Jan Pobrislo <ccx@te2000.cz>
Date:   Sat, 12 Sep 2026 20:34:48 +0000

Factor out common test code, run all tests from make

Diffstat:
MMakefile | 2+-
Mdotexp_tests.pl | 12+-----------
Atest_helpers.pl | 19+++++++++++++++++++
Mtests.pl | 12+-----------
4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,2 +1,2 @@ tests: - swipl -g run_tests -t halt tests.pl + swipl -g run_tests -t halt *tests.pl diff --git a/dotexp_tests.pl b/dotexp_tests.pl @@ -1,17 +1,7 @@ :- use_module(library(debug), [assertion/1]). :- use_module(dotexp). - -portray_long :- portray_depth(32). -portray_depth(Depth) :- - set_prolog_flag(answer_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]), - set_prolog_flag(debugger_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]). - -test_one_result(Template, Goal, Output) :- - findall(Template, Goal, Results), - % write(Results), nl, - assertion(length(Results, 1)), - Results = [Output]. +:- use_module(test_helpers). codes_to_ast(Codes, Result) :- test_one_result(E, phrase(dotexp(E), Codes), Result). diff --git a/test_helpers.pl b/test_helpers.pl @@ -0,0 +1,19 @@ +:- module(test_helpers, + [ portray_long/0 + , portray_depth/1 + , test_one_result/3 + ]). + +:- use_module(library(debug), [assertion/1]). + +portray_long :- portray_depth(32). + +portray_depth(Depth) :- + set_prolog_flag(answer_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]), + set_prolog_flag(debugger_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]). + +test_one_result(Template, Goal, Output) :- + findall(Template, Goal, Results), + % write(Results), nl, + assertion(length(Results, 1)), + Results = [Output]. diff --git a/tests.pl b/tests.pl @@ -1,17 +1,7 @@ :- use_module(library(debug), [assertion/1]). :- use_module(interpreter). - -portray_long :- portray_depth(32). -portray_depth(Depth) :- - set_prolog_flag(answer_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]), - set_prolog_flag(debugger_write_options, [quoted(true), portrayed(true), max_depth(Depth), spacing(next_argument)]). - -test_one_result(Template, Goal, Output) :- - findall(Template, Goal, Results), - % write(Results), nl, - assertion(length(Results, 1)), - Results = [Output]. +:- use_module(test_helpers). decode(Codes, Expression) :- test_one_result(E, parse_input_expression(Codes, E), Expression).