summaryrefslogtreecommitdiff
path: root/systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm
diff options
context:
space:
mode:
Diffstat (limited to 'systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm')
-rwxr-xr-xsystems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm64
1 files changed, 24 insertions, 40 deletions
diff --git a/systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm b/systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm
index 6c517415bd..6c663468ab 100755
--- a/systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm
+++ b/systems/texlive/tlnet/tlpkg/tlperl/lib/Test2/API.pm
@@ -9,7 +9,7 @@ BEGIN {
$ENV{TEST2_ACTIVE} = 1;
}
-our $VERSION = '1.302175';
+our $VERSION = '1.302183';
my $INST;
@@ -404,10 +404,10 @@ sub context {
my $end_phase = $ENDING || $phase eq 'END' || $phase eq 'DESTRUCT';
my $level = 1 + $params{level};
- my ($pkg, $file, $line, $sub) = $end_phase ? caller(0) : caller($level);
+ my ($pkg, $file, $line, $sub, @other) = $end_phase ? caller(0) : caller($level);
unless ($pkg || $end_phase) {
confess "Could not find context at depth $level" unless $params{fudge};
- ($pkg, $file, $line, $sub) = caller(--$level) while ($level >= 0 && !$pkg);
+ ($pkg, $file, $line, $sub, @other) = caller(--$level) while ($level >= 0 && !$pkg);
}
my $depth = $level;
@@ -460,6 +460,8 @@ sub context {
nested => $hub->{nested},
buffered => $hub->{buffered},
+ full_caller => [$pkg, $file, $line, $sub, @other],
+
$$UUID_VIA ? (
huuid => $hub->{uuid},
uuid => ${$UUID_VIA}->('context'),
@@ -595,6 +597,10 @@ sub _intercept {
$ctx->stack->top; # Make sure there is a top hub before we begin.
$ctx->stack->push($hub);
+ my $trace = $ctx->trace;
+ my $state = {};
+ $hub->clean_inherited(trace => $trace, state => $state);
+
my ($ok, $err) = (1, undef);
T2_SUBTEST_WRAPPER: {
# Do not use 'try' cause it localizes __DIE__
@@ -611,7 +617,8 @@ sub _intercept {
$hub->cull;
$ctx->stack->pop($hub);
- my $trace = $ctx->trace;
+ $hub->restore_inherited(trace => $trace, state => $state);
+
$ctx->release;
die $err unless $ok;
@@ -621,7 +628,8 @@ sub _intercept {
&& !$hub->no_ending
&& !$hub->ended;
- return \@events;
+ require Test2::API::InterceptResult;
+ return Test2::API::InterceptResult->new_from_ref(\@events);
}
sub run_subtest {
@@ -841,38 +849,9 @@ generated by the test system:
my_ok(0, "fail");
};
- my_ok(@$events == 2, "got 2 events, the pass and the fail");
- my_ok($events->[0]->pass, "first event passed");
- my_ok(!$events->[1]->pass, "second event failed");
-
-=head3 DEEP EVENT INTERCEPTION
-
-Normally C<intercept { ... }> only intercepts events sent to the main hub (as
-added by intercept itself). Nested hubs, such as those created by subtests,
-will not be intercepted. This is normally what you will still see the nested
-events by inspecting the subtest event. However there are times where you want
-to verify each event as it is sent, in that case use C<intercept_deep { ... }>.
-
- my $events = intercept_Deep {
- buffered_subtest foo => sub {
- ok(1, "pass");
- };
- };
-
-C<$events> in this case will contain 3 items:
-
-=over 4
-
-=item The event from C<ok(1, "pass")>
-
-=item The plan event for the subtest
-
-=item The subtest event itself, with the first 2 events nested inside it as children.
-
-=back
-
-This lets you see the order in which the events were sent, unlike
-C<intercept { ... }> which only lets you see events as the main hub sees them.
+As of version 1.302178 this now returns an arrayref that is also an instance of
+L<Test2::API::InterceptResult>. See the L<Test2::API::InterceptResult>
+documentation for details on how to best use it.
=head2 OTHER API FUNCTIONS
@@ -1161,8 +1140,13 @@ It will execute the codeblock, intercepting any generated events in the
process. It will return an array reference with all the generated event
objects. All events should be subclasses of L<Test2::Event>.
-This is a very low-level subtest tool. This is useful for writing tools which
-produce subtests. This is not intended for people simply writing tests.
+As of version 1.302178 the events array that is returned is blssed as an
+L<Test2::API::InterceptResult> instance. L<Test2::API::InterceptResult>
+Provides a helpful interface for filtering and/or inspecting the events list
+overall, or individual events within the list.
+
+This is intended to help you test your test code. This is not intended for
+people simply writing tests.
=head2 run_subtest(...)
@@ -1679,7 +1663,7 @@ F<http://github.com/Test-More/test-more/>.
=head1 COPYRIGHT
-Copyright 2019 Chad Granum E<lt>exodist@cpan.orgE<gt>.
+Copyright 2020 Chad Granum E<lt>exodist@cpan.orgE<gt>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.