Commit | Line | Data |
---|---|---|
b4514920 CG |
1 | use strict; |
2 | use warnings; | |
3 | ||
a5ab2255 | 4 | use Test2::Tools::Tiny; |
b4514920 CG |
5 | use Test2::Event::Plan; |
6 | use Test2::Util::Trace; | |
7 | ||
8 | my $plan = Test2::Event::Plan->new( | |
9 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
10 | max => 100, | |
11 | ); | |
12 | ||
13 | is($plan->summary, "Plan is 100 assertions", "simple summary"); | |
14 | is_deeply( [$plan->sets_plan], [100, '', undef], "Got plan details"); | |
15 | ||
16 | ok(!$plan->global, "regular plan is not a global event"); | |
17 | my $state = Test2::Hub->new; | |
18 | $plan->callback($state); | |
19 | is($state->plan, 100, "set plan in state"); | |
20 | is($plan->terminate, undef, "No terminate for normal plan"); | |
21 | ||
22 | $plan->set_max(0); | |
23 | $plan->set_directive('SKIP'); | |
24 | $plan->set_reason('foo'); | |
25 | $state = Test2::Hub->new; | |
26 | $plan->callback($state); | |
27 | is($state->plan, 'SKIP', "set plan in state"); | |
28 | is($plan->terminate, 0, "Terminate 0 on skip_all"); | |
29 | ||
30 | is($plan->summary, "Plan is 'SKIP', foo", "skip summary"); | |
31 | is_deeply( [$plan->sets_plan], [0, 'SKIP', 'foo'], "Got skip details"); | |
32 | ||
33 | $plan->set_max(0); | |
34 | $plan->set_directive('NO PLAN'); | |
35 | $plan->set_reason(undef); | |
36 | is($plan->summary, "Plan is 'NO PLAN'", "NO PLAN summary"); | |
37 | is_deeply( [$plan->sets_plan], [0, 'NO PLAN', undef], "Got 'NO PLAN' details"); | |
38 | $state = Test2::Hub->new; | |
39 | $plan->callback($state); | |
40 | is($state->plan, 'NO PLAN', "set plan in state"); | |
41 | is($plan->terminate, undef, "No terminate for no_plan"); | |
42 | $plan->set_max(100); | |
43 | $plan->set_directive(undef); | |
44 | $plan->callback($state); | |
45 | is($state->plan, '100', "Update plan in state if it is 'NO PLAN'"); | |
46 | ||
47 | $plan = Test2::Event::Plan->new( | |
48 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
49 | max => 0, | |
50 | directive => 'skip_all', | |
51 | ); | |
52 | is($plan->directive, 'SKIP', "Change skip_all to SKIP"); | |
53 | ||
54 | $plan = Test2::Event::Plan->new( | |
55 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
56 | max => 0, | |
57 | directive => 'no_plan', | |
58 | ); | |
59 | is($plan->directive, 'NO PLAN', "Change no_plan to 'NO PLAN'"); | |
60 | ok(!$plan->global, "NO PLAN is not global"); | |
61 | ||
62 | like( | |
63 | exception { | |
64 | $plan = Test2::Event::Plan->new( | |
65 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
66 | max => 0, | |
67 | directive => 'foo', | |
68 | ); | |
69 | }, | |
70 | qr/'foo' is not a valid plan directive/, | |
71 | "Invalid Directive" | |
72 | ); | |
73 | ||
74 | like( | |
75 | exception { | |
76 | $plan = Test2::Event::Plan->new( | |
77 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
78 | max => 0, | |
79 | reason => 'foo', | |
80 | ); | |
81 | }, | |
82 | qr/Cannot have a reason without a directive!/, | |
83 | "Reason without directive" | |
84 | ); | |
85 | ||
86 | like( | |
87 | exception { | |
88 | $plan = Test2::Event::Plan->new( | |
89 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
90 | ); | |
91 | }, | |
92 | qr/No number of tests specified/, | |
93 | "Nothing to do" | |
94 | ); | |
95 | ||
96 | like( | |
97 | exception { | |
98 | $plan = Test2::Event::Plan->new( | |
99 | trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]), | |
100 | max => 'skip', | |
101 | ); | |
102 | }, | |
103 | qr/Plan test count 'skip' does not appear to be a valid positive integer/, | |
104 | "Max must be an integer" | |
105 | ); | |
106 | ||
107 | done_testing; |