1Test2::Harness::Plugin(U3s)er Contributed Perl DocumentatTieosnt2::Harness::Plugin(3)
2
3
4
6 Test2::Harness::Plugin - Base class for Test2::Harness plugins.
7
9 This class holds the methods specific to Test2::Harness which is the
10 backend. Most of the time you actually want to subclass
11 App::Yath::Plugin which subclasses this class, and holds additional
12 methods that apply to yath (the UI layer).
13
15 You probably want to subclass App::Yath::Plugin instead. This class
16 here mainly exists to separate concerns, but is not something you
17 should use directly.
18
19 package Test2::Harness::Plugin::MyPlugin;
20
21 use parent 'Test2::Harness::Plugin';
22
23 # ... Define methods
24
25 1;
26
28 $plugin->munge_search($input, $default_search, $settings)
29 $input is an arrayref of files and/or directories provided at the
30 command line.
31
32 $default_search is an arrayref with the default files/directories
33 pulled in when nothing is specified at the command ine.
34
35 $settings is an instance of Test2::Harness::Settings
36
37 $undef_or_inst = $plugin->claim_file($path, $settings)
38 This is a chance for a plugin to claim a test file early, before
39 Test2::Harness takes care of it. If your plugin does not want to
40 claim the file just return undef. To claim the file return an
41 instance of Test2::Harness::TestFile created with $path.
42
43 $plugin->munge_files(\@tests, $settings)
44 This is an opportunity for your plugin to modify the data for any
45 test file that will be run. The first argument is an arrayref of
46 Test2::Harness::TestFile objects.
47
48 $hashref = $plugin->duration_data()
49 If defined, this can return a hashref of duration data. This should
50 return undef if no duration data is provided. The first plugin
51 listed that provides duration data wins, no other plugins will be
52 checked once duration data is obtained.
53
54 Example duration data:
55
56 {
57 't/foo.t' => 'medium',
58 't/bar.t' => 'short',
59 't/baz.t' => 'long',
60 }
61
62 $hashref_or_arrayref = $plugin->coverage_data(\@changed)
63 $hashref_or_arrayref = $plugin->coverage_data()
64 If defined, this can return a hashref of all coverage data, or an
65 arrayref of tests that cover the tests listed in @changed. This
66 should return undef if no coverage data is available. The first
67 plugin to provide coverage data wins, no other plugins will be
68 checked once coverage data has been obtained.
69
70 Examples:
71
72 [
73 'foo.t',
74 'bar.t',
75 'baz.t',
76 ]
77
78 {
79 'lib/Foo.pm' => [
80 't/foo.t',
81 't/integration.t',
82 ],
83 'lib/Bar.pm' => [
84 't/bar.t',
85 't/integration.t',
86 ],
87 }
88
89 $plugin->inject_run_data(meta => $meta, fields => $fields, run => $run)
90 This is a callback that lets your plugin add meta-data or custom
91 fields to the run event. The meta-data and fields are available in
92 the event log, and are particularily useful to App::Yath::UI.
93
94 sub inject_run_data {
95 my $class = shift;
96 my %params = @_;
97
98 my $meta = $params{meta};
99 my $fields = $params{fields};
100
101 # Meta-data is a hash, each plugin should define its own key, and put
102 # data under that key
103 $meta->{MyPlugin}->{stuff} = "Stuff!";
104
105 # Fields is an array of fields that a UI might want to display when showing the run.
106 push @$fields => {name => 'MyPlugin', details => "Human Friendly Stuff", raw => "Less human friendly stuff", data => $all_the_stuff};
107
108 return;
109 }
110
111 $plugin->setup($settings)
112 This is a callback that lets you run setup logic when the runner
113 starts. Note that in a persistent runner this is run once on
114 startup, it is not run for each "run" command against the
115 persistent runner.
116
117 $plugin->teardown($settings)
118 This is a callback that lets you run teardown logic when the runner
119 stops. Note that in a persistent runner this is run once on
120 termination, it is not run for each "run" command against the
121 persistent runner.
122
123 @files = $plugin->changed_files($settings)
124 Get a list of files that have changed. Plugins are free to define
125 what "changed" means. This may be used by the finder to determine
126 what tests to run based on coverage data collected in previous
127 runs.
128
129 $exit = $plugin->shellcall($settings, $name, $cmd)
130 $exit = $plugin->shellcall($settings, $name, @cmd)
131 This is essentially the same as "system()" except that STDERR and
132 STDOUT are redirected to files that the yath collector will pick up
133 so that any output from the command will be seen as events and will
134 be part of the yath log. If no workspace is available this will not
135 redirect IO and it will be identical to calling "system()".
136
137 This is particularily useful in "setup()" and "teardown()" when
138 running external commands, specially any that daemonize and
139 continue to produce output after the setup/teardown method has
140 completed.
141
142 $name is required because it will be used for filenames, and will
143 be used as the output tag (best to limit it to 8 characters).
144
145 $plugin->redirect_io($settings, $name)
146 WARNING: This must NEVER be called in a primary yath process. Only
147 use this in forked processes that you control. If this is used in a
148 main process it could hide ALL output.
149
150 This will redirect STDERR and STDOUT to files that will be picked
151 up by the yath collector so that any output appears as proper yath
152 events and will be included in the yath log.
153
154 $name is required because it will be used for filenames, and will
155 be used as the output tag (best to limit it to 8 characters).
156
157 $plugin->TO_JSON
158 This is here as a bare minimum serialization method. It returns the
159 plugin class name.
160
162 The source code repository for Test2-Harness can be found at
163 http://github.com/Test-More/Test2-Harness/.
164
166 Chad Granum <exodist@cpan.org>
167
169 Chad Granum <exodist@cpan.org>
170
172 Copyright 2020 Chad Granum <exodist7@gmail.com>.
173
174 This program is free software; you can redistribute it and/or modify it
175 under the same terms as Perl itself.
176
177 See http://dev.perl.org/licenses/
178
179
180
181perl v5.32.1 2021-03-12 Test2::Harness::Plugin(3)