5 no warnings 'redefine';
8 use lib "$FindBin::Bin/lib";
12 use Catalyst::Test 'TestApp';
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', @_) };
19 local *TestApp::debug = sub { 0 };
21 is $get->('foo'), 'Bad Request', 'detected action signature error';
22 is $subget->('foo'), 'Bad Request', 'detected action signature error (child)';
23 is $modget->('foo'), 'Bad Request', 'detected action signature error (modified)';
27 like $get->('bar'), qr/come back later/i, 'normal handling of method validation error';
29 } qr/Validation failed/, 'method error throws validation error to error log';
33 like $subget->('bar'), qr/come back later/i, 'normal handling of method validation error (child)';
35 } qr/Validation failed/, 'method error throws validation error to error log (child)';
39 like $modget->('bar'), qr/come back later/i, 'normal handling of method validation error (modified)';
41 } qr/Validation failed/, 'method error throws validation error to error log (modified)';
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)';
48 local *TestApp::debug = sub { 1 };
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';
56 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message';
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)';
64 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (child)';
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)';
72 } qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (modified)';
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';
80 } qr/Validation failed/i, 'error message reaches stdout';
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)';
88 } qr/Validation failed/i, 'error message reaches stdout (child)';
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)';
96 } qr/Validation failed/i, 'error message reaches stdout (modified)';
100 is $get->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode';
102 } qr/\[error\]/i, 'no errors in output';
106 is $subget->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode (child)';
108 } qr/\[error\]/i, 'no errors in output (child)';
112 is $modget->('baz'), 'FOO_MODIFY BAR', 'make sure all works without any errors happening in debug mode (modified)';
114 } qr/\[error\]/i, 'no errors in output (modified)';