File: 07-status_messages.t

package info (click to toggle)
libhttp-exception-perl 0.04001-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 284 kB
  • sloc: perl: 297; makefile: 2
file content (67 lines) | stat: -rwxr-xr-x 3,129 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
use strict;

use Test::More;
use HTTP::Exception;

# double checking synonym for status_message and message

my $e = HTTP::Exception->new(404, status_message => 'Nothing here');
is  $e->status_message, 'Nothing here', 'status message with H::E + new ';
is  $e->message,        'Nothing here', 'message with H::E + new ';

my $e1 = HTTP::Exception->new(404, message => 'Nothing here');
is  $e1->status_message, 'Nothing here', 'status message with H::E + new ';
is  $e1->message,        'Nothing here', 'message with H::E + new ';

my $e2 = HTTP::Exception::404->new(status_message => 'Nothing here');
is  $e2->status_message, 'Nothing here', 'status message with H::E::404 + new';
is  $e2->message,        'Nothing here', 'message with H::E::404 + new';

my $e21 = HTTP::Exception::404->new(message => 'Nothing here');
is  $e21->status_message, 'Nothing here', 'status message with H::E::404 + new';
is  $e21->message,        'Nothing here', 'message with H::E::404 + new';

my $e3 = HTTP::Exception::NOT_FOUND->new(status_message => 'Nothing here');
is  $e3->status_message, 'Nothing here', 'status message with H::E::NOT_FOUND + new';
is  $e3->message,        'Nothing here', 'message with H::E::NOT_FOUND + new';

my $e31 = HTTP::Exception::NOT_FOUND->new(message => 'Nothing here');
is  $e31->status_message, 'Nothing here', 'status message with H::E::NOT_FOUND + new';
is  $e31->message,        'Nothing here', 'message with H::E::NOT_FOUND + new';

my $e4 = HTTP::Exception::404->new();
$e4->status_message('Nothing here too');
is $e4->status_message, 'Nothing here too', 'status_message set after ->new';
is $e4->message,        'Nothing here too', 'message set after ->new';
$e4->message('Nothing here');
is $e4->status_message, 'Nothing here', 'status_message set after ->new';
is $e4->message,        'Nothing here', 'message set after ->new';

my @tests = (
    sub { $e4->throw;                                                          },
    sub { HTTP::Exception->throw(404, status_message => 'Nothing here');       },
    sub { HTTP::Exception::404->throw(status_message => 'Nothing here');       },
    sub { HTTP::Exception::NOT_FOUND->throw(status_message => 'Nothing here'); },
    sub { HTTP::Exception->throw(404, message => 'Nothing here');       },
    sub { HTTP::Exception::404->throw(message => 'Nothing here');       },
    sub { HTTP::Exception::NOT_FOUND->throw(message => 'Nothing here'); },
);

for my $test (@tests) {
    eval { $test->() };
    my $e5 = HTTP::Exception->caught;
    my $e6 = HTTP::Exception::4XX->caught;
    my $e7 = HTTP::Exception::404->caught;
    my $e8 = HTTP::Exception::NOT_FOUND->caught;
    my $e9 = Exception::Class->caught;

    for my $accessor (qw~status_message message~) {
        is  $e5->$accessor, 'Nothing here', "$accessor with H::E";
        is  $e6->$accessor, 'Nothing here', "$accessor with H::E::4XX";
        is  $e7->$accessor, 'Nothing here', "$accessor with H::E::404";
        is  $e8->$accessor, 'Nothing here', "$accessor with H::E::NOT_FOUND";
        is  $e9->$accessor, 'Nothing here', "$accessor with Exception::Class";
    }
}

done_testing;