Thanks, finally someone accepting my question! :)
> There doesn't seem to be a simple, generic way to negate an arbitrary test in Test::More AFAICT.
I just realized that all tests return a boolean result.
So here a workaround:
use strict;
use warnings;
use Test::More;
sub fail_ok (&;@) {
my ($code,$description) = @_;
my $result;
TODO:
{
local $TODO= "should be silent";
my $result = $code->();
}
$result
? fail($description)
: pass($description);
}
fail_ok { is(1,2,"") }
"Bingo! Test failed";
done_testing;
The TODO block ensures that there is no failed test in the final result.
But I still need to understand how to make the output of the failed inner test silent ... °
... I probably need to redirect the STDERR output of Test::Builder or fiddle with TAP altogether
-*- mode: compilation; default-directory: "d:/exp/" -*-
Compilation started at Fri Jul 24 13:02:20
C:/Perl_524/bin\perl.exe -w d:/exp/pm_negate_test.pl
not ok 1 - # TODO should be silent
# Failed (TODO) test ''
# at d:/exp/pm_negate_test.pl line 21.
# got: '1'
# expected: '2'
ok 2 - Bingo! Test failed
1..2
Compilation finished at Fri Jul 24 13:02:21
°) Hmm... probably with subtests... |