| 1 |
# vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et : |
| 2 |
# no package, so things defined here appear in the namespace of the parent. |
| 3 |
use strictures 2; |
| 4 |
use 5.020; |
| 5 |
use stable 0.031 'postderef'; |
| 6 |
use experimental 'signatures'; |
| 7 |
no autovivification warn => qw(fetch store exists delete); |
| 8 |
use if "$]" >= 5.022, experimental => 're_strict'; |
| 9 |
no if "$]" >= 5.031009, feature => 'indirect'; |
| 10 |
no if "$]" >= 5.033001, feature => 'multidimensional'; |
| 11 |
no if "$]" >= 5.033006, feature => 'bareword_filehandles'; |
| 12 |
no if "$]" >= 5.041009, feature => 'smartmatch'; |
| 13 |
no feature 'switch'; |
| 14 |
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8 |
| 15 |
|
| 16 |
use Test::Deep qw(!array !hash !blessed); # import symbols: ignore, re etc |
| 17 |
use Test2::API 'context_do'; |
| 18 |
|
| 19 |
my $encoder = JSON::PP->new->allow_nonref(1)->utf8(0)->allow_blessed(1)->allow_bignum(1)->canonical(1)->convert_blessed(1)->pretty(1)->space_before(0); |
| 20 |
|
| 21 |
# deep comparison, with Test::Deep syntax sugar |
| 22 |
sub cmp_result ($got, $expected, $test_name) { |
| 23 |
context_do { |
| 24 |
my $ctx = shift; |
| 25 |
my ($got, $expected, $test_name) = @_; |
| 26 |
my ($equal, $stack) = Test::Deep::cmp_details($got, $expected); |
| 27 |
if ($equal) { |
| 28 |
$ctx->pass($test_name); |
| 29 |
} |
| 30 |
else { |
| 31 |
$ctx->fail($test_name); |
| 32 |
my $method = |
| 33 |
# be less noisy for expected failures |
| 34 |
(grep $_->{todo}, Test2::API::test2_stack->top->{_pre_filters}->@*) ? 'note' |
| 35 |
: $ENV{AUTHOR_TESTING} || $ENV{AUTOMATED_TESTING} ? 'diag' : 'note'; |
| 36 |
$ctx->$method(Test::Deep::deep_diag($stack)); |
| 37 |
$ctx->$method("got result:\n".$encoder->encode($got)); |
| 38 |
} |
| 39 |
return $equal; |
| 40 |
} $got, $expected, $test_name; |
| 41 |
} |
| 42 |
|
| 43 |
sub failing_test_names ($events) { |
| 44 |
my $sub = sub (@events) { |
| 45 |
map +( |
| 46 |
($_->{pass}//1) ? () : ( |
| 47 |
$_->{name}, |
| 48 |
$_->{subevents} |
| 49 |
? (map +(' '.$_), __SUB__->($_->{subevents}->@*)) |
| 50 |
: (), |
| 51 |
) |
| 52 |
), |
| 53 |
@events |
| 54 |
}; |
| 55 |
|
| 56 |
$sub->($events->flatten(args => [ include_subevents => 1 ])->@*); |
| 57 |
} |
| 58 |
|
| 59 |
1; |