1Test2::Harness::Plugin(U3s)er Contributed Perl DocumentatTieosnt2::Harness::Plugin(3)
2
3
4

NAME

6       Test2::Harness::Plugin - Base class for Test2::Harness plugins.
7

DESCRIPTION

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

SYNOPSIS

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

METHODS

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           Note that data from all changed_files() calls from all plugins will
130           be merged.
131
132       ($type, $value) = $plugin->changed_diff($settings)
133           Generate a diff that can be used to calculate changed files/subs
134           for which to run tests. Unlike changed_files(), only 1 diff will be
135           used, first plugin listed that returns one wins. This is not run at
136           all if a diff is provided via --changed-diff.
137
138           Diffs must be in the same format as this git command:
139
140               git diff -U1000000 -W --minimal BASE_BRANCH_OR_COMMIT
141
142           Some other diff formats may work by chance, but they are not
143           dirfectly supported. In the future other diff formats may be
144           directly supported, but not yet.
145
146           The following return sets are allowed:
147
148           file => string
149               Path to a diff file
150
151           diff => string
152               In memory diff as a single string
153
154           lines => \@lines
155               Diff where each line is a seperate string in an arrayref.
156
157           line_sub => sub { ... }
158               Sub that returns one line per call and undef when there are no
159               more lines
160
161           handle => $FH
162               A filehandle to the diff
163
164       $exit = $plugin->shellcall($settings, $name, $cmd)
165       $exit = $plugin->shellcall($settings, $name, @cmd)
166           This is essentially the same as "system()" except that STDERR and
167           STDOUT are redirected to files that the yath collector will pick up
168           so that any output from the command will be seen as events and will
169           be part of the yath log. If no workspace is available this will not
170           redirect IO and it will be identical to calling "system()".
171
172           This is particularily useful in "setup()" and "teardown()" when
173           running external commands, specially any that daemonize and
174           continue to produce output after the setup/teardown method has
175           completed.
176
177           $name is required because it will be used for filenames, and will
178           be used as the output tag (best to limit it to 8 characters).
179
180       $plugin->redirect_io($settings, $name)
181           WARNING: This must NEVER be called in a primary yath process. Only
182           use this in forked processes that you control. If this is used in a
183           main process it could hide ALL output.
184
185           This will redirect STDERR and STDOUT to files that will be picked
186           up by the yath collector so that any output appears as proper yath
187           events and will be included in the yath log.
188
189           $name is required because it will be used for filenames, and will
190           be used as the output tag (best to limit it to 8 characters).
191
192       $plugin->TO_JSON
193           This is here as a bare minimum serialization method. It returns the
194           plugin class name.
195

SOURCE

197       The source code repository for Test2-Harness can be found at
198       http://github.com/Test-More/Test2-Harness/.
199

MAINTAINERS

201       Chad Granum <exodist@cpan.org>
202

AUTHORS

204       Chad Granum <exodist@cpan.org>
205
207       Copyright 2020 Chad Granum <exodist7@gmail.com>.
208
209       This program is free software; you can redistribute it and/or modify it
210       under the same terms as Perl itself.
211
212       See http://dev.perl.org/licenses/
213
214
215
216perl v5.34.0                      2021-11-05         Test2::Harness::Plugin(3)
Impressum