File: 50_Class_Throwable_retrofit_test.t

package info (click to toggle)
libclass-throwable-perl 0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 108 kB
  • ctags: 20
  • sloc: perl: 447; makefile: 43
file content (54 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl

use strict;
use warnings;

use Test::More no_plan => 1;

BEGIN {
    use_ok('Class::Throwable' => (
                'InsufficientArguments'
                ));
    use_ok('Class::Throwable' => (
                retrofit => 'My::Test::Package'
                ));
    use_ok('Class::Throwable' => (
                retrofit => 'My::Other::Test::Package' => sub {
                    if ($_[0] =~ /Insufficient Arguments/) {
                        InsufficientArguments->throw(@_);                    
                    }
                    else {
                        Class::Throwable->throw(@_);
                    }
                }
                ));                
}

{
    package My::Test::Package;
    sub test { die 'This will be a Class::Throwable exeception' }

    package My::Other::Test::Package;
    sub test { die 'Insufficient Arguments : This will be a InsufficientArguments exeception' }
    sub other_test { die 'This will be a Class::Throwable exeception' }    
}

eval { My::Test::Package::test() };
isa_ok($@, 'Class::Throwable');
is($@->getMessage(), 'This will be a Class::Throwable exeception', '... got the right message too');

eval { My::Other::Test::Package::test() };
isa_ok($@, 'InsufficientArguments');
isa_ok($@, 'Class::Throwable');

is($@->getMessage(), 'Insufficient Arguments : This will be a InsufficientArguments exeception', '... got the right message too');

eval { My::Other::Test::Package::other_test() };
isa_ok($@, 'Class::Throwable');
is($@->getMessage(), 'This will be a Class::Throwable exeception', '... got the right message too');

eval "use Class::Throwable 'retrofit';";
like($@, 
    qr/You must specify a module for Class\:\:Throwable to retrofit/, 
    '... got the exception we expected');