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