Skip to content

Commit 48b5d92

Browse files
Test::Fatal -> Test2::Tools::Exception
1 parent 1f7207b commit 48b5d92

File tree

12 files changed

+69
-81
lines changed

12 files changed

+69
-81
lines changed

t/add-schema.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ no if "$]" >= 5.041009, feature => 'smartmatch';
1111
no feature 'switch';
1212
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1313

14-
use Test::Fatal;
14+
use Test2::Tools::Exception;
1515
use Test2::Warnings qw(warnings :no_end_test had_no_warnings);
1616
use List::Util 'unpairs';
1717
use lib 't/lib';
@@ -231,7 +231,7 @@ subtest 'add a schema associated with a uri' => sub {
231231
my $js = JSON::Schema::Modern->new;
232232

233233
like(
234-
exception { $js->add_schema('https://foo.com#/x/y/z', {}) },
234+
dies { $js->add_schema('https://foo.com#/x/y/z', {}) },
235235
qr/^cannot add a schema with a uri with a fragment/,
236236
'cannot use a uri with a fragment',
237237
);
@@ -694,13 +694,13 @@ subtest 'register a document against multiple uris, with absolute root uri' => s
694694
);
695695

696696
like(
697-
exception { $js->add_schema('https://uri2.com', { x => 1 }) },
697+
dies { $js->add_schema('https://uri2.com', { x => 1 }) },
698698
qr!^\Quri "https://uri2.com" conflicts with an existing schema resource\E!,
699699
'cannot call add_schema with the same URI as for another schema',
700700
);
701701

702702
like(
703-
exception { $js->add_schema('https://uri3.com', { '$id' => 'https://foo.com', x => 1 }) },
703+
dies { $js->add_schema('https://uri3.com', { '$id' => 'https://foo.com', x => 1 }) },
704704
qr!^\Quri "https://foo.com" conflicts with an existing schema resource\E!,
705705
'cannot reuse the same $id in another document',
706706
);
@@ -862,13 +862,13 @@ subtest 'register a document against multiple uris, with relative root uri' => s
862862
);
863863

864864
like(
865-
exception { $js->add_schema('https://uri2.com', { x => 1 }) },
865+
dies { $js->add_schema('https://uri2.com', { x => 1 }) },
866866
qr!^\Quri "https://uri2.com" conflicts with an existing schema resource\E!,
867867
'cannot call add_schema with the same URI as for another schema',
868868
);
869869

870870
like(
871-
exception { $js->add_schema('https://uri3.com', { '$id' => 'https://uri2.com', x => 1 }) },
871+
dies { $js->add_schema('https://uri3.com', { '$id' => 'https://uri2.com', x => 1 }) },
872872
qr!^\Quri "https://uri2.com" conflicts with an existing schema resource\E!,
873873
'cannot reuse the same $id in another document',
874874
);
@@ -1024,13 +1024,13 @@ subtest 'register a document against multiple uris, with no root uri' => sub {
10241024
);
10251025

10261026
like(
1027-
exception { $js->add_schema('https://uri2.com', { x => 1 }) },
1027+
dies { $js->add_schema('https://uri2.com', { x => 1 }) },
10281028
qr!^\Quri "https://uri2.com" conflicts with an existing schema resource\E!,
10291029
'cannot call add_schema with the same URI as for another schema',
10301030
);
10311031

10321032
like(
1033-
exception { $js->add_schema('https://uri3.com', { '$id' => 'https://uri2.com', x => 1 }) },
1033+
dies { $js->add_schema('https://uri3.com', { '$id' => 'https://uri2.com', x => 1 }) },
10341034
qr!^\Quri "https://uri2.com" conflicts with an existing schema resource\E!,
10351035
'cannot reuse the same $id in another document',
10361036
);

t/annotations.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ no feature 'switch';
1313
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1414

1515
use builtin::compat 'load_module';
16-
use Test::Fatal;
16+
use Test2::Tools::Exception;
1717
use lib 't/lib';
1818
use Helper;
1919

