canged prereq for D:D to ensure fix of method call issue
[catagits/CatalystX-Declare.git] / t / 060_exception_handling.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 no warnings 'redefine';
6
7 use FindBin;
8 use lib "$FindBin::Bin/lib";
9
10 use Test::More; 
11 use Test::Output;
12 use Catalyst::Test 'TestApp';
13
14 my $get    = sub { get(join '/', '/errors/signature_error_on_foo', @_) };
15 my $subget = sub { get(join '/', '/sub_errors/signature_error_on_foo', @_) };
16 my $modget = sub { get(join '/', '/sub_errors/signature_error_on_foo_modify', @_) };
17
18
19 local *TestApp::debug = sub { 0 };
20
21 is $get->('foo'),       'Not found', 'detected action signature error';
22 is $subget->('foo'),    'Not found', 'detected action signature error (child)';
23 is $modget->('foo'),    'Not found', 'detected action signature error (modified)';
24
25 stderr_like {
26
27     like $get->('bar'),     qr/come back later/i, 'normal handling of method validation error';
28
29 } qr/Validation failed/, 'method error throws validation error to error log';
30
31 stderr_like {
32
33     like $subget->('bar'),  qr/come back later/i, 'normal handling of method validation error (child)';
34
35 } qr/Validation failed/, 'method error throws validation error to error log (child)';
36
37 stderr_like {
38
39     like $modget->('bar'),  qr/come back later/i, 'normal handling of method validation error (modified)';
40
41 } qr/Validation failed/, 'method error throws validation error to error log (modified)';
42
43 is $get->('baz'),       'FOO BAR', 'make sure all works without any errors happening';
44 is $subget->('baz'),    'FOO BAR', 'make sure all works without any errors happening (child)';
45 is $modget->('baz'),    'FOO_MODIFY BAR', 'make sure all works without any errors happening (child)';
46
47
48 local *TestApp::debug = sub { 1 };
49
50 stderr_like {
51
52     my $foo_err = $get->('foo');
53     like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error';
54     like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message';
55
56 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message';
57
58 stderr_like {
59
60     my $foo_err = $subget->('foo');
61     like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error (child)';
62     like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message (child)';
63
64 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (child)';
65
66 stderr_like {
67
68     my $foo_err = $modget->('foo');
69     like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error (modified)';
70     like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message (modified)';
71
72 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (modified)';
73
74 stderr_like {
75
76     my $bar_err = $get->('bar');
77     unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note';
78     like $bar_err, qr/Validation failed/i, 'we got the right error message';
79
80 } qr/Validation failed/i, 'error message reaches stdout';
81
82 stderr_like {
83
84     my $bar_err = $subget->('bar');
85     unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note (child)';
86     like $bar_err, qr/Validation failed/i, 'we got the right error message (child)';
87
88 } qr/Validation failed/i, 'error message reaches stdout (child)';
89
90 stderr_like {
91
92     my $bar_err = $modget->('bar');
93     unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note (modified)';
94     like $bar_err, qr/Validation failed/i, 'we got the right error message (modified)';
95
96 } qr/Validation failed/i, 'error message reaches stdout (modified)';
97
98 stderr_unlike {
99
100     is $get->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode';
101
102 } qr/\[error\]/i, 'no errors in output';
103
104 stderr_unlike {
105
106     is $subget->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode (child)';
107
108 } qr/\[error\]/i, 'no errors in output (child)';
109
110 stderr_unlike {
111
112     is $modget->('baz'), 'FOO_MODIFY BAR', 'make sure all works without any errors happening in debug mode (modified)';
113
114 } qr/\[error\]/i, 'no errors in output (modified)';
115
116
117 done_testing;