diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-25 04:47:55 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-25 04:47:55 +0000 |
commit | 7e7ddbe33ca34359d711aee1e0ddebaeb40c2a18 (patch) | |
tree | 2a03e101e7b0302f5dcde62ed415a415ecca041d /t/013-errors.t | |
download | Class-Load-tarball-master.tar.gz |
Class-Load-0.23HEADClass-Load-0.23master
Diffstat (limited to 't/013-errors.t')
-rw-r--r-- | t/013-errors.t | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/t/013-errors.t b/t/013-errors.t new file mode 100644 index 0000000..38fd4a1 --- /dev/null +++ b/t/013-errors.t @@ -0,0 +1,123 @@ +use strict; +use warnings; + +use Test::More 0.88; + +use lib 't/lib'; +use Test::Class::Load ':all'; + +my $file = __FILE__; + +{ +# line 1 + eval { load_class('Class::NonExistent') }; + my $e = $@; + + unlike( + $e, + qr/at .+Load\.pm line \d+/, + 'load_class exception does not refer to Class::Load internals' + ); + + unlike( + $e, + qr/at .+Runtime\.pm line \d+/, + 'load_class exception does not refer to Module::Runtime internals' + ); + + like( + $e, + qr/Can't locate [^\n]+ at \Q$file\E line 1/, + 'error appears from the spot that called load_class' + ); +} + +{ + my ( $ok, $e ) = try_load_class('Class::NonExistent::Take2'); + + unlike( + $e, + qr/at .+Load\.pm line \d+/, + 'try_load_class exception does not refer to Class::Load internals' + ); + + unlike( + $e, + qr/at .+Runtime\.pm line \d+/, + 'try_load_class exception does not refer to Module::Runtime internals' + ); +} + +{ +# line 2 + eval { load_first_existing_class('Class::NonExistent::Take3') }; + my $e = $@; + + unlike( + $e, + qr/at .+Load\.pm line \d+/, + 'load_first_existing_class exception does not refer to Class::Load internals' + ); + + unlike( + $e, + qr/at .+Runtime\.pm line \d+/, + 'load_first_existing_class exception does not refer to Module::Runtime internals' + ); + + like( + $e, + qr/Can't locate [^\n]+ at \Q$file\E line 2/, + 'error appears from the spot that called load_first_existing_class' + ); +} + +{ +# line 3 + eval { load_first_existing_class('Class::Load::SyntaxError') }; + my $e = $@; + + unlike( + $e, + qr/at .+Load\.pm line \d+/, + 'load_first_existing_class exception does not refer to Class::Load internals' + ); + + unlike( + $e, + qr/at .+Runtime\.pm line \d+/, + 'load_first_existing_class exception does not refer to Module::Runtime internals' + ); + + like( + $e, + qr/Compilation failed .+? at \Q$file\E line 3/s, + 'error appears from the spot that called load_first_existing_class' + ); +} + +{ +# line 4 + eval { load_optional_class('Class::Load::SyntaxError') }; + my $e = $@; + + unlike( + $e, + qr/at .+Load\.pm line \d+/, + 'load_optional_class exception does not refer to Class::Load internals' + ); + + unlike( + $e, + qr/at .+Runtime\.pm line \d+/, + 'load_optional_class exception does not refer to Module::Runtime internals' + ); + + like( + $e, + qr/Compilation failed .+? at \Q$file\E line 4/s, + 'error appears from the spot that called load_optional_class' + ); +} + +done_testing(); |