Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert to use Test::Fatal from Test::Exception

  • Loading branch information...
commit 8fc2f19d1db2efd14fed7513184563c492a9a542 1 parent 534860a
Jeremy Stashewsky authored
2  Makefile.PL
View
@@ -72,7 +72,7 @@ WriteMakefile(ev_args(
'AnyEvent' => 5.261,
'Guard' => 1.012,
'Test::More' => 0.94,
- 'Test::Exception' => 0.29,
+ 'Test::Fatal' => 0.003,
'Test::TCP' => 1.06,
},
PREREQ_PM => {
14 t/01-simple.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 31;
-use Test::Exception;
+use Test::Fatal;
use utf8;
use lib 't'; use Utils;
@@ -14,9 +14,9 @@ ok $socket->fileno, "has a fileno";
my $evh = Feersum->new();
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cb;
{
@@ -24,9 +24,9 @@ my $cb;
$cb = sub { $g = $g; fail "old callback" };
}
-lives_ok {
+is exception {
$evh->request_handler($cb);
-} "can assign code block";
+}, undef, "can assign code block";
undef $cb;
pass "after undef cb";
@@ -52,9 +52,9 @@ $cb = sub {
pass "done request handler";
};
-lives_ok {
+is exception {
$evh->request_handler($cb);
-} "can assign another code block";
+}, undef, "can assign another code block";
my $cv = AE::cv;
$cv->begin;
10 t/02-array-body.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 12;
-use Test::Exception;
+use Test::Fatal;
use utf8;
use lib 't'; use Utils;
@@ -17,17 +17,17 @@ my $evh = Feersum->new();
$evh->request_handler(sub {
my $r = shift;
isa_ok $r, 'Feersum::Connection', 'got an object!';
- lives_ok {
+ is exception {
$r->send_response("200 OK", [
'Content-Type' => 'text/plain; charset=UTF-8',
'Connection' => 'close',
], ['this ',\'should ',undef,'be ','cøncātenated.']);
- } 'sent response';
+ }, undef, 'sent response';
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cv = AE::cv;
$cv->begin;
14 t/03-env-hash.t
View
@@ -2,8 +2,8 @@
use warnings;
use strict;
use Test::More tests => 143;
-use Test::Exception;
use utf8;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -27,7 +27,7 @@ $evh->request_handler(sub {
my $r = shift;
isa_ok $r, 'Feersum::Connection', 'connection';
my $env;
- lives_ok { $env = $r->env() } 'obtain env';
+ is exception { $env = $r->env() }, undef, 'obtain env';
ok $env && ref($env) eq 'HASH', "env hash";
my $tn = $env->{HTTP_X_TEST_NUM} || 0;
@@ -43,7 +43,7 @@ $evh->request_handler(sub {
my $errfh = $env->{'psgi.errors'};
ok $errfh, 'got psgi.errors';
- lives_ok { $errfh->print() } "errors fh can print()";
+ is exception { $errfh->print() }, undef, "errors fh can print()";
is $env->{REQUEST_METHOD}, ($tn == 5 ? 'POST' : 'GET'), "got req method";
like $env->{HTTP_USER_AGENT}, qr/FeersumSimpleClient/, "got UA";
@@ -91,17 +91,17 @@ $evh->request_handler(sub {
ok !exists $env->{HTTP_ACCEPT_LANGUAGE},
"spot check that a placeholder Accept-Language isn't there";
- lives_ok {
+ is exception {
$r->send_response("200 OK", [
'Content-Type' => 'text/plain; charset=UTF-8',
'Connection' => 'close',
], ["Oh Hai $env->{HTTP_X_TEST_NUM}\n"]);
- } 'sent response';
+ }, undef, 'sent response';
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cv = AE::cv;
$cv->begin;
6 t/04-died.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 10;
-use Test::Exception;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -26,9 +26,9 @@ $evh->request_handler(sub {
die "holy crap!";
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cv = AE::cv;
$cv->begin;
10 t/05-streaming.t
View
@@ -5,7 +5,7 @@ use constant CLIENTS_11 => 25;
use constant CLIENTS_10 => 25;
use constant CLIENTS => CLIENTS_11 + CLIENTS_10;
use Test::More tests => 7 + 21 * CLIENTS_11 + 22 * CLIENTS_10;
-use Test::Exception;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -80,9 +80,9 @@ $evh->request_handler(sub {
ok blessed($w), "still blessed? $cnum";
$w->close();
pass "async writer finished $cnum";
- dies_ok {
+ like exception {
$w->write("after completion");
- } "can't write after completion $cnum";
+ }, qr/closed/i, "can't write after completion $cnum";
$finished++;
$cv->end;
undef $t; # important ref
@@ -93,9 +93,9 @@ $evh->request_handler(sub {
};
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
sub client {
my $cnum = sprintf("%04d",shift);
6 t/06-input.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 53;
-use Test::Exception;
+use Test::Fatal;
use Fcntl qw/SEEK_CUR SEEK_SET SEEK_END/;
use lib 't'; use Utils;
@@ -75,9 +75,9 @@ $evh->request_handler(sub {
fail "don't know about client $env->{HTTP_X_CLIENT}";
}
- lives_ok {
+ is exception {
$input->close();
- } 'closed handle';
+ }, undef, 'closed handle';
$r->send_response(200, ['Content-Type' => 'text/plain'], [uc $body]);
pass "sent response";
10 t/07-graceful-shutdown.t
View
@@ -3,7 +3,7 @@ use warnings;
use strict;
use constant CLIENTS => 15;
use Test::More tests => 10 + 11 * CLIENTS;
-use Test::Exception;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -41,10 +41,10 @@ $evh->request_handler(sub {
isa_ok($w, 'Feersum::Connection::Writer', "got a writer $cnum");
isa_ok($w, 'Feersum::Connection::Handle', "... it's a handle $cnum");
my $t; $t = AE::timer 1.5+rand(0.5), 0, sub {
- lives_ok {
+ is exception {
$w->write("So graceful!\n");
$w->close();
- } "wrote after waiting a little $cnum";
+ }, undef, "wrote after waiting a little $cnum";
undef $t; # keep timer alive until it runs
undef $w;
$cv->end;
@@ -52,9 +52,9 @@ $evh->request_handler(sub {
};
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my @got;
sub client {
28 t/08-read-timeout.t
View
@@ -5,8 +5,8 @@ use constant POST_CLIENTS => 5;
use constant GET_CLIENTS => 5;
use constant GOOD_CLIENTS => 5;
use Test::More tests =>
- 17 + 2*POST_CLIENTS + 2*GET_CLIENTS + 4*GOOD_CLIENTS;
-use Test::Exception;
+ 19 + 2*POST_CLIENTS + 2*GET_CLIENTS + 4*GOOD_CLIENTS;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -16,7 +16,7 @@ ok $socket, "made listen socket";
ok $socket->fileno, "has a fileno";
my $evh = Feersum->new();
-lives_ok { $evh->use_socket($socket) };
+is exception { $evh->use_socket($socket) }, undef,;
$evh->request_handler(sub {
my $r = shift;
my $env = $r->env();
@@ -27,22 +27,30 @@ $evh->request_handler(sub {
my $default = $evh->read_timeout;
is $default, 5.0, "default timeout is 5 seconds";
-dies_ok { $evh->read_timeout(-1.0) } "can't set a negative number";
+like exception { $evh->read_timeout(-1.0) },
+ qr/^must set a positive \(non-zero\) value for the timeout/,
+ "can't set a negative number";
is $evh->read_timeout, 5.0;
-dies_ok {
+like exception { $evh->read_timeout(0) },
+ qr/^must set a positive \(non-zero\) value for the timeout/,
+ "can't set a negative number";
+is $evh->read_timeout, 5.0;
+
+like exception {
no warnings 'numeric';
$evh->read_timeout("this isn't a number");
-} "can't set a string as the timeout";
+}, qr/^must set a positive \(non-zero\) value for the timeout/,
+ "can't set a string as the timeout";
is $evh->read_timeout, 5.0;
-lives_ok { $evh->read_timeout(6+1) } "IV is OK";
+is exception { $evh->read_timeout(6+1) }, undef, "IV is OK";
is $evh->read_timeout, 7.0, "new timeout set";
-lives_ok { $evh->read_timeout("8.0") } "NV-as-string is OK";
+is exception { $evh->read_timeout("8.0") }, undef, "NV-as-string is OK";
is $evh->read_timeout, 8.0, "new timeout set";
-lives_ok { $evh->read_timeout($default) } "NV is OK";
+is exception { $evh->read_timeout($default) }, undef, "NV is OK";
is $evh->read_timeout, $default, "reset to default";
@@ -122,5 +130,5 @@ timeout_post_client($_) for (1 .. POST_CLIENTS);
good_client($_) for (1 .. GOOD_CLIENTS);
$cv->end;
-lives_ok { $cv->recv } "no client errors";
+is exception { $cv->recv }, undef, "no client errors";
pass "all done";
14 t/09-magic.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 25;
-use Test::Exception;
+use Test::Fatal;
use utf8;
use lib 't'; use Utils;
@@ -52,32 +52,32 @@ $evh->request_handler(sub {
# magic scalar
tie my $ms, 'My::MagicScalar';
$ms = "foobar";
- lives_ok(sub {
+ is exception {
$r->send_response("200 OK", [
'Content-Type' => 'text/plain',
], \$ms);
- }, "sent response for $type");
+ }, undef, "sent response for $type";
}
elsif ($type eq 'ARRAY') {
# magic array
tie my @ma, 'My::MagicArray';
@ma = ("aaaa","bbb");
- lives_ok(sub {
+ is exception {
$r->send_response("200 OK", [
'Content-Type' => 'text/plain',
], \@ma);
- }, "sent response for $type");
+ }, undef, "sent response for $type";
}
else {
tie my $ms, 'My::MagicScalar';
$ms = "dddd";
tie my @ma, 'My::MagicArray';
@ma = ("cccc",\$ms);
- lives_ok(sub {
+ is exception {
$r->send_response("200 OK", [
'Content-Type' => 'text/plain',
], \@ma);
- }, "sent response for $type");
+ }, undef, "sent response for $type";
}
});
10 t/10-respond-304.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 21;
-use Test::Exception;
+use Test::Fatal;
use utf8;
use lib 't'; use Utils;
@@ -19,19 +19,19 @@ $evh->request_handler(sub {
isa_ok $r, 'Feersum::Connection', 'got an object!';
my $env = $r->env;
ok $env, 'got env';
- lives_ok {
+ is exception {
if ($env->{HTTP_X_CLIENT} == 1) {
$r->send_response("304", [], []); # explicit string, not num
}
else {
$r->send_response("304 Not Modified", ['Content-Length'=>123], []);
}
- } 'sent response for '.$env->{HTTP_X_CLIENT};
+ }, undef, 'sent response for '.$env->{HTTP_X_CLIENT};
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cv = AE::cv;
$cv->begin;
10 t/12-close-on-drop.t
View
@@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More tests => 14;
-use Test::Exception;
+use Test::Fatal;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
@@ -26,14 +26,14 @@ $evh->request_handler(sub {
my $w = $r->start_streaming(200, []);
$w->write("hello ");
$w->write("world!\n");
- lives_ok {
+ is exception {
undef $w;
- } 'no death on undef';
+ }, undef, 'no death on undef';
});
-lives_ok {
+is exception {
$evh->use_socket($socket);
-} 'assigned socket';
+}, undef, 'assigned socket';
my $cv = AE::cv;
1  t/15-write_array.t
View
@@ -3,7 +3,6 @@ use warnings;
use strict;
use constant CLIENTS => 3;
use Test::More tests => 4 + 10 * CLIENTS;
-use Test::Exception;
use lib 't'; use Utils;
BEGIN { use_ok('Feersum') };
Please sign in to comment.
Something went wrong with that request. Please try again.