/
07-errors.t
73 lines (60 loc) · 2.5 KB
/
07-errors.t
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
68
69
70
71
72
73
use v6.c;
use Test;
use Bailador;
use Bailador::Test;
plan 6;
get '/die' => sub { die "oh no!" }
get '/fail' => sub { fail "hell froze!" }
get '/exception' => sub { X::NYI.new(feature => 'NYI').throw }
# Call baile just once
my $p6w-app = baile('p6w');
subtest {
plan 2;
my %data = run-psgi-request($p6w-app, 'GET', '/die');
is-deeply %data<response>, [500, ["Content-Type" => "text/plain;charset=UTF-8"], 'Internal Server Error'], 'route GET handles die';
like %data<err>, rx:s/oh no\!/, 'stderr';
};
subtest {
plan 2;
my %data = run-psgi-request($p6w-app, 'GET', '/fail');
is-deeply %data<response>, [500, ["Content-Type" => "text/plain;charset=UTF-8"], 'Internal Server Error'], 'route GET handles fail';
like %data<err>, rx:s/hell froze\!/, 'stderr';
};
subtest {
plan 2;
my %data = run-psgi-request($p6w-app, 'GET', '/exception');
is-deeply %data<response>, [500, ["Content-Type" => "text/plain;charset=UTF-8"], 'Internal Server Error'], 'route GET handles thrown exception';
like %data<err>, rx:s/NYI not yet implemented\. Sorry\./, 'stderr';
};
subtest {
plan 3;
config.mode = 'development';
my %data = run-psgi-request($p6w-app, 'GET', '/die');
my $html = %data<response>[2];
like $html, rx:s/In the future this will be a nice error page\. For now we try to make it at least informative\./;
%data<response>[2] = '';
is-deeply %data<response>, [500, ["Content-Type" => "text/html;charset=UTF-8"], ''], 'route GET handles die';
like %data<err>, rx:s/oh no\!/, 'stderr';
}
subtest {
plan 3;
config.mode = 'development';
my %data = run-psgi-request($p6w-app, 'GET', '/fail');
my $html = %data<response>[2];
like $html, rx:s/In the future this will be a nice error page\. For now we try to make it at least informative\./;
%data<response>[2] = '';
is-deeply %data<response>, [500, ["Content-Type" => "text/html;charset=UTF-8"], ''], 'route GET handles die';
like %data<err>, rx:s/hell froze\!/, 'stderr';
}
subtest {
plan 3;
config.mode = 'development';
my %data = run-psgi-request($p6w-app, 'GET', '/exception');
my $html = %data<response>[2];
like $html, rx:s/In the future this will be a nice error page\. For now we try to make it at least informative\./;
%data<response>[2] = '';
is-deeply %data<response>, [500, ["Content-Type" => "text/html;charset=UTF-8"], ''], 'route GET handles die';
like %data<err>, rx:s/NYI not yet implemented\. Sorry\./, 'stderr';
}
# vim: expandtab
# vim: tabstop=4