2020
subtest 'draft7' => sub {
2121
like(
22-
exception {
22+
dies {
2323
JSON::Schema::Modern->new(collect_annotations => 1, specification_version => 'draft7');
2424
},
2525
qr/collect_annotations cannot be used with specification_version draft7/,

t/boolean-schemas.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ no if "$]" >= 5.041009, feature => 'smartmatch';
1212
no feature 'switch';
1313
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1414

15-
use Test::Fatal;
15+
use Test2::Tools::Exception;
1616
use lib 't/lib';
1717
use Helper;
1818

@@ -33,7 +33,7 @@ my @tests = (
3333
foreach my $test (@tests) {
3434
my $data = 'hello';
3535
is(
36-
exception {
36+
dies {
3737
my $result = $js->evaluate($data, $test->{schema});
3838
ok(!($result->exception xor $test->{exception}), json_sprintf('%s is not a schema', $test->{schema}));
3939
ok(!($result->valid xor $test->{valid}), json_sprintf('schema: %s evaluates to: %s', $test->{schema}, $test->{valid}));

t/content-encoding.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ no feature 'switch';
1212
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1313
use utf8;
1414

15-
use Test::Fatal;
15+
use Test2::Tools::Exception;
1616
use lib 't/lib';
1717
use Helper;
1818

@@ -56,7 +56,7 @@ subtest 'media_type and encoding handlers' => sub {
5656
my $js = JSON::Schema::Modern->new;
5757

5858
like(
59-
exception { $js->add_media_type('FOO/BAR' => sub { \1 }) },
59+
dies { $js->add_media_type('FOO/BAR' => sub { \1 }) },
6060
qr!Value "FOO/BAR" did not pass type constraint !,
6161
'upper-cased names are not accepted',
6262
);
@@ -103,7 +103,7 @@ subtest 'media_type and encoding handlers' => sub {
103103
);
104104

105105
like(
106-
exception { $js->get_media_type('application/x-ndjson')->(\qq!{"foo":1,"bar":2}\n["a","b",]!) },
106+
dies { $js->get_media_type('application/x-ndjson')->(\qq!{"foo":1,"bar":2}\n["a","b",]!) },
107107
qr/^parse error at line 2: malformed JSON string/,
108108
'application/x-ndjson dies with line number of the bad data',
109109
);

t/dialects.t

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ no feature 'switch';
1313
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1414

1515
use Test2::Warnings qw(warnings :no_end_test had_no_warnings allow_warnings);
16-
use Test::Fatal;
16+
use Test2::Tools::Exception;
1717
use lib 't/lib';
1818
use Helper;
1919

@@ -1691,27 +1691,27 @@ subtest 'custom vocabulary classes with add_vocabulary()' => sub {
16911691
my $js = JSON::Schema::Modern->new;
16921692

16931693
like(
1694-
exception { $js->add_vocabulary('MyVocabulary::Does::Not::Exist') },
1694+
dies { $js->add_vocabulary('MyVocabulary::Does::Not::Exist') },
16951695
qr!an't locate MyVocabulary/Does/Not/Exist.pm in \@INC!,
16961696
'vocabulary class must exist',
16971697
);
16981698

16991699
like(
1700-
exception { $js->add_vocabulary('MyVocabulary::MissingRole') },
1700+
dies { $js->add_vocabulary('MyVocabulary::MissingRole') },
17011701
qr/Value "MyVocabulary::MissingRole" did not pass type constraint/,
17021702
'vocabulary class must implement the role',
17031703
);
17041704

17051705
like(
1706-
exception { $js->add_vocabulary('MyVocabulary::MissingSub') },
1706+
dies { $js->add_vocabulary('MyVocabulary::MissingSub') },
17071707
qr/Can't apply JSON::Schema::Modern::Vocabulary to MyVocabulary::MissingSub - missing vocabulary, keywords/,
17081708
'vocabulary class must implement some subs',
17091709
);
17101710

17111711
cmp_result(
17121712
[ warnings {
17131713
like(
1714-
exception { $js->add_vocabulary('MyVocabulary::BadVocabularySub1') },
1714+
dies { $js->add_vocabulary('MyVocabulary::BadVocabularySub1') },
17151715
qr/Undef did not pass type constraint/,
17161716
'vocabulary() sub in the vocabulary class must return uri => specification_version pairs',
17171717
)
@@ -1721,21 +1721,20 @@ subtest 'custom vocabulary classes with add_vocabulary()' => sub {
17211721
);
17221722

17231723
like(
1724-
exception { $js->add_vocabulary('MyVocabulary::BadVocabularySub2') },
1724+
dies { $js->add_vocabulary('MyVocabulary::BadVocabularySub2') },
17251725
qr!Value "https://some/uri#/invalid/uri" did not pass type constraint!,
17261726
'vocabulary() sub in the vocabulary class must contain valid absolute, fragmentless URIs',
17271727
);
17281728

17291729
like(
1730-
exception { $js->add_vocabulary('MyVocabulary::BadVocabularySub3') },
1730+
dies { $js->add_vocabulary('MyVocabulary::BadVocabularySub3') },
17311731
qr/Value "wrongdraft" did not pass type constraint/,
17321732
'vocabulary() sub in the vocabulary class must reference a known specification version',
17331733
);
17341734

17351735

1736-
is(
1737-
exception { $js->add_vocabulary('MyVocabulary::BadEvaluationOrder') },
1738-
undef,
1736+
ok(
1737+
lives { $js->add_vocabulary('MyVocabulary::BadEvaluationOrder') },
17391738
'added a vocabulary sub',
17401739
);
17411740

@@ -1774,9 +1773,8 @@ subtest 'custom vocabulary classes with add_vocabulary()' => sub {
17741773
'custom vocabulary class has a conflicting evaluation_order',
17751774
);
17761775

1777-
is(
1778-
exception { $js->add_vocabulary('MyVocabulary::StringComparison') },
1779-
undef,
1776+
ok(
1777+
lives { $js->add_vocabulary('MyVocabulary::StringComparison') },
17801778
'added another vocabulary sub',
17811779
);
17821780

@@ -1813,15 +1811,14 @@ subtest 'custom vocabulary classes with add_vocabulary()' => sub {
18131811

18141812

18151813
like(
1816-
exception { $js->add_vocabulary('MyVocabulary::ReservedKeyword') },
1814+
dies { $js->add_vocabulary('MyVocabulary::ReservedKeyword') },
18171815
qr/^keywords starting with "\$" are reserved for core and cannot be used/,
18181816
'$ keywords are prohibited',
18191817
);
18201818

18211819

1822-
is(
1823-
exception { $js->add_vocabulary('MyVocabulary::ConflictingKeyword') },
1824-
undef,
1820+
ok(
1821+
lives { $js->add_vocabulary('MyVocabulary::ConflictingKeyword') },
18251822
'added another vocabulary sub',
18261823
);
18271824

t/document.t

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ no feature 'switch';
1212
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1313

1414
use Test::Deep::UnorderedPairs;
15-
use Test::Fatal;
15+
use Test2::Tools::Exception;
1616
use Test::Memory::Cycle;
1717
use List::Util 'unpairs';
1818
use lib 't/lib';
@@ -46,7 +46,7 @@ subtest 'boolean document' => sub {
4646
);
4747

4848
like(
49-
exception {
49+
dies {
5050
JSON::Schema::Modern::Document->new(
5151
canonical_uri => Mojo::URL->new('https://foo.com#/x/y/z'),
5252
schema => false,
@@ -885,19 +885,18 @@ subtest 'JSON pointer and URI escaping' => sub {
885885
};
886886

887887
subtest 'resource collisions' => sub {
888-
is(
889-
exception {
888+
ok(
889+
lives {
890890
JSON::Schema::Modern::Document->new(
891891
canonical_uri => Mojo::URL->new('https://foo.com/x/y/z'),
892892
schema => { '$id' => '/x/y/z' },
893893
);
894894
},
895-
undef,
896895
'no collision when adding an identical resource (after resolving with base uri)',
897896
);
898897

899898
like(
900-
exception {
899+
dies {
901900
JSON::Schema::Modern::Document->new(
902901
canonical_uri => Mojo::URL->new('https://foo.com/x/y/z'),
903902
schema => {
@@ -943,23 +942,22 @@ subtest 'resource collisions' => sub {
943942
my $doc2 = JSON::Schema::Modern::Document->new(schema => { '$id' => 'b' });
944943
my $js = JSON::Schema::Modern->new;
945944

946-
is(
945+
ok(
947946
# id resolves to https://foo.com/a/b
948-
exception { $js->add_document('https://foo.com' => $doc1) },
949-
undef,
947+
lives { $js->add_document('https://foo.com' => $doc1) },
950948
'add first document, resolving resources to a base uri',
951949
);
952950

953951
like(
954952
# id resolves to https://foo.com/a/b
955-
exception { $js->add_document('https://foo.com/a/' => $doc2) },
953+
dies { $js->add_document('https://foo.com/a/' => $doc2) },
956954
qr{^uri "https://foo.com/a/b" conflicts with an existing schema resource},
957955
'the resource in the second document resolves to the same uri as from the first document',
958956
);
959957

960958

961-
is(
962-
exception {
959+
ok(
960+
lives {
963961
JSON::Schema::Modern::Document->new(
964962
canonical_uri => Mojo::URL->new('https://foo.com/x/y/z'),
965963
schema => {
@@ -976,7 +974,6 @@ subtest 'resource collisions' => sub {
976974
},
977975
);
978976
},
979-
undef,
980977
'ignored "duplicate" uris embedded in non-schemas',
981978
);
982979
};

t/evaluate_json_string.t

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ no if "$]" >= 5.041009, feature => 'smartmatch';
1212
no feature 'switch';
1313
use open ':std', ':encoding(UTF-8)'; # force stdin, stdout, stderr into utf8
1414

15-
use Test::Fatal;
15+
use Test2::Tools::Exception;
1616

1717
use lib 't/lib';
1818
use Helper;
@@ -21,16 +21,15 @@ my $js = JSON::Schema::Modern->new;
2121

2222
like(ref($js->_json_decoder), qr/^(?:Cpanel::JSON::XS|JSON::PP)$/, 'we have a JSON decoder');
2323

24-
is(
25-
exception {
24+
ok(
25+
lives {
2626
ok($js->evaluate_json_string('true', {})->valid, 'json data "true" is evaluated successfully');
2727
},
28-
undef,
2928
'no exceptions in evaluate_json_string on good json',
3029
);
3130

32-
is(
33-
exception {
31+
ok(
32+
lives {
3433
cmp_result(
3534
$js->evaluate_json_string('blargh', {})->TO_JSON,
3635
{
@@ -46,7 +45,6 @@ is(
4645
'evaluating bad json data returns false, with error',
4746
);
4847
},
49-
undef,
5048
'no exceptions in evaluate_json_string on bad json',
5149
);
5250

0 commit comments

Comments
 (0)