Test::S...ntercept(3)

πŸ“¦
version 1.302027 Β· 2 versions
, in fedora 43

✨ 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 context you get is a snapshot of the context for the intercept() tool itself, and it references the parent hub.
  • The hub parameter is the brand new hub created for the intercept run. 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: with no_ending turned 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 to 80 inside 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 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