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
|
use strict;
use warnings;
use B;
use Test::Stream;
use Test::MostlyLike;
use Test::More tests => 8;
use Test::Builder; # Not loaded by default in modern mode
my $orig = Test::Builder->can('plan');
use Test::Stream::Tester;
my $ran = 0;
no warnings 'redefine';
my $file = __FILE__;
my $line = __LINE__ + 1;
*Test::Builder::plan = sub { my $self = shift; $ran++; $self->$orig(@_) };
use warnings;
my @warnings;
$SIG{__WARN__} = sub { push @warnings => @_ };
events_are(
intercept {
plan tests => 2;
ok(1, "pass");
ok(0, "fail");
},
check {
event plan => { max => 2 };
event ok => { bool => 1 };
event ok => { bool => 0 };
directive 'end';
},
);
events_are(
intercept {
Test::More->import('tests' => 2);
ok(1, "pass");
ok(0, "fail");
},
check {
event plan => { max => 2 };
event ok => { bool => 1 };
event ok => { bool => 0 };
directive 'end';
},
);
events_are(
intercept {
Test::More->import(skip_all => 'damn');
ok(1, "pass");
ok(0, "fail");
},
check {
event plan => { max => 0, directive => 'SKIP', reason => 'damn' };
directive 'end';
},
);
events_are(
intercept {
Test::More->import('no_plan');
ok(1, "pass");
ok(0, "fail");
},
check {
event plan => { directive => 'NO PLAN' };
event ok => { bool => 1 };
event ok => { bool => 0 };
directive 'end';
},
);
is($ran, 4, "We ran our override each time");
mostly_like(
\@warnings,
[
qr{The new sub is 'main::__ANON__' defined in \Q$file\E around line $line},
undef,
],
"Got the warning once"
);
no warnings 'redefine';
*Test::Builder::plan = sub { };
use warnings;
my $ok;
events_are(
intercept {
$ok = eval {
plan(tests => 1);
plan(tests => 2);
ok(1);
ok(1);
ok(1);
done_testing;
1;
};
},
check {
event ok => { bool => 1 };
event ok => { bool => 1 };
event ok => { bool => 1 };
event plan => { max => 3 };
directive 'end';
},
"Make sure plan monkeypatching does not effect done_testing"
);
ok($ok, "Did not die");
|