Skip to content

Commit 7b76d30

Browse files
oaldersgenio
authored andcommitted
Use Try::Tiny in test rather than Test::Fatal.
1 parent 6a9cefc commit 7b76d30

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

META.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"PerlIO::encoding" : "0",
6767
"Test::More" : "0.88",
6868
"Time::Local" : "0",
69+
"Try::Tiny" : "0",
6970
"perl" : "5.008001"
7071
}
7172
}

Makefile.PL

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ my %WriteMakefileArgs = (
4242
"TEST_REQUIRES" => {
4343
"PerlIO::encoding" => 0,
4444
"Test::More" => "0.88",
45-
"Time::Local" => 0
45+
"Time::Local" => 0,
46+
"Try::Tiny" => 0
4647
},
4748
"VERSION" => "6.12",
4849
"test" => {
@@ -72,6 +73,7 @@ my %FallbackPrereqs = (
7273
"Storable" => 0,
7374
"Test::More" => "0.88",
7475
"Time::Local" => 0,
76+
"Try::Tiny" => 0,
7577
"URI" => "1.10",
7678
"base" => 0,
7779
"strict" => 0,

cpanfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ on 'test' => sub {
2525
requires "PerlIO::encoding" => "0";
2626
requires "Test::More" => "0.88";
2727
requires "Time::Local" => "0";
28+
requires "Try::Tiny" => "0";
2829
requires "perl" => "5.008001";
2930
};
3031

t/request.t

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@ use strict;
55
use warnings;
66

77
use Test::More;
8-
use Test::Fatal qw( dies_ok lives_ok );
98
plan tests => 15;
109

1110
use HTTP::Request;
11+
use Try::Tiny qw( catch try );
1212

13-
my $req = HTTP::Request->new(GET => "http://www.example.com");
13+
my $req = HTTP::Request->new( GET => "http://www.example.com" );
1414
$req->accept_decodable;
1515

16-
is($req->method, "GET");
17-
is($req->uri, "http://www.example.com");
18-
like($req->header("Accept-Encoding"), qr/\bgzip\b/); # assuming IO::Uncompress::Gunzip is there
16+
is( $req->method, "GET" );
17+
is( $req->uri, "http://www.example.com" );
18+
like( $req->header("Accept-Encoding"), qr/\bgzip\b/ )
19+
; # assuming IO::Uncompress::Gunzip is there
1920

20-
$req->dump(prefix => "# ");
21+
$req->dump( prefix => "# " );
2122

22-
is($req->method("DELETE"), "GET");
23-
is($req->method, "DELETE");
23+
is( $req->method("DELETE"), "GET" );
24+
is( $req->method, "DELETE" );
2425

25-
is($req->uri("http:"), "http://www.example.com");
26-
is($req->uri, "http:");
26+
is( $req->uri("http:"), "http://www.example.com" );
27+
is( $req->uri, "http:" );
2728

2829
$req->protocol("HTTP/1.1");
2930

30-
my $r2 = HTTP::Request->parse($req->as_string);
31-
is($r2->method, "DELETE");
32-
is($r2->uri, "http:");
33-
is($r2->protocol, "HTTP/1.1");
34-
is($r2->header("Accept-Encoding"), $req->header("Accept-Encoding"));
31+
my $r2 = HTTP::Request->parse( $req->as_string );
32+
is( $r2->method, "DELETE" );
33+
is( $r2->uri, "http:" );
34+
is( $r2->protocol, "HTTP/1.1" );
35+
is( $r2->header("Accept-Encoding"), $req->header("Accept-Encoding") );
3536

3637
# Test objects which are accepted as URI-like
3738
{
@@ -57,16 +58,31 @@ is($r2->header("Accept-Encoding"), $req->header("Accept-Encoding"));
5758

5859
package main;
5960

60-
ok( Foo::URI->new->can( 'scheme' ), 'Object can scheme()' );
61-
dies_ok(
62-
sub { HTTP::Request->new( GET => Foo::URI->new ) },
61+
ok( Foo::URI->new->can('scheme'), 'Object can scheme()' );
62+
ok(
63+
!do {
64+
try {
65+
HTTP::Request->new( GET => Foo::URI->new );
66+
return 1;
67+
}
68+
catch { return 0 };
69+
},
6370
'Object without canonical method triggers an exception'
6471
);
6572

66-
ok( Foo::URI::WithCanonical->new->can( 'canonical' ),
67-
'Object can canonical()' );
68-
lives_ok(
69-
sub { HTTP::Request->new( GET => Foo::URI::WithCanonical->new ) },
73+
ok(
74+
Foo::URI::WithCanonical->new->can('canonical'),
75+
'Object can canonical()'
76+
);
77+
78+
ok(
79+
do {
80+
try {
81+
HTTP::Request->new( GET => Foo::URI::WithCanonical->new );
82+
return 1;
83+
}
84+
catch { return 0 };
85+
},
7086
'Object with canonical method does not trigger an exception'
7187
);
7288
}

0 commit comments

Comments
 (0)