This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Test-Simple to CPAN version 1.302073
[perl5.git] / cpan / Test-Simple / t / Test2 / modules / Event / Plan.t
CommitLineData
b4514920
CG
1use strict;
2use warnings;
3
a5ab2255 4use Test2::Tools::Tiny;
b4514920
CG
5use Test2::Event::Plan;
6use Test2::Util::Trace;
7
8my $plan = Test2::Event::Plan->new(
9 trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]),
10 max => 100,
11);
12
13is($plan->summary, "Plan is 100 assertions", "simple summary");
14is_deeply( [$plan->sets_plan], [100, '', undef], "Got plan details");
15
16ok(!$plan->global, "regular plan is not a global event");
17my $state = Test2::Hub->new;
18$plan->callback($state);
19is($state->plan, 100, "set plan in state");
20is($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);
27is($state->plan, 'SKIP', "set plan in state");
28is($plan->terminate, 0, "Terminate 0 on skip_all");
29
30is($plan->summary, "Plan is 'SKIP', foo", "skip summary");
31is_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);
36is($plan->summary, "Plan is 'NO PLAN'", "NO PLAN summary");
37is_deeply( [$plan->sets_plan], [0, 'NO PLAN', undef], "Got 'NO PLAN' details");
38$state = Test2::Hub->new;
39$plan->callback($state);
40is($state->plan, 'NO PLAN', "set plan in state");
41is($plan->terminate, undef, "No terminate for no_plan");
42$plan->set_max(100);
43$plan->set_directive(undef);
44$plan->callback($state);
45is($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);
52is($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);
59is($plan->directive, 'NO PLAN', "Change no_plan to 'NO PLAN'");
60ok(!$plan->global, "NO PLAN is not global");
61
62like(
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
74like(
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
86like(
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
96like(
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
107done_testing;