Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^3: Inverting test conditions in Test::More ? (workaround)

by LanX (Cardinal)
on Jul 24, 2020 at 14:43 UTC ( #11119763=note: print w/replies, xml ) Need Help??

in reply to Re^2: Inverting test conditions in Test::More ? (workaround)
in thread Inverting test conditions in Test::More ?

> But I still need to understand how to make the output of the failed inner test silent ... °

FWIW, this will silence the output, tho using a new Test::Builder object or using Test::Builder::Tester might be the better approach.

use strict; use warnings; use Test::More; my $Test = Test::Builder->new; sub fail_ok (&;@) { my ($code,$description) = @_; # --- silence output my $ignore; $Test->output(\$ignore); $Test->failure_output(\$ignore); $Test->todo_output(\$ignore); my $result; TODO: { local $TODO= "should be silent"; #my $result = subtest "Negation of $description", $code; my $result = $code->(); } # --- undo silence $Test->reset_outputs; # --- output result $result ? fail($description) : pass($description); } fail_ok { is(1,2,"") } "Bingo! Test failed"; fail_ok { is(1,3,"") } "Bingo! Test failed again"; done_testing;

C:/Perl_524/bin\perl.exe -w d:/exp/ ok 2 - Bingo! Test failed ok 4 - Bingo! Test failed again 1..4

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119763]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2020-09-29 15:13 GMT
Find Nodes?
    Voting Booth?
    If at first I don’t succeed, I …

    Results (146 votes). Check out past polls.