| 1 |
# vim: set ts=8 sts=2 sw=2 tw=100 et : |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use 5.020; |
| 5 |
use strictures 2; |
| 6 |
use stable 0.031 'postderef'; |
| 7 |
use experimental 'signatures'; |
| 8 |
no autovivification warn => qw(fetch store exists delete); |
| 9 |
use if "$]" >= 5.022, experimental => 're_strict'; |
| 10 |
no if "$]" >= 5.031009, feature => 'indirect'; |
| 11 |
no if "$]" >= 5.033001, feature => 'multidimensional'; |
| 12 |
no if "$]" >= 5.033006, feature => 'bareword_filehandles'; |
| 13 |
no if "$]" >= 5.041009, feature => 'smartmatch'; |
| 14 |
|
| 15 |
use Test2::API 'intercept'; |
| 16 |
use Test2::V0 qw(!bag !bool), -no_pragmas => 1; |
| 17 |
use if $ENV{AUTHOR_TESTING}, 'Test2::Warnings'; |
| 18 |
use Test::JSON::Schema::Acceptance; |
| 19 |
use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } }; |
| 20 |
|
| 21 |
use lib 't/lib'; |
| 22 |
use Helper; |
| 23 |
|
| 24 |
my $accepter = Test::JSON::Schema::Acceptance->new(test_dir => 't/tests/bad'); |
| 25 |
|
| 26 |
my $events = intercept( |
| 27 |
sub { |
| 28 |
$accepter->acceptance( |
| 29 |
validate_data => sub ($schema, $data) { |
| 30 |
die 'ach I am slain' if $data->{exception}; |
| 31 |
return 1; |
| 32 |
}, |
| 33 |
tests => { file => 'invalid-schema.json' }, |
| 34 |
); |
| 35 |
} |
| 36 |
); |
| 37 |
|
| 38 |
cmp_result( |
| 39 |
[ map exists $_->{parent} |
| 40 |
? { |
| 41 |
details => $_->{assert}{details}, |
| 42 |
pass => $_->{assert}{pass}, |
| 43 |
children => [ map exists $_->{assert} ? $_->{assert} : (), @{$_->{parent}{children}} ], |
| 44 |
} |
| 45 |
: (), |
| 46 |
map $_->facet_data, @$events ], |
| 47 |
[ |
| 48 |
{ |
| 49 |
details => 'invalid-schema.json: "exception handling" - "no exception; expect invalid: want test failure"', |
| 50 |
pass => 0, |
| 51 |
children => [ |
| 52 |
superhashof({ |
| 53 |
details => 'evaluation result is incorrect', |
| 54 |
pass => 0, |
| 55 |
}), |
| 56 |
], |
| 57 |
}, |
| 58 |
{ |
| 59 |
details => 'invalid-schema.json: "exception handling" - "no exception; expect valid: want test pass"', |
| 60 |
pass => 1, |
| 61 |
children => [ |
| 62 |
superhashof({ |
| 63 |
details => 'test passes: data is valid: true', |
| 64 |
pass => 1, |
| 65 |
}), |
| 66 |
], |
| 67 |
}, |
| 68 |
{ |
| 69 |
details => 'invalid-schema.json: "exception handling" - "exception; expect invalid: want test failure (via exception)"', |
| 70 |
pass => 0, |
| 71 |
children => [ |
| 72 |
superhashof({ |
| 73 |
details => re(qr/^died: ach I am slain /), |
| 74 |
pass => 0, |
| 75 |
}), |
| 76 |
], |
| 77 |
}, |
| 78 |
{ |
| 79 |
details => 'invalid-schema.json: "exception handling" - "exception; expect valid: want test failure (via exception)"', |
| 80 |
pass => 0, |
| 81 |
children => [ |
| 82 |
superhashof({ |
| 83 |
details => re(qr/^died: ach I am slain /), |
| 84 |
pass => 0, |
| 85 |
}), |
| 86 |
], |
| 87 |
}, |
| 88 |
], |
| 89 |
'four tests, all with correct results', |
| 90 |
); |
| 91 |
|
| 92 |
done_testing; |