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

Testing Was: Appropriate last words

Thread Previous | Thread Next
From:
Richard Hainsworth
Date:
October 21, 2018 08:09
Subject:
Testing Was: Appropriate last words
Message ID:
6a3b8ed2-7940-9077-63e3-5a0ef31973b3@gmail.com
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 <1parrota@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.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About