http://qs321.pair.com?node_id=11119763


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/pm_negate_test.pl 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