How to print to screen in unit tests?

Why is this code not displaying anything on the screen?

  debug(log, 'sum ~q', [Sum]),

debug/3 will only show messages if you’ve turned the “topic” on; have you run debug(log). first?

:- use_module(library(debug)).

:- debug(log).

Strange. I just recently had an issue where debug calls in a thread that was created with user_error pointing elsewhere wouldn’t show up. How is the predicate containing that debug being run?

Something I ended up doing to make it show up:

?- stream_property(S, alias(user_error)), debug(log > S)

The version of plunit in the development versions by default suppresses output for test that succeed. The test framework captures the output and discards it if the test succeeds. You can get the “old” behavior using

?- set_prolog_flag(plunit_output, always).

The stable (9.0.x) always prints output.

Further, when using optimization (-O or the Prolog flag), debug/3 statements are removed by the compiler.

1 Like

it didn’t help me