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...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|