Commit 4194f625 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain

introduce a warning counter, use it through print_message/3

parent c117f67e
......@@ -106,15 +106,18 @@ check_conservation(C) :-
(
check_conserv_reactions(C)
->
message('~w checked from reactions', [C])
print_message(informational, conservation_checked(C, reactions, true))
;
message('~w not checked from reactions', [C]),
print_message(
informational,
conservation_checked(C, reactions, false)
),
check_conserv_num(C)
->
message('~w checked from kinetics', [C])
print_message(informational, conservation_checked(C, kinetics, true))
;
message('~w not checked from kinetics either, but trusted anyway', [C]),
throw(error(unchecked_conservation_law(C)))
print_message(informational, conservation_checked(C, kinetics, false)),
print_message(warning, conservation_trusted(C))
).
......@@ -160,8 +163,17 @@ scalar_conservation([K*M | L], C, Total) :-
Total is I*K + T1.
message(M, O) :-
format(M, O),
nl.
prolog:message(conservation_trusted(C)) -->
['Conservation ~w trusted without proof'-[C]].
prolog:message(conservation_checked(C, From, Truth)) -->
{
Truth == true
->
Not = ''
;
Not = 'not '
},
['Conservation ~w ~wchecked from ~w'-[C, Not, From]].
% vi: set ts=2 sts=2 sw=2
......@@ -58,8 +58,8 @@ test(
test(
'check_conservations is ok with trivial P-invariants',
[
setup(models:clear_model),
cleanup(models:clear_model)
setup((models:clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal)))
]
) :-
command(add_reaction(a => b)),
......@@ -71,8 +71,8 @@ test(
test(
'check_conservations is ok with kinetically conserved moieties',
[
setup(models:clear_model),
cleanup(models:clear_model)
setup((models:clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal)))
]
) :-
command(add_reaction(k*[a] for a => b)),
......@@ -84,16 +84,20 @@ test(
test(
'check_conservations is unhappy with non-conserved moieties',
[
setup(models:clear_model),
cleanup(models:clear_model),
throws(error(unchecked_conservation_law([1*'a', 2*'b'])))
setup((models:clear_model, set_prolog_flag(verbose, silent))),
cleanup((models:clear_model, set_prolog_flag(verbose, normal))),
true(Warnings == 1)
]
) :-
% not written 'a => b' to allow flycheck by separate compilation…
command(add_reaction('=>'(2*a, b))),
command(add_reaction('=>'(a, b))),
set_counter(warnings, 0),
command(add_reaction(2*a => b)),
command(add_reaction(a => b)),
command(add_conservation(a + 2*b)),
with_output_to(atom(_), command(check_conservations)).
with_output_to(atom(_), command(check_conservations)),
count(warnings, Warnings).
:- end_tests(conservation_laws).
set_some_conservations :-
......@@ -103,6 +107,4 @@ set_some_conservations :-
command(add_conservation(c-c + 2*c)).
:- end_tests(conservation_laws).
% vi: set ts=2 sts=2 sw=2
......@@ -19,6 +19,7 @@ loop :-
read_execute_print :-
set_counter(warnings, 0),
read_command(Command),
(
Command = end_of_file
......
......@@ -106,3 +106,8 @@ nth0_eqq(N, [_Head | Tail], Result) :-
executable_filename(Filename) :-
current_prolog_flag(os_argv, [_Swipl, _X, Filename | _]).
user:message_hook(Msg, warning, Lines) :-
count(warnings, _),
fail.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment