|
368 | 368 | base_type(list). |
369 | 369 | base_type(number). |
370 | 370 | base_type(string). |
371 | | -%base_type(variable). % not really, but it prevents assert_type/2 testing it as a compound |
| 371 | + |
372 | 372 |
|
373 | 373 | term_type(Term, Type) :- |
374 | 374 | ( var(Term) -> Type = variable |
|
383 | 383 | %; Type = unknown |
384 | 384 | ). |
385 | 385 |
|
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)). |
389 | 392 |
|
390 | 393 | call_protected(Cond, Callback) :- |
391 | 394 | setup_call_cleanup( |
|
401 | 404 | erase(Ref) |
402 | 405 | ), |
403 | 406 | 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 | | -*/ |
416 | 407 |
|
417 | 408 | pretty_with_eval(Term, Pretty) :- |
418 | 409 | ( |
|
438 | 429 | % Meta test to check that Goal would trigger a PlUnit test fail |
439 | 430 | % |
440 | 431 | % @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 | | - |
449 | 432 | assert_test_fails(Goal) :- |
450 | 433 | % Phase 1: silence all messages from the Goal |
451 | 434 | setup_call_cleanup( |
|
463 | 446 | ; true |
464 | 447 | ). |
465 | 448 |
|
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 | | - |
477 | 449 | %! assert_test_passes(:Goal) is semidet |
478 | 450 | % |
479 | 451 | % Meta test to check that Goal would not trigger a PlUnit test fail |
480 | 452 | % |
481 | 453 | % @arg Goal The goal to be queried in the form of a plunit_assert predicate |
482 | 454 | assert_test_passes(Goal) :- |
483 | 455 | 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