| 1 |
package App::Yath::Plugin; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
our $VERSION = '1.000179'; |
| 6 |
|
| 7 |
use parent 'Test2::Harness::Plugin'; |
| 8 |
|
| 9 |
# We do not want this defined by default, but it should be documented |
| 10 |
#sub handle_event {} |
| 11 |
#sub sort_files {} |
| 12 |
#sub sort_files_2 {} |
| 13 |
|
| 14 |
sub finish {} |
| 15 |
|
| 16 |
sub finalize {} |
| 17 |
|
| 18 |
1; |
| 19 |
|
| 20 |
__END__ |
| 21 |
|
| 22 |
=pod |
| 23 |
|
| 24 |
=encoding UTF-8 |
| 25 |
|
| 26 |
=head1 NAME |
| 27 |
|
| 28 |
App::Yath::Plugin - Base class for yath plugins |
| 29 |
|
| 30 |
=head1 DESCRIPTION |
| 31 |
|
| 32 |
This is a base class for yath plugins. Note this class also subclasses |
| 33 |
L<Test2::Harness::Plugin>. |
| 34 |
|
| 35 |
This class holds the methods specific to yath, which is the UI layer. |
| 36 |
L<Test2::Harness::Plugin> holds the methods specific to L<Test2::Harness> which |
| 37 |
is the backend. |
| 38 |
|
| 39 |
=head1 SYNOPSIS |
| 40 |
|
| 41 |
package App::Yath::Plugin::MyPlugin; |
| 42 |
|
| 43 |
use parent 'App::Yath::Plugin'; |
| 44 |
|
| 45 |
# ... Define methods |
| 46 |
|
| 47 |
1; |
| 48 |
|
| 49 |
|
| 50 |
Then to use it at the command line: |
| 51 |
|
| 52 |
$ yath -pMyPlugin ... |
| 53 |
|
| 54 |
=head1 NOTE ON INSTANCE VS CLASS |
| 55 |
|
| 56 |
None of the plugin base classes provide a C<new()> method. By default plugins |
| 57 |
are not instantiated and only the plugin package name is passed around. All |
| 58 |
methods are then called on the class. |
| 59 |
|
| 60 |
If you want your plugin to be instantiated as an object you need only define a |
| 61 |
C<new()> method. If this method is defined yath will call it and create an |
| 62 |
instance. The instance created will then be used when calling all the methods. |
| 63 |
|
| 64 |
To pass arguments to the constructor you can use |
| 65 |
C<yath -pYourPlugin=arg1,arg2,arg3...>. Your plugin can also define options |
| 66 |
using L<App::Yath::Options> which will be dropped into the C<$settings> that |
| 67 |
get passed around. |
| 68 |
|
| 69 |
=head1 METHODS |
| 70 |
|
| 71 |
B<Note:> See L<Test2::Harness::Plugin> for additional method you can implement/override |
| 72 |
|
| 73 |
=over 4 |
| 74 |
|
| 75 |
=item $plugin->handle_event($event, $settings) |
| 76 |
|
| 77 |
Called for every single event that yath sees. Note that this method is not |
| 78 |
defined by default for performance reasons, however it will be called if you |
| 79 |
define it. |
| 80 |
|
| 81 |
=item @sorted = $plugin->sort_files_2(settings => $settings, files => \@unsorted) |
| 82 |
|
| 83 |
This gives your plugin a chance to sort the files before they are added to the |
| 84 |
queue. Other things are done later to re-order the files optimally based on |
| 85 |
length or category, so this sort is just for initial job numbering, and to |
| 86 |
define a base order before optimization takes place. |
| 87 |
|
| 88 |
All files to sort will be instances of L<Test2::Harness::TestFile>. |
| 89 |
|
| 90 |
This method is normally left undefined, but will be called if you define it. |
| 91 |
|
| 92 |
If this is present then C<sort_files()> will be ignored. |
| 93 |
|
| 94 |
=item @sorted = $plugin->sort_files(@unsorted) |
| 95 |
|
| 96 |
B<DEPRECATED> Use C<sort_files_2()> instead. |
| 97 |
|
| 98 |
This gives your plugin a chance to sort the files before they are added to the |
| 99 |
queue. Other things are done later to re-order the files optimally based on |
| 100 |
length or category, so this sort is just for initial job numbering, and to |
| 101 |
define a base order before optimization takes place. |
| 102 |
|
| 103 |
All files to sort will be instances of L<Test2::Harness::TestFile>. |
| 104 |
|
| 105 |
This method is normally left undefined, but will be called if you define it. |
| 106 |
|
| 107 |
=item $plugin->finish(%args) |
| 108 |
|
| 109 |
This is what arguments are received: |
| 110 |
|
| 111 |
( |
| 112 |
settings => $settings, # The settings |
| 113 |
final_data => $final_data, # See below |
| 114 |
pass => $pass ? 1 : 0, # Always a 0 or 1 |
| 115 |
tests_seen => $self->{+TESTS_SEEN} // 0, # Integer 0 or greater |
| 116 |
asserts_seen => $self->{+ASSERTS_SEEN} // 0, # Integer 0 or greater |
| 117 |
) |
| 118 |
|
| 119 |
The final_data looks like this, note that some data may not be present if it is |
| 120 |
not applicable. The data structure can be as simple as |
| 121 |
C<< { pass => $bool } >>. |
| 122 |
|
| 123 |
{ |
| 124 |
pass => $pass, # boolean, did the test run pass or fail? |
| 125 |
|
| 126 |
failed => [ # Jobs that failed, and did not pass on a retry |
| 127 |
[$job_id1, $file1], # Failing job 1 |
| 128 |
[$job_id2, $file2], # Failing job 2 |
| 129 |
... |
| 130 |
], |
| 131 |
retried => [ # Jobs that failed and were retried |
| 132 |
[$job_id1, $times_run1, $file1, $passed_eventually1], # Passed_eventually is a boolean |
| 133 |
[$job_id2, $times_run2, $file2, $passed_eventually2], |
| 134 |
... |
| 135 |
], |
| 136 |
hatled => [ # Jobs that caused the entire test suite to halt |
| 137 |
[$job_id1, $file1, $halt_reason1], # halt_reason is a human readible string |
| 138 |
[$job_id2, $file2, $halt_reason2], |
| 139 |
], |
| 140 |
} |
| 141 |
|
| 142 |
=item $plugin->finalize($settings) |
| 143 |
|
| 144 |
This is called as late as possible before exit. This is mainly useful for |
| 145 |
outputting messages such as "Extra log file written to ..." which are best put |
| 146 |
at the end of output. |
| 147 |
|
| 148 |
=back |
| 149 |
|
| 150 |
=head1 SOURCE |
| 151 |
|
| 152 |
The source code repository for Test2-Harness can be found at |
| 153 |
F<http://github.com/Test-More/Test2-Harness/>. |
| 154 |
|
| 155 |
=head1 MAINTAINERS |
| 156 |
|
| 157 |
=over 4 |
| 158 |
|
| 159 |
=item Chad Granum E<lt>[email protected]<gt> |
| 160 |
|
| 161 |
=back |
| 162 |
|
| 163 |
=head1 AUTHORS |
| 164 |
|
| 165 |
=over 4 |
| 166 |
|
| 167 |
=item Chad Granum E<lt>[email protected]<gt> |
| 168 |
|
| 169 |
=back |
| 170 |
|
| 171 |
=head1 COPYRIGHT |
| 172 |
|
| 173 |
Copyright 2020 Chad Granum E<lt>[email protected]<gt>. |
| 174 |
|
| 175 |
This program is free software; you can redistribute it and/or |
| 176 |
modify it under the same terms as Perl itself. |
| 177 |
|
| 178 |
See F<http://dev.perl.org/licenses/> |
| 179 |
|
| 180 |
=cut |