From: Jesse Luehrs Date: Sun, 31 Oct 2010 21:24:41 +0000 (-0500) Subject: convert to Test::Fatal X-Git-Tag: 0.01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=01b68b64a3f85bdf4615d74d357a4e8735ead106;p=gitmo%2FEval-Closure.git convert to Test::Fatal --- diff --git a/dist.ini b/dist.ini index f844b71..95d5767 100644 --- a/dist.ini +++ b/dist.ini @@ -12,7 +12,7 @@ Sub::Exporter = 0 Try::Tiny = 0 [Prereq / TestRequires] -Test::Exception = 0 +Test::Fatal = 0 Test::More = 0.88 Test::Requires = 0 diff --git a/t/01-basic.t b/t/01-basic.t index 7856f6e..d6d9b37 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Eval::Closure; @@ -12,7 +12,7 @@ use Eval::Closure; ); ok($code, "got something"); - throws_ok { $code->() } qr/^called$/, "got the right thing"; + like(exception { $code->() }, qr/^called$/, "got the right thing"); } { diff --git a/t/02-close-over.t b/t/02-close-over.t index 4b0e06a..8a58aa3 100644 --- a/t/02-close-over.t +++ b/t/02-close-over.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Eval::Closure; @@ -37,12 +37,16 @@ use Test::Requires 'PadWalker'; my $foo = []; my $env = { '$foo' => \$foo }; - throws_ok { - my $code = eval_closure( - source => 'sub { push @$foo, @_; return $__captures }', - environment => $env, - ); - } qr/Global symbol "\$__captures/, "we don't close over \$__captures"; + like( + exception { + eval_closure( + source => 'sub { push @$foo, @_; return $__captures }', + environment => $env, + ); + }, + qr/Global symbol "\$__captures/, + "we don't close over \$__captures" + ); } # it'd be nice if we could test that closing over other things wasn't possible, diff --git a/t/03-description.t b/t/03-description.t index 8f7d893..97f8372 100644 --- a/t/03-description.t +++ b/t/03-description.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Eval::Closure; @@ -17,10 +17,11 @@ SOURCE source => $source, ); - throws_ok { - $code->(); - } qr/^foo at \(eval \d+\) line \d+\n/, - "no location info if context isn't passed"; + like( + exception { $code->() }, + qr/^foo at \(eval \d+\) line \d+\n/, + "no location info if context isn't passed" + ); } { @@ -29,10 +30,11 @@ SOURCE description => 'accessor foo (defined at Class.pm line 282)', ); - throws_ok { - $code->(); - } qr/^foo at accessor foo \(defined at Class\.pm line 282\) line 2\n/, - "description is set"; + like( + exception { $code->() }, + qr/^foo at accessor foo \(defined at Class\.pm line 282\) line 2\n/, + "description is set" + ); } done_testing; diff --git a/t/10-errors.t b/t/10-errors.t index d8925ee..e724e78 100644 --- a/t/10-errors.t +++ b/t/10-errors.t @@ -2,44 +2,54 @@ use strict; use warnings; use Test::More; -use Test::Exception; +use Test::Fatal; use Eval::Closure; -throws_ok { - eval_closure() -} qr/'source'.*required/, "error when source isn't declared"; - -throws_ok { - eval_closure( - source => {}, - ) -} qr/'source'.*string or array/, "error when source isn't string or array"; - -throws_ok { - eval_closure( - source => '1', - ) -} qr/'source'.*return.*sub/, "error when source doesn't return a sub"; - -throws_ok { - eval_closure( - source => 'sub { }', - environment => { 'foo' => \1 }, - ) -} qr/should start with \@, \%, or \$/, "error from malformed env"; - -throws_ok { - eval_closure( - source => 'sub { }', - environment => { '$foo' => 1 }, - ) -} qr/must be.*reference/, "error from non-ref value"; - -throws_ok { - eval_closure( - source => '$1++', - ) -} qr/Modification of a read-only value/, "gives us compile errors properly"; +like( + exception { eval_closure() }, + qr/'source'.*required/, + "error when source isn't declared" +); + +like( + exception { eval_closure(source => {}) }, + qr/'source'.*string or array/, + "error when source isn't string or array" +); + +like( + exception { eval_closure(source => 1) }, + qr/'source'.*return.*sub/, + "error when source doesn't return a sub" +); + +like( + exception { + eval_closure( + source => 'sub { }', + environment => { 'foo' => \1 }, + ) + }, + qr/should start with \@, \%, or \$/, + "error from malformed env" +); + +like( + exception { + eval_closure( + source => 'sub { }', + environment => { '$foo' => 1 }, + ) + }, + qr/must be.*reference/, + "error from non-ref value" +); + +like( + exception { eval_closure(source => '$1++') }, + qr/Modification of a read-only value/, + "gives us compile errors properly" +); done_testing;