1Test2::Tools::Tester(3)User Contributed Perl DocumentatioTnest2::Tools::Tester(3)
2
3
4
6 Test2::Tools::Tester - Tools to help you test other testing tools.
7
9 This is a collection of tools that are useful when testing other test
10 tools.
11
13 use Test2::Tools::Tester qw/event_groups filter_events facets/;
14
15 use Test2::Tools::Basic qw/plan pass ok/;
16 use Test2::Tools::Compare qw/is like/;
17
18 my $events = intercept {
19 plan 11;
20
21 pass('pass');
22 ok(1, 'pass');
23
24 is(1, 1, "pass");
25 like(1, 1, "pass");
26 };
27
28 # Grab events generated by tools in Test2::Tools::Basic
29 my $basic = filter $events => 'Test2::Tools::Basic';
30
31 # Grab events generated by Test2::Tools::Basic;
32 my $compare = filter $events => 'Test2::Tools::Compare';
33
34 # Grab events generated by tools named 'ok'.
35 my $oks = filter $events => qr/.*::ok$/;
36
37 my $grouped = group_events $events;
38 # Breaks events into this structure:
39 {
40 '__NA__' => [ ... ],
41 'Test2::Tools::Basic' => {
42 '__ALL__' => [ $events->[0], $events->[1], $events->[2] ],
43 plan => [ $events->[0] ],
44 pass => [ $events->[1] ],
45 ok => [ $events->[2] ],
46 },
47 Test2::Tools::Compare => { ... },
48 }
49
50 # Get an arrayref of all the assert facets from the list of events.
51 my $assert_facets = facets assert => $events;
52 # [
53 # bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
54 # bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
55 # ]
56
57 # Same, but for info facets
58 my $info_facets = facets info => $events;
59
61 No subs are exported by default.
62
63 $array_ref = filter $events => $PACKAGE
64 $array_ref = filter $events => $PACKAGE1, $PACKAGE2
65 $array_ref = filter $events => qr/match/
66 $array_ref = filter $events => qr/match/, $PACKAGE
67 This function takes an arrayref of events as the first argument.
68 All additional arguments must either be a package name, or a regex.
69 Any event that is generated by a tool in any of the package, or by
70 a tool that matches any of the regexes, will be returned in an
71 arrayref.
72
73 $grouped = group_events($events)
74 This function iterates all the events in the argument arrayref and
75 splits them into groups. The resulting data structure is:
76
77 { PACKAGE => { SUBNAME => [ $EVENT1, $EVENT2, ... }}
78
79 If the package of an event is not known it will be put into and
80 arrayref under the '__NA__' key at the root of the structure. If a
81 sub name is not known it will typically go under the '__ANON__' key
82 in under the package name.
83
84 In addition there is an '__ALL__' key under each package which
85 stores all of the events sorted into that group.
86
87 A more complete example:
88
89 {
90 '__NA__' => [ $event->[3] ],
91 'Test2::Tools::Basic' => {
92 '__ALL__' => [ $events->[0], $events->[1], $events->[2] ],
93 plan => [ $events->[0] ],
94 pass => [ $events->[1] ],
95 ok => [ $events->[2] ],
96 },
97 }
98
99 $arrayref = facets TYPE => $events
100 This function will compile a list of all facets of the specified
101 type that are found in the arrayref of events. If the facet has a
102 "Test2::EventFacet::TYPE" package available then the facet will be
103 constructed into an instance of the class, otherwise it is left as
104 a hashref. Facet Order is preserved.
105
106 my $assert_facets = facets assert => $events;
107 # [
108 # bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
109 # bless({ details => 'pass', pass => 1}, 'Test2::EventFacet::Assert'),
110 # ]
111
113 The source code repository for Test2-Suite can be found at
114 https://github.com/Test-More/Test2-Suite/.
115
117 Chad Granum <exodist@cpan.org>
118
120 Chad Granum <exodist@cpan.org>
121
123 Copyright 2018 Chad Granum <exodist@cpan.org>.
124
125 This program is free software; you can redistribute it and/or modify it
126 under the same terms as Perl itself.
127
128 See http://dev.perl.org/licenses/
129
130
131
132perl v5.34.0 2021-11-16 Test2::Tools::Tester(3)