Skip to content

Commit 5135f49

Browse files
committed
Clean up new feedback-catching code. Closes #32
1 parent 97904a3 commit 5135f49

1 file changed

Lines changed: 7 additions & 51 deletions

File tree

plunit_assert.pl

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
base_type(list).
369369
base_type(number).
370370
base_type(string).
371-
%base_type(variable). % not really, but it prevents assert_type/2 testing it as a compound
371+
372372

373373
term_type(Term, Type) :-
374374
( var(Term) -> Type = variable
@@ -383,9 +383,12 @@
383383
%; Type = unknown
384384
).
385385

386-
% feedback(Format, Args) :-
387-
% format(atom(Atom), Format, Args),
388-
% format(user_error, '[plunit_assert] ~s', [Atom]).
386+
prolog:message(plunit_assert(Msg)) -->
387+
[ '[plunit_assert] ~w'-[Msg] ].
388+
389+
feedback(Format, Args) :-
390+
format(atom(Msg), Format, Args),
391+
print_message(error, plunit_assert(Msg)).
389392

390393
call_protected(Cond, Callback) :-
391394
setup_call_cleanup(
@@ -401,18 +404,6 @@
401404
erase(Ref)
402405
),
403406
Failed == false.
404-
/*
405-
pretty_with_eval(Term, Pretty) :-
406-
(
407-
% Try to evaluate as arithmetic
408-
term_type(Term, TermType),
409-
\+ base_type(TermType),
410-
catch(Result is Term, _, fail
411-
)
412-
-> format(atom(Pretty), '~q (~q)', [Term, Result])
413-
; format(atom(Pretty), '~q', [Term])
414-
).
415-
*/
416407

417408
pretty_with_eval(Term, Pretty) :-
418409
(
@@ -438,14 +429,6 @@
438429
% Meta test to check that Goal would trigger a PlUnit test fail
439430
%
440431
% @arg Goal The goal to be queried in the form of a plunit_assert predicate
441-
% assert_test_fails(Goal) :-
442-
% ( Goal
443-
% -> feedback('Asserted test failure but test passed: ~q', [Goal]),
444-
% fail
445-
% ; true
446-
% ).
447-
448-
449432
assert_test_fails(Goal) :-
450433
% Phase 1: silence all messages from the Goal
451434
setup_call_cleanup(
@@ -463,37 +446,10 @@
463446
; true
464447
).
465448

466-
467-
468-
469-
prolog:message(plunit_assert(Msg)) -->
470-
[ '[plunit_assert] ~w'-[Msg] ].
471-
472-
feedback(Format, Args) :-
473-
format(atom(Msg), Format, Args),
474-
print_message(error, plunit_assert(Msg)).
475-
476-
477449
%! assert_test_passes(:Goal) is semidet
478450
%
479451
% Meta test to check that Goal would not trigger a PlUnit test fail
480452
%
481453
% @arg Goal The goal to be queried in the form of a plunit_assert predicate
482454
assert_test_passes(Goal) :-
483455
Goal.
484-
485-
% These don't work. See #20
486-
487-
% assert_test_feedback(TestGoal, Expected) :-
488-
% with_output_to(atom(Actual), catch(TestGoal, _, true)),
489-
% assert_equals(Actual, Expected).
490-
491-
% assert_test_feedback(TestGoal, Expected) :-
492-
% current_output(OldOut),
493-
% with_output_to(atom(Actual), (
494-
% set_output(user_error),
495-
% catch(TestGoal, _, true),
496-
% flush_output(user_error)
497-
% )),
498-
% set_output(OldOut),
499-
% assert_equals(Expected, Actual).

0 commit comments

Comments
 (0)