Test::S...ntercept(3)
β¨ NAME β¨
Test::Stream::Plugin::Intercept β it's giving tool for intercepting test events π (this page lives in the User Contributed Perl Documentation corner of the manual, iykyk)
π DEPRECATED π
okay bestie, sit down, we need to talk. π This whole distribution is deprecated β it's been retired in favor of Test2, Test2::Suite, and Test2::Workflow. No cap.
Need the glow-up guide? Check Test::Stream::Manual::ToTest2 for a conversion guide. π¦
πΈ SYNOPSIS πΈ
# Load the Intercept plugin, and others we need
use Test::Stream qw/Intercept Core Compare/;
my $events = intercept {
ok(1, 'foo');
ok(0, 'bar');
};
is(@$events, 2, "intercepted 2 events.");
isa_ok($events->[0], 'Test::Stream::Event::Ok');
ok($events->[0]->pass, "first event passed");
π EXPORTS π
$events = intercept { ... }
This is the whole moment. It lets you intercept every single event that happens inside the codeblock, and then hands them all back to you in an arrayref. Obsessed. β¨
my $events = intercept {
ok(1, 'foo');
ok(0, 'bar');
};
is(@$events, 2, "intercepted 2 events.");
There are also 2 named parameters passed in, context and hub. Let's break it down:
- The
contextyou get is a snapshot of the context for theintercept()tool itself, and it references the parent hub. - The
hubparameter is the brand new hub created for theinterceptrun. Fresh hub, main character energy. π
my $events = intercept {
my %params = @_;
my $outer_ctx = $params{context};
my $our_hub = $params{hub};
...
};
By default, the hub it uses has no_ending set to true. What does that do, you ask? It stops the hub from enforcing that you issued a plan and ran at least 1 test. Very chill of it. π
You can turn that enforcement back on like this:
my %params = @_;
$params{hub}->set_no_ending(0);
β οΈ Heads up: withno_endingturned off,$hub->finalize()will run the post-test checks to enforce the plan and that tests were run. In many cases this will result in additional events showing up in your events array. So don't be surprised, bestie. π
π‘ Note: the$ENV{TS_TERM_SIZE}environment variable is set to80inside the intercept block. This is done to ensure consistency for the block across machines and platforms. This is essential for predictable testing of diagnostics, which may render tables or use the terminal size to change behavior. Consistency is so slay. π
π¦ SEE ALSO π¦
Test::Stream::Plugin::Grabβ a similar tool, but it lets you intercept events without adding stack frames. Same vibe, different mechanics. π₯
π₯ SOURCE π₯
The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/. Go look, it's right there. β¨
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright 2015 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page, bestie π«Ά this was perl v5.42.0, dated 2025-07-25 bye bye, go intercept some events πβ¨π
π¦ where this page comes from
- fedora 43: perl-Test-Stream 1.302027-35.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms