Debian Codegraph @

t/01-basic.t

raw
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::Deep qw(!array !hash);;
19
20 use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } };
21 use Test::JSON::Schema::Acceptance;
22 use lib 't/lib';
23 use SchemaParser;
24 use Helper;
25
26 my $accepter = Test::JSON::Schema::Acceptance->new(7);
27
28 my $line;
29 my $parser = SchemaParser->new;
30 my $events = intercept(
31 sub {
32 $accepter->acceptance(sub ($schema, $data_string) {
33 return $parser->validate_json_string($data_string, $schema);
34 # we didn't adjust level, so test appears to originate where the subref ends
35 }); $line = __LINE__;
36 }
37 );
38
39 cmp_deeply(
40 $events->[0],
41 all(
42 isa('Test2::Event::Note'),
43 methods(message => 'running tests in '.$accepter->test_dir.' against draft7...'),
44 ),
45 'first test event is the note',
46 );
47
48 my @bool_tests = grep $_->isa('Test2::Event::Ok') && $_->name =~ /boolean type matches booleans/,
49 @$events;
50 is(@bool_tests, 10, 'found all the tests that check for boolean type');
51
52 cmp_deeply(
53 \@bool_tests,
54 array_each(methods(
55 pass => 1,
56 effective_pass => 1,
57 trace => methods(
58 frame => [ 'main', __FILE__, $line, 'Test::JSON::Schema::Acceptance::acceptance' ],
59 ),
60 )),
61 'tests pass for checking schemas that test for boolean type',
62 )
63 or diag "all failing tests:\n", join("\n", failing_test_names($events));
64
65 done_testing;