From: Tokuhiro Matsuno Date: Wed, 3 Dec 2008 05:44:16 +0000 (+0000) Subject: move Test::Exception to inc/. suggested by autarch++ X-Git-Tag: 0.19~136^2~61 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eab815459cfd4be951f1f44cd656e76169f7a1d6;p=gitmo%2FMouse.git move Test::Exception to inc/. suggested by autarch++ --- diff --git a/Makefile.PL b/Makefile.PL index d89d8f6..675b7fe 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -5,6 +5,8 @@ all_from 'lib/Mouse.pm'; tests 't/*.t t/*/*.t'; +build_requires 'Test::Exception'; +build_requires 'Sub::Uplevel'; # required by Test::Exception build_requires 'Test::More'; WriteAll; diff --git a/t/000-recipes/001_point.t b/t/000-recipes/001_point.t index 450055c..23f15d5 100644 --- a/t/000-recipes/001_point.t +++ b/t/000-recipes/001_point.t @@ -14,7 +14,7 @@ BEGIN { } use Mouse::Util; -use t::Exception; +use Test::Exception; BEGIN { use_ok('Mouse'); diff --git a/t/001-strict.t b/t/001-strict.t index 50f4b41..fb82c0e 100644 --- a/t/001-strict.t +++ b/t/001-strict.t @@ -1,6 +1,6 @@ #!/usr/bin/env perl use Test::More tests => 1; -use t::Exception; +use Test::Exception; throws_ok { package Class; diff --git a/t/007-attributes.t b/t/007-attributes.t index 140d0db..4316e25 100644 --- a/t/007-attributes.t +++ b/t/007-attributes.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 10; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/010-required.t b/t/010-required.t index 6962a29..161717c 100644 --- a/t/010-required.t +++ b/t/010-required.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 3; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/011-lazy.t b/t/011-lazy.t index e23e674..2d87867 100644 --- a/t/011-lazy.t +++ b/t/011-lazy.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 16; -use t::Exception; +use Test::Exception; my $lazy_run = 0; diff --git a/t/016-trigger.t b/t/016-trigger.t index 06f0aff..223e387 100644 --- a/t/016-trigger.t +++ b/t/016-trigger.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 11; -use t::Exception; +use Test::Exception; my @trigger; diff --git a/t/017-default-reference.t b/t/017-default-reference.t index b169ddd..41d2593 100644 --- a/t/017-default-reference.t +++ b/t/017-default-reference.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 8; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/019-handles.t b/t/019-handles.t index 7911f3c..e48511a 100644 --- a/t/019-handles.t +++ b/t/019-handles.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 24; -use t::Exception; +use Test::Exception; do { package Person; diff --git a/t/020-load-class.t b/t/020-load-class.t index b95d180..d115db7 100644 --- a/t/020-load-class.t +++ b/t/020-load-class.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 11; -use t::Exception; +use Test::Exception; require Mouse; use lib 't/lib'; diff --git a/t/021-weak-ref.t b/t/021-weak-ref.t index e626f35..cdafd3c 100644 --- a/t/021-weak-ref.t +++ b/t/021-weak-ref.t @@ -12,7 +12,7 @@ BEGIN { } } -use t::Exception; +use Test::Exception; my %destroyed; diff --git a/t/023-builder.t b/t/023-builder.t index b3cf1c7..6b3e35e 100644 --- a/t/023-builder.t +++ b/t/023-builder.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 47; -use t::Exception; +use Test::Exception; my $builder_called = 0; my $lazy_builder_called = 0; diff --git a/t/024-isa.t b/t/024-isa.t index bae920e..ee970db 100644 --- a/t/024-isa.t +++ b/t/024-isa.t @@ -3,7 +3,7 @@ use strict; use warnings; use Test::More; use IO::Handle; -use t::Exception; +use Test::Exception; my @types = qw/Any Item Bool Undef Defined Value Num Int Str ClassName Ref ScalarRef ArrayRef HashRef CodeRef RegexpRef GlobRef diff --git a/t/025-more-isa.t b/t/025-more-isa.t index 9db3441..132d57f 100644 --- a/t/025-more-isa.t +++ b/t/025-more-isa.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 29; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/026-auto-deref.t b/t/026-auto-deref.t index efc3987..d4b1df5 100644 --- a/t/026-auto-deref.t +++ b/t/026-auto-deref.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 15; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/029-new.t b/t/029-new.t index c35ce6c..d387bdf 100644 --- a/t/029-new.t +++ b/t/029-new.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 5; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/030-has-plus.t b/t/030-has-plus.t index 0c83dcf..34b8ec4 100644 --- a/t/030-has-plus.t +++ b/t/030-has-plus.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 3; -use t::Exception; +use Test::Exception; do { package Class; diff --git a/t/031-clone.t b/t/031-clone.t index 711aaf5..9d7454f 100644 --- a/t/031-clone.t +++ b/t/031-clone.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 10; -use t::Exception; +use Test::Exception; do { package Foo; diff --git a/t/033-requires.t b/t/033-requires.t index dd02d86..bb1a222 100644 --- a/t/033-requires.t +++ b/t/033-requires.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 1; -use t::Exception; +use Test::Exception; { package Foo; diff --git a/t/034-apply_all_roles.t b/t/034-apply_all_roles.t index 4b0dd5c..b69e84f 100644 --- a/t/034-apply_all_roles.t +++ b/t/034-apply_all_roles.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 4; -use t::Exception; +use Test::Exception; { package FooRole; diff --git a/t/301-bugs-non-mouse.t b/t/301-bugs-non-mouse.t index 413b208..bfa53a4 100644 --- a/t/301-bugs-non-mouse.t +++ b/t/301-bugs-non-mouse.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More 'no_plan'; -use t::Exception; +use Test::Exception; { package Foo; diff --git a/t/400-define-role.t b/t/400-define-role.t index 5e1e2d1..d2ab456 100644 --- a/t/400-define-role.t +++ b/t/400-define-role.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 11; -use t::Exception; +use Test::Exception; lives_ok { package Role; diff --git a/t/402-attribute-application.t b/t/402-attribute-application.t index 136ffdc..fbb400d 100644 --- a/t/402-attribute-application.t +++ b/t/402-attribute-application.t @@ -2,7 +2,7 @@ use strict; use warnings; use Test::More tests => 11; -use t::Exception; +use Test::Exception; do { package Role; diff --git a/t/403-method-modifiers.t b/t/403-method-modifiers.t index 8daf21f..6c316b3 100644 --- a/t/403-method-modifiers.t +++ b/t/403-method-modifiers.t @@ -10,7 +10,7 @@ BEGIN { plan skip_all => "Class::Method::Modifiers required for this test"; } } -use t::Exception; +use Test::Exception; my @calls; my ($before, $after, $around); diff --git a/t/500_moose_extends_mouse.t b/t/500_moose_extends_mouse.t index 526d4a9..cb99d00 100644 --- a/t/500_moose_extends_mouse.t +++ b/t/500_moose_extends_mouse.t @@ -4,13 +4,13 @@ use strict; use warnings; use Test::More; -use t::Exception; +use Test::Exception; BEGIN { plan skip_all => "Moose required for this test" unless eval { require Moose && Moose->VERSION('0.59') }; plan tests => 27; } -use t::Exception; +use Test::Exception; { package Foo; diff --git a/t/501_moose_coerce_mouse.t b/t/501_moose_coerce_mouse.t index 68c420f..dc8edde 100644 --- a/t/501_moose_coerce_mouse.t +++ b/t/501_moose_coerce_mouse.t @@ -4,13 +4,13 @@ use strict; use warnings; use Test::More; -use t::Exception; +use Test::Exception; BEGIN { plan skip_all => "Moose required for this test" unless eval { require Moose && Moose->VERSION('0.59') }; plan tests => 5; } -use t::Exception; +use Test::Exception; { package Headers; diff --git a/t/800_shikabased/003-make_immutable.t b/t/800_shikabased/003-make_immutable.t index 111fb3d..189a5b2 100644 --- a/t/800_shikabased/003-make_immutable.t +++ b/t/800_shikabased/003-make_immutable.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More tests => 4; -use t::Exception; +use Test::Exception; { package HardDog; diff --git a/t/800_shikabased/004-immutable-demolish.t b/t/800_shikabased/004-immutable-demolish.t index 38917e7..0db7efe 100644 --- a/t/800_shikabased/004-immutable-demolish.t +++ b/t/800_shikabased/004-immutable-demolish.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More tests => 2; -use t::Exception; +use Test::Exception; my $i; diff --git a/t/Exception.pm b/t/Exception.pm deleted file mode 100644 index d984d29..0000000 --- a/t/Exception.pm +++ /dev/null @@ -1,67 +0,0 @@ -package t::Exception; -use strict; -use warnings; -use base qw/Exporter/; - -our @EXPORT = qw/throws_ok lives_ok/; - -my $Tester; - -my $is_exception = sub { - my $exception = shift; - return ref $exception || $exception ne ''; -}; - -my $exception_as_string = sub { - my ( $prefix, $exception ) = @_; - return "$prefix normal exit" unless $is_exception->( $exception ); - my $class = ref $exception; - $exception = "$class ($exception)" - if $class && "$exception" !~ m/^\Q$class/; - chomp $exception; - return "$prefix $exception"; -}; -my $try_as_caller = sub { - my $coderef = shift; - eval { $coderef->() }; - $@; -}; - -sub throws_ok (&$;$) { - my ( $coderef, $expecting, $description ) = @_; - Carp::croak "throws_ok: must pass exception class/object or regex" - unless defined $expecting; - $description = $exception_as_string->( "threw", $expecting ) - unless defined $description; - my $exception = $try_as_caller->($coderef); - - $Tester ||= Test::Builder->new; - - my $regex = $Tester->maybe_regex( $expecting ); - my $ok = $regex - ? ( $exception =~ m/$regex/ ) - : eval { - $exception->isa( ref $expecting ? ref $expecting : $expecting ) - }; - $Tester->ok( $ok, $description ); - unless ( $ok ) { - $Tester->diag( $exception_as_string->( "expecting:", $expecting ) ); - $Tester->diag( $exception_as_string->( "found:", $exception ) ); - }; - $@ = $exception; - return $ok; -} - -sub lives_ok (&;$) { - my ( $coderef, $description ) = @_; - my $exception = $try_as_caller->( $coderef ); - - $Tester ||= Test::Builder->new; - - my $ok = $Tester->ok( ! $is_exception->( $exception ), $description ); - $Tester->diag( $exception_as_string->( "died:", $exception ) ) unless $ok; - $@ = $exception; - return $ok; -} - -1;