Debian Codegraph @

t/unsupported-keywords.t

raw
1 # vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et :
2 use strictures 2;
3 use 5.020;
4 use stable 0.031 'postderef';
5 use experimental 'signatures';
6 no autovivification warn => qw(fetch store exists delete);
7 use if "$]" >= 5.022, experimental => 're_strict';
8 no if "$]" >= 5.031009, feature => 'indirect';
9 no if "$]" >= 5.033001, feature => 'multidimensional';
10 no if "$]" >= 5.033006, feature => 'bareword_filehandles';
11 no if "$]" >= 5.041009, feature => 'smartmatch';
12 no feature 'switch';
13 use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
14
15 use lib 't/lib';
16 use Helper;
17 use Test2::Warnings qw(warnings :no_end_test had_no_warnings);
18
19 my %strings = (
20 id => qr/^no-longer-supported "id" keyword present \(at location ""\): this should be rewritten as "\$id" at /,
21 definitions => qr/^no-longer-supported "definitions" keyword present \(at location ""\): this should be rewritten as "\$defs" at /,
22 dependencies => qr/^no-longer-supported "dependencies" keyword present \(at location ""\): this should be rewritten as "dependentSchemas" or "dependentRequired" at /,
23 );
24
25 my %schemas = (
26 id => 'https://localhost:1234',
27 definitions => {},
28 dependencies => {},
29 );
30
31 my @warnings = (
32 [ draft6 => [ qw(id) ] ],
33 [ draft7 => [ qw(id) ] ],
34 [ 'draft2019-09' => [ qw(id definitions dependencies) ] ],
35 );
36
37 foreach my $index (0 .. $#warnings) {
38 my ($spec_version, $removed_keywords) = $warnings[$index]->@*;
39
40 note "\n", $spec_version;
41 my $js = JSON::Schema::Modern->new(specification_version => $spec_version);
42 foreach my $keyword (@$removed_keywords) {
43 cmp_result(
44 [ warnings {
45 is_equal(
46 $js->evaluate(true, { $keyword => $schemas{$keyword} })->TO_JSON,
47 { valid => true },
48 'schema with "'.$keyword.'" still validates in '.$spec_version,
49 )
50 } ],
51 superbagof(re($strings{$keyword})),
52 'warned for "'.$keyword.'" in '.$spec_version,
53 );
54 }
55
56 next if $index == $#warnings;
57 my ($next_spec_version, $removed_next_keywords) = $warnings[$index+1]->@*;
58 foreach my $keyword (@$removed_next_keywords) {
59 next if grep $keyword eq $_, @$removed_keywords;
60 local $SIG{__WARN__} = sub {
61 warn @_ if $_[0] =~ /^no-longer-supported "$keyword" keyword present/;
62 };
63 is_equal(
64 [ warnings {
65 is_equal(
66 $js->evaluate(true, { $keyword => $schemas{$keyword} })->TO_JSON,
67 { valid => true },
68 'schema with "'.$keyword.'" validates in '.$spec_version,
69 )
70 } ],
71 [],
72 'did not warn for "'.$keyword.'" in '.$spec_version,
73 );
74 }
75 }
76
77 had_no_warnings if $ENV{AUTHOR_TESTING};
78 done_testing;