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
|
use strict;
use warnings;
use Test2::Tools::Tiny;
use Test2::API qw/run_subtest intercept context/;
# Test a subtest that should inherit the trace from the tool that calls it
my ($file, $line) = (__FILE__, __LINE__ + 1);
my $events = intercept { my_tool_inherit() };
is(@$events, 1, "got 1 event");
my $e = shift @$events;
ok($e->isa('Test2::Event::Subtest'), "got a subtest event");
is($e->trace->file, $file, "subtest is at correct file");
is($e->trace->line, $line, "subtest is at correct line");
my $plan = pop @{$e->subevents};
ok($plan->isa('Test2::Event::Plan'), "Removed plan");
for my $se (@{$e->subevents}) {
is($se->trace->file, $file, "subtest event is at correct file");
is($se->trace->line, $line, "subtest event is at correct line");
ok($se->facets->{assert}->pass, "subtest event passed");
}
# Test a subtest that should NOT inherit the trace from the tool that calls it
($file, $line) = (__FILE__, __LINE__ + 1);
$events = intercept { my_tool_no_inherit() };
is(@$events, 1, "got 1 event");
$e = shift @$events;
ok($e->isa('Test2::Event::Subtest'), "got a subtest event");
is($e->trace->file, $file, "subtest is at correct file");
is($e->trace->line, $line, "subtest is at correct line");
$plan = pop @{$e->subevents};
ok($plan->isa('Test2::Event::Plan'), "Removed plan");
for my $se (@{$e->subevents}) {
ok($se->trace->file ne $file, "subtest event is not in our file");
ok($se->trace->line ne $line, "subtest event is not on our line");
ok($se->facets->{assert}->{pass}, "subtest event passed");
}
done_testing;
# Make these tools appear to be in a different file/line
#line 100 'fake.pm'
sub my_tool_inherit {
my $ctx = context();
run_subtest(
'foo',
sub {
ok(1, 'a');
ok(2, 'b');
is_deeply(\@_, [qw/arg1 arg2/], "got args");
},
{buffered => 1, inherit_trace => 1},
'arg1', 'arg2'
);
$ctx->release;
}
sub my_tool_no_inherit {
my $ctx = context();
run_subtest(
'foo',
sub {
ok(1, 'a');
ok(2, 'b');
is_deeply(\@_, [qw/arg1 arg2/], "got args");
},
{buffered => 1, inherit_trace => 0},
'arg1', 'arg2'
);
$ctx->release;
}
|