I'm writing a module and want to exit without a backtrace if conditions are not met.

So I can write:

exit note '$path directory does not exist' unless $path.IO ~~ :d;

Fine. But how do I test this? I thought dies-ok, but dies-ok wants an exception.

test.t:

    sub testnote {exit note 'this ends' }

    dies-ok { testnote }, 'we died';

    my $x = True;

    ok $x, 'next test';

The exit is not trapped. The output I get from prove is:

# prove -ve perl6
t/1-test.t .. this ends
Dubious, test returned 1 (wstat 256, 0x100)

So in this sense 'exit note $message' is not a quiet equivalent of 'die $message'

However `note exit` is an elegant construction. But how do I test for it?

Although Test::Output gives a way to test for stderr output (which note produced), it can't be used simultaneously with an exit trap.


On 04/09/18 21:39, Elizabeth Mattijsen wrote:
FWIW, that’s because the True returned by the “note” gets coerced to Int: True 
-> 1

On 4 Sep 2018, at 15:32, Parrot Raiser <1parr...@gmail.com> wrote:

exit note "message";
seems to work well as a substitute. "note" outputs the message, and
exit sends the return code (1) to the OS, marking a failure.

Reply via email to