From 01b68b64a3f85bdf4615d74d357a4e8735ead106 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 31 Oct 2010 16:24:41 -0500 Subject: convert to Test::Fatal --- t/01-basic.t | 4 +-- t/02-close-over.t | 18 +++++++----- t/03-description.t | 20 +++++++------ t/10-errors.t | 82 ++++++++++++++++++++++++++++++------------------------ 4 files changed, 70 insertions(+), 54 deletions(-) (limited to 't') 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; -- cgit v1.2.3-54-g00ecf