1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
use strict;
use warnings;
use Test2::Tools::Tiny;
use Test2::Hub::Subtest;
use Test2::Util qw/get_tid/;
use Carp qw/croak/;
my %TODO;
sub def {
my ($func, @args) = @_;
my @caller = caller(0);
$TODO{$caller[0]} ||= [];
push @{$TODO{$caller[0]}} => [$func, \@args, \@caller];
}
sub do_def {
my $for = caller;
my $tests = delete $TODO{$for} or croak "No tests to run!";
for my $test (@$tests) {
my ($func, $args, $caller) = @$test;
my ($pkg, $file, $line) = @$caller;
# Note: The '&' below is to bypass the prototype, which is important here.
eval <<" EOT" or die $@;
package $pkg;
# line $line "(eval in DeferredTests) $file"
\&$func(\@\$args);
1;
EOT
}
}
my $ran = 0;
my $event;
my $one = Test2::Hub::Subtest->new(
nested => 3,
);
ok($one->isa('Test2::Hub'), "inheritence");
{
no warnings 'redefine';
local *Test2::Hub::process = sub { $ran++; (undef, $event) = @_; 'P!' };
use warnings;
my $ok = Test2::Event::Ok->new(
pass => 1,
name => 'blah',
trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__, 'xxx']),
);
def is => ($one->process($ok), 'P!', "processed");
def is => ($ran, 1, "ran the mocked process");
def is => ($event, $ok, "got our event");
def is => ($event->nested, 3, "nested was set");
def is => ($one->bailed_out, undef, "did not bail");
$ran = 0;
$event = undef;
my $bail = Test2::Event::Bail->new(
message => 'blah',
trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__, 'xxx']),
);
def is => ($one->process($bail), 'P!', "processed");
def is => ($ran, 1, "ran the mocked process");
def is => ($event, $bail, "got our event");
def is => ($event->nested, 3, "nested was set");
def is => ($one->bailed_out, $event, "bailed");
}
do_def;
my $skip = Test2::Event::Plan->new(
trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__], pid => $$, tid => get_tid),
directive => 'SKIP',
reason => 'foo',
);
$ran = 0;
T2_SUBTEST_WRAPPER: {
$ran++;
$one->terminate(100, $skip);
$ran++;
}
is($ran, 1, "did not get past the terminate");
$ran = 0;
T2_SUBTEST_WRAPPER: {
$ran++;
$one->send($skip);
$ran++;
}
is($ran, 1, "did not get past the terminate");
$one->reset_state;
$one->set_manual_skip_all(1);
$ran = 0;
T2_SUBTEST_WRAPPER: {
$ran++;
$one->terminate(100, $skip);
$ran++;
}
is($ran, 2, "did not automatically abort");
$one->reset_state;
$ran = 0;
T2_SUBTEST_WRAPPER: {
$ran++;
$one->send($skip);
$ran++;
}
is($ran, 2, "did not automatically abort");
done_testing;
|