Add tests for new Chained strictures
[catagits/Catalyst-Runtime.git] / t / dead_load_bad_args.t
CommitLineData
dd97c1ac 1#!perl
2
3use strict;
4use warnings;
5use lib 't/lib';
6
7use Test::More;
8
dd97c1ac 9use Catalyst::Test 'TestApp';
10
11for my $fail (
12 "(' ')",
13 "('')",
14 "('1.23')",
15) {
08f8d85c 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} {}
dd97c1ac 21END
08f8d85c 22 ok(!$@);
dd97c1ac 23
08f8d85c 24 eval { TestApp->setup_actions };
25 like($@, qr/Invalid \Q${type}${fail}\E/,
26 "Bad ${type}${fail} attribute makes action setup fail");
27 }
dd97c1ac 28}
29
30for my $ok (
31 "()",
32 "(0)",
33 "(1)",
34 "('0')",
35 "",
36) {
08f8d85c 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} {}
42END
43 ok(!$@);
44 eval { TestApp->setup_actions };
45 ok(!$@, "${type}${ok} works");
46 }
47}
48
49for 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 {}
dd97c1ac 55END
08f8d85c 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 }
dd97c1ac 64}
08f8d85c 65
66done_testing();