1Test::Stream::Plugin::IUnsteerrcCeopntt(r3i)buted Perl DToecsutm:e:nSttarteiaomn::Plugin::Intercept(3)
2
3
4
6 Test::Stream::Plugin::Intercept - Tool for intercepting test events.
7
9 This distribution is deprecated in favor of Test2, Test2::Suite, and
10 Test2::Workflow.
11
12 See Test::Stream::Manual::ToTest2 for a conversion guide.
13
15 # Load the Intercept plugin, and others we need
16 use Test::Stream qw/Intercept Core Compare/;
17
18 my $events = intercept {
19 ok(1, 'foo');
20 ok(0, 'bar');
21 };
22
23 is(@$events, 2, "intercepted 2 events.");
24
25 isa_ok($events->[0], 'Test::Stream::Event::Ok');
26 ok($events->[0]->pass, "first event passed");
27
29 $events = intercept { ... }
30 This lets you intercept all events inside the codeblock. All the
31 events will be returned in an arrayref.
32
33 my $events = intercept {
34 ok(1, 'foo');
35 ok(0, 'bar');
36 };
37 is(@$events, 2, "intercepted 2 events.");
38
39 There are also 2 named parameters passed in, "context" and "hub".
40 The "context" passed in is a snapshot of the context for the
41 intercept() tool itself, referencing the parent hub. The "hub"
42 parameter is the new hub created for the "intercept" run.
43
44 my $events = intercept {
45 my %params = @_;
46
47 my $outer_ctx = $params{context};
48 my $our_hub = $params{hub};
49
50 ...
51 };
52
53 By default the hub used has "no_ending" set to true. This will
54 prevent the hub from enforcing that you issued a plan and ran at
55 least 1 test. You can turn enforcement back one like this:
56
57 my %params = @_;
58 $params{hub}->set_no_ending(0);
59
60 With "no_ending" turned off, "$hub-"finalize()> will run the post-
61 test checks to enforce the plan and that tests were run. In many
62 cases this will result in additional events in your events array.
63
64 Note: the $ENV{TS_TERM_SIZE} environment variable is set to 80
65 inside the intercept block. This is done to ensure consistency for
66 the block across machines and platforms. This is essential for
67 predictable testing of diagnostics, which may render tables or use
68 the terminal size to change behavior.
69
71 Test::Stream::Plugin::Grab - Similar tool, but allows you to intercept
72 events without adding stack frames.
73
75 The source code repository for Test::Stream can be found at
76 http://github.com/Test-More/Test-Stream/.
77
79 Chad Granum <exodist@cpan.org>
80
82 Chad Granum <exodist@cpan.org>
83
85 Copyright 2015 Chad Granum <exodist7@gmail.com>.
86
87 This program is free software; you can redistribute it and/or modify it
88 under the same terms as Perl itself.
89
90 See http://dev.perl.org/licenses/
91
92
93
94perl v5.36.0 2023-01-20Test::Stream::Plugin::Intercept(3)