reluctantlt move setup_trace before setup_plugins (we want it for use in plugins)
[catagits/Catalyst-Runtime.git] / t / dead_load_bad_args.t
1 use strict;
2 use warnings;
3 use lib 't/lib';
4
5 use Test::More;
6
7 use Catalyst::Test 'TestApp';
8
9 for my $fail (
10     "(' ')",
11     "('')",
12     "('1.23')",
13     "(-1)",
14 ) {
15     for my $type (qw(Args CaptureArgs)) {
16         eval <<"END";
17             package TestApp::Controller::Action::Chained;
18             no warnings 'redefine';
19             sub should_fail : Chained('/') ${type}${fail} {}
20 END
21         ok(!$@);
22
23         eval { TestApp->setup_actions };
24         like($@, qr/Invalid \Q${type}${fail}\E/,
25              "Bad ${type}${fail} attribute makes action setup fail");
26     }
27 }
28
29 for my $ok (
30     "()",
31     "(0)",
32     "(1)",
33     "('0')",
34     "",
35 ) {
36     for my $type (qw(Args CaptureArgs)) {
37         eval <<"END";
38             package TestApp::Controller::Action::Chained;
39             no warnings 'redefine';
40             sub should_fail : Chained('/') ${type}${ok} {}
41 END
42         ok(!$@);
43         eval { TestApp->setup_actions };
44         ok(!$@, "${type}${ok} works");
45     }
46 }
47
48 for my $first (qw(Args CaptureArgs)) {
49     for my $second (qw(Args CaptureArgs)) {
50         eval <<"END";
51             package TestApp::Controller::Action::Chained;
52             no warnings 'redefine';
53             sub should_fail :Chained('/') $first $second {}
54 END
55         ok(!$@);
56         eval { TestApp->setup_actions };
57         my $msg = $first eq $second
58            ? "Multiple $first"
59            : "Combining Args and CaptureArgs";
60         like($@, qr/$msg attributes not supported registering/,
61              "$first + $second attribute makes action setup fail");
62     }
63 }
64
65 done_testing();