Debian Codegraph @

t/06-subset-of-tests.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::JSON::Schema::Acceptance;
19 use List::Util 'sum';
20 use Test::File::ShareDir -share => { -dist => { 'Test-JSON-Schema-Acceptance' => 'share' } };
21
22 use lib 't/lib';
23 use SchemaParser;
24 use Helper;
25
26 my $accepter = Test::JSON::Schema::Acceptance->new(test_dir => 't/tests/subset');
27 my $parser = SchemaParser->new;
28
29 # bar contains only failing tests (3x3)
30 # baz contains only passing tests (3)
31 # foo contains only passing tests (3x3)
32
33 # count indicates the number of tests run from each of: bar.json, baz.json, foo.json
34 foreach my $test (
35 # run tests in this file
36 { count => [0,0,9], tests => { file => 'foo.json' } },
37
38 # run tests in these files
39 { count => [0,3,9], tests => { file => [ 'foo.json', 'baz.json' ] } },
40
41 # run tests in any file, with this group description
42 { count => [3,'0 but true',3], tests => { group_description => 'false schema' } },
43
44 # run tests in this file with this group description
45 { count => [0,0,3], tests => { file => 'foo.json', group_description => 'false schema' } },
46
47 # run tests in this file with these group descriptions
48 {
49 count => [0,0,3+3],
50 tests => { file => 'foo.json', group_description => [ 'true schema', 'false schema' ], },
51 },
52
53 # run tests in this file with this group description and test description
54 { count => [0,0,1], tests => {
55 file => 'foo.json',
56 group_description => 'true schema',
57 test_description => 'boolean false',
58 }
59 },
60
61 # run tests in this file with this group description and these test descriptions
62 { count => [2,0,0], tests => {
63 file => 'bar.json',
64 group_description => 'false schema',
65 test_description => [ 'boolean true', 'boolean false' ],
66 }
67 },
68
69 # run tests in any file with this group description and this test description
70 { count => [1,1,1], tests => {
71 group_description => 'empty schema',
72 test_description => [ 'boolean true' ],
73 }
74 },
75
76 # run tests in any file with any group description with this test description
77 { count => [3,1,3], tests => {
78 test_description => [ 'boolean true' ],
79 }
80 },
81 ) {
82 my ($count, $test_options) = @{$test}{qw(count tests)};
83
84 my $events = intercept( # Test2::API::InterceptResult
85 sub {
86 $accepter->acceptance(
87 validate_data => sub ($schema, $data) {
88 return $parser->validate_data($data, $schema);
89 },
90 tests => $test_options,
91 );
92 }
93 );
94
95 my @tests = grep $_->isa('Test2::Event::Ok'), @$events;
96 is(scalar(@tests), sum(@$count), 'ran ('.join('+',@$count).') tests');
97
98 cmp_result(
99 $accepter->results,
100 [
101 map +(
102 $count->[$_] ? +{
103 file => str([ qw(bar.json baz.json foo.json) ]->[$_]),
104 pass => ($_ ? 0+$count->[$_] : 0),
105 todo_fail => 0,
106 fail => ($_ ? 0 : 0+$count->[$_]),
107 } : ()
108 ), (0..2)
109 ],
110 'result data was populated',
111 )
112 or diag "all failing tests:\n", join("\n", failing_test_names($events));
113 }
114
115 done_testing;