|
76 | 76 | % @arg B The second of the terms to be compared |
77 | 77 | % @see assert_equals/2 |
78 | 78 | assert_not_equals(A, B) :- |
79 | | - call_protected(A \= B, fail_assert_not_equals(A, B)). |
| 79 | + call_protected(\+ equal_after_eval(A, B), |
| 80 | + fail_assert_not_equals(A, B)). |
| 81 | + |
| 82 | +% this differs somewhat from assert_equals/2 at the moment, but this general |
| 83 | +% approach may be more suitable once we start comparing compound terms etc |
| 84 | +equal_after_eval(A, B) :- |
| 85 | + catch(ValA is A, _, fail), |
| 86 | + catch(ValB is B, _, fail), |
| 87 | + ValA =:= ValB, !. |
| 88 | +equal_after_eval(A, B) :- |
| 89 | + A == B. |
80 | 90 |
|
81 | 91 | fail_assert_not_equals(A, B) :- |
82 | 92 | feedback('Asserted ~q and ~q are not equal, but they are', [A, B]). |
|
278 | 288 | assert_output(Goal, Vars, Expected) :- |
279 | 289 | call(Goal), |
280 | 290 | find_values(Vars, Actual), |
281 | | - call_protected(Actual == Expected, fail_assert_output(Expected, Actual)). |
| 291 | + call_protected(Actual == Expected, fail_assert_output(Expected, Actual)), |
| 292 | + !. |
282 | 293 |
|
283 | 294 | find_values([], []). |
284 | 295 | find_values([V|Vs], [Val|Vals]) :- |
|
313 | 324 |
|
314 | 325 | feedback(Format, Args) :- |
315 | 326 | format(atom(Atom), Format, Args), |
316 | | - format(user_error, '[plunit_assert] ~s', [Atom]), |
317 | | - nl(user_error). |
| 327 | + format(user_error, '[plunit_assert] ~s', [Atom]). |
318 | 328 |
|
319 | 329 | call_protected(Cond, Callback) :- |
320 | 330 | setup_call_cleanup( |
|
342 | 352 | % @arg Goal The goal to be queried in the form of a plunit_assert predicate |
343 | 353 | assert_test_fails(Goal) :- |
344 | 354 | ( Goal |
345 | | - -> format('[assert_test_fails] Expected failure but succeeded: ~q~n', [Goal]), |
| 355 | + -> feedback('Asserted test failure but test passed: ~q', [Goal]), |
346 | 356 | fail |
347 | 357 | ; true |
348 | 358 | ). |
|
0 commit comments