develooper Front page | perl.perl6.users | Postings from October 2018

Testing Was: Appropriate last words

Thread Previous | Thread Next
Richard Hainsworth
October 21, 2018 08:09
Testing Was: Appropriate last words
Message ID:
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 


     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 

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 <> 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.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About