| 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 SchemaParser; |
| 23 |
use Helper; |
| 24 |
|
| 25 |
my $accepter = Test::JSON::Schema::Acceptance->new(test_dir => 't/tests/subset'); |
| 26 |
my $parser = SchemaParser->new; |
| 27 |
|
| 28 |
# bar contains only failing tests (3x3) |
| 29 |
# baz contains only passing tests (3) |
| 30 |
# foo contains only passing tests (3x3) |
| 31 |
|
| 32 |
foreach my $test ( |
| 33 |
# match tests in this file |
| 34 |
{ todo_count => 9, todo_tests => [ { file => 'foo.json' } ], |
| 35 |
results => [ |
| 36 |
{ file => str('bar.json'), pass => 0, todo_fail => 0, fail => 9 }, |
| 37 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 38 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 39 |
], |
| 40 |
}, |
| 41 |
|
| 42 |
# match tests in these files |
| 43 |
{ todo_count => 9+3, todo_tests => [ { file => [ 'foo.json', 'baz.json' ] } ], |
| 44 |
results => [ |
| 45 |
{ file => str('bar.json'), pass => 0, todo_fail => 0, fail => 9 }, |
| 46 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 47 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 48 |
], |
| 49 |
}, |
| 50 |
|
| 51 |
# match tests in any file, with this group description |
| 52 |
{ todo_count => 3+3, todo_tests => [ { group_description => 'false schema' } ], |
| 53 |
results => [ |
| 54 |
{ file => str('bar.json'), pass => 0, todo_fail => 3, fail => 6 }, |
| 55 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 56 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 57 |
], |
| 58 |
}, |
| 59 |
|
| 60 |
# match tests in this file with this group description |
| 61 |
{ todo_count => 3, todo_tests => [ { file => 'foo.json', group_description => 'false schema' } ], |
| 62 |
results => [ |
| 63 |
{ file => str('bar.json'), pass => 0, todo_fail => 0, fail => 9 }, |
| 64 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 65 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 66 |
], |
| 67 |
}, |
| 68 |
|
| 69 |
# match tests in this file with these group descriptions |
| 70 |
{ |
| 71 |
todo_count => 3+3, |
| 72 |
todo_tests => [ { file => 'foo.json', group_description => [ 'true schema', 'false schema' ] } ], |
| 73 |
results => [ |
| 74 |
{ file => str('bar.json'), pass => 0, todo_fail => 0, fail => 9 }, |
| 75 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 76 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 77 |
], |
| 78 |
}, |
| 79 |
|
| 80 |
# match tests in this file with this group description and test description |
| 81 |
{ todo_count => 1, todo_tests => [ { |
| 82 |
file => 'foo.json', |
| 83 |
group_description => 'true schema', |
| 84 |
test_description => 'boolean false', |
| 85 |
} ], |
| 86 |
results => [ |
| 87 |
{ file => str('bar.json'), pass => 0, todo_fail => 0, fail => 9 }, |
| 88 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 89 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 90 |
], |
| 91 |
}, |
| 92 |
|
| 93 |
# match tests in this file with this group description and these test descriptions |
| 94 |
{ todo_count => 2, todo_tests => [ { |
| 95 |
file => 'bar.json', |
| 96 |
group_description => 'false schema', |
| 97 |
test_description => [ 'boolean true', 'boolean false' ], |
| 98 |
} ], |
| 99 |
results => [ |
| 100 |
{ file => str('bar.json'), pass => 0, todo_fail => 2, fail => 7 }, |
| 101 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 102 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 103 |
], |
| 104 |
}, |
| 105 |
|
| 106 |
# match tests in any file with this group description and this test description |
| 107 |
{ todo_count => 1+1+1, todo_tests => [ { |
| 108 |
group_description => 'empty schema', |
| 109 |
test_description => [ 'boolean true' ], |
| 110 |
} ], |
| 111 |
results => [ |
| 112 |
{ file => str('bar.json'), pass => 0, todo_fail => 1, fail => 8 }, |
| 113 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 114 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 115 |
], |
| 116 |
}, |
| 117 |
|
| 118 |
# match tests in any file with any group description with this test description |
| 119 |
{ todo_count => 3+3+1, todo_tests => [ { test_description => [ 'boolean true' ] } ], |
| 120 |
results => [ |
| 121 |
{ file => str('bar.json'), pass => 0, todo_fail => 3, fail => 6 }, |
| 122 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 123 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 124 |
], |
| 125 |
}, |
| 126 |
|
| 127 |
# match tests with multiple specifications at once |
| 128 |
{ todo_count => 9+3, todo_tests => [ { file => 'foo.json' }, { group_description => 'true schema' } ], |
| 129 |
results => [ |
| 130 |
{ file => str('bar.json'), pass => 0, todo_fail => 3, fail => 6 }, |
| 131 |
{ file => str('baz.json'), pass => 3, todo_fail => 0, fail => 0 }, |
| 132 |
{ file => str('foo.json'), pass => 9, todo_fail => 0, fail => 0 }, |
| 133 |
], |
| 134 |
}, |
| 135 |
) { |
| 136 |
my $todo_count = delete $test->{todo_count}; |
| 137 |
my $events = intercept( |
| 138 |
sub { |
| 139 |
$accepter->acceptance( |
| 140 |
validate_data => sub ($schema, $data) { |
| 141 |
return $parser->validate_data($data, $schema); |
| 142 |
}, |
| 143 |
%$test, |
| 144 |
); |
| 145 |
} |
| 146 |
); |
| 147 |
|
| 148 |
is(scalar(grep $_->isa('Test2::Event::Skip'), @$events), 0, 'skipped and todo_skipped no tests'); |
| 149 |
is( |
| 150 |
scalar( |
| 151 |
grep exists $_->{assert} && (grep $_->{tag} eq 'TODO', @{$_->{amnesty} // []}), |
| 152 |
map $_->facet_data, @$events |
| 153 |
), |
| 154 |
$todo_count, |
| 155 |
'right number of tests are marked TODO ('.$todo_count.')', |
| 156 |
); |
| 157 |
|
| 158 |
cmp_result( |
| 159 |
$accepter->results, |
| 160 |
$test->{results}, |
| 161 |
'result data was populated', |
| 162 |
); |
| 163 |
} |
| 164 |
|
| 165 |
done_testing; |