Debian Codegraph @

lib/App/Yath.pm

raw
1 package App::Yath;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.000179';
6
7 use Test2::Harness::Util::HashBase qw{
8 -config
9 -settings
10
11 -_options -options_loaded
12 -_argv -argv_processed <_orig_argv
13
14 -_command_class -_command_name -_early_command
15 };
16
17 use Time::HiRes qw/time/;
18
19 use App::Yath::Util qw/find_pfile/;
20 use Test2::Harness::Util qw/find_libraries clean_path/;
21 use App::Yath::Options();
22 use Scalar::Util qw/blessed/;
23
24 my $APP_PATH = __FILE__;
25 $APP_PATH =~ s{App\S+Yath\.pm$}{}g;
26 $APP_PATH = clean_path($APP_PATH);
27 sub app_path { $APP_PATH }
28
29 sub init {
30 my $self = shift;
31
32 my $old = select STDOUT;
33 $| = 1;
34 select STDERR;
35 $| = 1;
36 select $old;
37
38 my @caller = caller(1);
39
40 $self->{+SETTINGS} //= Test2::Harness::Settings->new;
41
42 ${$self->{+SETTINGS}->define_prefix('harness')->vivify_field('script')} //= clean_path($caller[1]);
43 ${$self->{+SETTINGS}->define_prefix('harness')->vivify_field('start')} //= time();
44 ${$self->{+SETTINGS}->define_prefix('harness')->vivify_field('no_scan_plugins')} //= 0;
45
46 $self->{+_ARGV} //= delete($self->{argv}) // [];
47 $self->{+_ORIG_ARGV} = [@{$self->{+_ARGV}}];
48 $self->{+CONFIG} //= {};
49 }
50
51 sub generate_run_sub {
52 my $self = shift;
53 my ($symbol) = @_;
54
55 my $cmd_class;
56 my ($options, $argv);
57
58 if (my $cmd = $self->_command_from_argv(no_default => 1, valid_only => 1)) {
59 $cmd_class = $self->load_command($cmd);
60
61 $self->{+_COMMAND_NAME} = $cmd;
62 $self->{+_COMMAND_CLASS} = $cmd_class;
63
64 if ($cmd_class->only_cmd_opts) {
65 $self->{+_EARLY_COMMAND} = 1;
66 my $settings = $self->{+SETTINGS};
67
68 $options = App::Yath::Options->new(settings => $settings);
69 $options->set_command_class($cmd_class);
70 $options->set_args($self->{+_ARGV});
71
72 $argv = $self->{+_ARGV};
73 $cmd_class->munge_opts($options, $argv, $settings);
74 }
75 }
76
77 $options //= $self->load_options();
78
79 $cmd_class //= $self->command_class();
80 ${$self->{+SETTINGS}->define_prefix('harness')->vivify_field('command')} //= $cmd_class;
81
82 $argv = $self->process_argv();
83
84 return $cmd_class->generate_run_sub($symbol, $argv, $self->{+SETTINGS}, $self->{+_ORIG_ARGV}) if $cmd_class->can('generate_run_sub');
85
86 my $cmd = $cmd_class->new(settings => $options->settings, args => $argv, orig_args => $self->{+_ORIG_ARGV});
87
88 $options->process_option_post_actions($cmd);
89
90 my $run = sub { $self->run_command($cmd) };
91
92 {
93 no strict 'refs';
94 *{$symbol} = $run;
95 }
96
97 return;
98 }
99
100 sub run_command {
101 my $self = shift;
102 my ($cmd) = @_;
103
104 my $exit = $cmd->run;
105
106 die "Command '" . $cmd->name() . "' did not return an exit value.\n"
107 unless defined $exit;
108
109 return $exit;
110 }
111
112 sub load_options {
113 my $self = shift;
114
115 my $settings = $self->{+SETTINGS} = $self->{+SETTINGS};
116
117 my $options = $self->{+_OPTIONS} //= App::Yath::Options->new(settings => $settings);
118
119 return $options if $self->{+OPTIONS_LOADED}++;
120
121 $options->include_from(
122 'App::Yath::Options::Debug',
123 'App::Yath::Options::PreCommand',
124 );
125
126 return $options if $self->{+SETTINGS}->harness->no_scan_plugins;
127
128 my $option_libs = {
129 %{find_libraries('App::Yath::Plugin::*')},
130 %{find_libraries('Test2::Harness::Runner::Resource::*')},
131 };
132 for my $lib (sort keys %$option_libs) {
133 my $ok = eval { require $option_libs->{$lib}; 1 };
134 unless ($ok) {
135 warn "Failed to load module '$option_libs->{$lib}': $@";
136 next;
137 }
138
139 next unless $lib->can('options');
140
141 my $add;
142 $ok = eval { $add = $lib->options; 1 };
143 unless ($ok) {
144 warn "Failed to get options from module '$option_libs->{$lib}': $@";
145 next;
146 }
147
148 next unless $add;
149
150 unless (blessed($add) && $add->isa('App::Yath::Options')) {
151 warn "Module '$option_libs->{$lib}' is outdated, not loading options.\n"
152 unless $ENV{'YATH_SELF_TEST'};
153 next;
154 }
155
156 # A module found by the scan is not necessarily one we know anything
157 # about, it may conflict with another. That is not a reason to abort
158 # every yath command on the system.
159 $ok = eval { $options->include_from($lib); 1 };
160 unless ($ok) {
161 warn "Failed to include options from module '$option_libs->{$lib}': $@";
162 next;
163 }
164 }
165
166 return $options;
167 }
168
169 sub process_argv {
170 my $self = shift;
171
172 return $self->{+_ARGV} if $self->{+ARGV_PROCESSED}++;
173
174 my $options = $self->load_options();
175 my $settings = $self->settings;
176
177 my $config_pre_args = $self->{+CONFIG}->{'~'};
178 $options->grab_pre_command_opts(args => $config_pre_args, stop_at_non_opt => 0, passthrough => 0, die_at_non_opt => 1)
179 if $config_pre_args;
180
181 $options->set_args($self->{+_ARGV});
182 $options->grab_pre_command_opts();
183
184 $options->process_pre_command_opts();
185
186 my $cmd_name = $self->_command_from_argv();
187 my $cmd_class = $self->load_command($cmd_name);
188 die "Command '$cmd_name' needs to be specified earlier in the command line arguments to yath.\n" if $cmd_class->only_cmd_opts && !$self->{+_EARLY_COMMAND};
189 $options->set_command_class($cmd_class);
190 $self->{+_COMMAND_CLASS} = $cmd_class;
191
192 $options->grab_pre_command_opts(stop_at_non_opt => 1, passthrough => 1, die_at_non_opt => 0);
193
194 my $config_cmd_args = $self->{+CONFIG}->{$cmd_name};
195
196 $options->grab_pre_command_opts(args => $config_cmd_args, stop_at_non_opt => 1, passthrough => 1, die_at_non_opt => 0)
197 if $config_cmd_args;
198
199 $options->process_pre_command_opts();
200
201 $options->grab_command_opts(args => $config_cmd_args, die_at_non_opt => 1, stop_at_non_opt => 0, passthrough => 0)
202 if $config_cmd_args;
203
204 $options->grab_command_opts();
205 $options->process_command_opts();
206
207 $options->clear_env();
208
209 $self->clear_env();
210
211 my %seen = map {((ref($_) || $_) => 1)} @{$settings->harness->plugins};
212 for my $plugin (@{$options->used_plugins}) {
213 next if $seen{$plugin}++;
214 push @{$settings->harness->plugins} => $plugin->can('new') ? $plugin->new() : $plugin;
215 }
216
217 return $self->{+_ARGV};
218 }
219
220 sub clear_env {
221 delete $ENV{HARNESS_IS_VERBOSE};
222 delete $ENV{T2_FORMATTER};
223 delete $ENV{T2_HARNESS_FORKED};
224 delete $ENV{T2_HARNESS_IS_VERBOSE};
225 delete $ENV{T2_HARNESS_JOB_IS_TRY};
226 delete $ENV{T2_HARNESS_JOB_NAME};
227 delete $ENV{T2_HARNESS_PRELOAD};
228 delete $ENV{T2_STREAM_DIR};
229 delete $ENV{T2_STREAM_FILE};
230 delete $ENV{T2_STREAM_JOB_ID};
231 delete $ENV{TEST2_JOB_DIR};
232 delete $ENV{TEST2_RUN_DIR};
233
234 # If Test2::API is already loaded then we need to keep these.
235 delete $ENV{TEST2_ACTIVE} unless $INC{'Test2/API.pm'};
236 delete $ENV{TEST_ACTIVE} unless $INC{'Test2/API.pm'};
237 }
238
239 sub command_class {
240 my $self = shift;
241
242 $self->process_argv() unless $self->{+_COMMAND_CLASS};
243
244 return $self->{+_COMMAND_CLASS};
245 }
246
247 sub _command_from_argv {
248 my $self = shift;
249 my %params = @_;
250
251 return $self->{+_COMMAND_NAME} if $self->{+_COMMAND_NAME};
252
253 my $argv = $self->{+_ARGV};
254
255 for (my $idx = 0; $idx < @$argv; $idx++) {
256 my $arg = $argv->[$idx];
257
258 if ($arg =~ m/^-*h(elp)?$/i) {
259 splice(@$argv, $idx, 1);
260 return 'help';
261 }
262
263 if ($arg eq 'do') {
264 splice(@$argv, $idx, 1);
265 last;
266 }
267
268 last if $arg eq '::';
269 next if $arg =~ /^-/;
270
271 if ($arg =~ m/\.jsonl(\.bz2|\.gz)?$/) {
272 warn "\n** First argument is a log file, defaulting to the 'replay' command **\n\n";
273 return 'replay';
274 }
275
276 return splice(@$argv, $idx, 1) if $self->load_command($arg, check_only => 1);
277 return if $params{valid_only};
278
279 my $is_path = 0;
280 $is_path ||= -f $arg;
281 $is_path ||= -d $arg;
282
283 # Assume it is a command, but an invalid one.
284 return splice(@$argv, $idx, 1) unless $is_path;
285 }
286
287 return if $params{no_default};
288
289 if (my $pfile = find_pfile($self->settings, no_checks => 1)) {
290 warn "\n** Persistent runner detected, defaulting to the 'run' command **\n\n";
291 return 'run';
292 }
293
294 warn "\n** Defaulting to the 'test' command **\n\n";
295 return 'test';
296 }
297
298 sub load_command {
299 my $self = shift;
300 my ($cmd_name, %params) = @_;
301
302 my $cmd_class = "App::Yath::Command::$cmd_name";
303 my $cmd_file = "App/Yath/Command/$cmd_name.pm";
304
305 return $cmd_class if eval { require $cmd_file; 1 };
306 my $error = $@ || 'unknown error';
307
308 my $not_found = $error =~ m{Can't locate \Q$cmd_file\E in \@INC};
309
310 return undef if $params{check_only} && $not_found;
311
312 die "yath command '$cmd_name' not found. (did you forget to install $cmd_class?)\n"
313 if $not_found;
314
315 die $error;
316 }
317
318
319 1;
320
321 __END__
322
323
324 =pod
325
326 =encoding UTF-8
327
328 =head1 NAME
329
330 App::Yath - Yet Another Test Harness (Test2-Harness) Command Line Interface
331 (CLI)
332
333 =head1 DESCRIPTION
334
335 This is the primary documentation for C<yath>, L<App::Yath>, L<Test2::Harness>.
336
337 The canonical source of up-to-date command options are the help output when
338 using C<$ yath help> and C<$ yath help COMMAND>.
339
340 This document is mainly an overview of C<yath> usage and common recipes.
341
342 L<App::Yath> is an alternative to L<App::Prove>, and L<Test2::Harness> is an alternative to L<Test::Harness>. It is not designed to
343 replace L<Test::Harness>/prove. L<Test2::Harness> is designed to take full
344 advantage of the rich data L<Test2> can provide. L<Test2::Harness> is also able to
345 use non-core modules and provide more functionality than prove can achieve with
346 its restrictions.
347
348 =head1 PLATFORM SUPPORT
349
350 L<Test2::Harness>/L<App::Yath> is is focused on unix-like platforms. Most
351 development happens on linux, but bsd, macos, etc should work fine as well.
352
353 Patches are welcome for any/all platforms, but the primary author (Chad
354 'Exodist' Granum) does not directly develop against non-unix platforms.
355
356 =head2 WINDOWS
357
358 Currently windows is not supported, and it is known that the package will not
359 install on windows. Patches are be welcome, and it would be great if someone
360 wanted to take on the windows-support role, but it is not a primary goal for
361 the project.
362
363 =head1 OVERVIEW
364
365 To use L<Test2::Harness>, you use the C<yath> command. Yath will find the tests
366 (or use the ones you specify) and run them. As it runs, it will output
367 diagnostic information such as failures. At the end, yath will print a summary
368 of the test run.
369
370 C<yath> can be thought of as a more powerful alternative to C<prove>
371 (L<Test::Harness>)
372
373 =head1 RECIPES
374
375 These are common recipes for using C<yath>.
376
377 =head2 RUN PROJECT TESTS
378
379 $ yath
380
381 Simply running yath with no arguments means "Run all tests for the current
382 project". Yath will look for tests in C<./t>, C<./t2>, and C<./test.pl> and
383 run any which are found.
384
385 Normally this implies the C<test> command but will instead imply the C<run>
386 command if a persistent test runner is detected.
387
388 =head2 PRELOAD MODULES
389
390 Yath has the ability to preload modules. Yath normally forks to start new
391 tests, so preloading can reduce the time spent loading modules over and over in
392 each test.
393
394 Note that some tests may depend on certain modules not being loaded. In these
395 cases you can add the C<# HARNESS-NO-PRELOAD> directive to the top of the test
396 files that cannot use preload.
397
398 =head3 SIMPLE PRELOAD
399
400 Any module can be preloaded:
401
402 $ yath -PMoose
403
404 You can preload as many modules as you want:
405
406 $ yath -PList::Util -PScalar::Util
407
408 =head3 COMPLEX PRELOAD
409
410 If your preload is a subclass of L<Test2::Harness::Runner::Preload> then more
411 complex preload behavior is possible. See those docs for more info.
412
413 =head2 LOGGING
414
415 =head3 RECORDING A LOG
416
417 You can turn on logging with a flag. The filename of the log will be printed at
418 the end.
419
420 $ yath -L
421 ...
422 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl
423
424 The event log can be quite large. It can be compressed with bzip2.
425
426 $ yath -B
427 ...
428 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2
429
430 gzip compression is also supported.
431
432 $ yath -G
433 ...
434 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.gz
435
436 C<-B> and C<-G> both imply C<-L>.
437
438 =head3 REPLAYING FROM A LOG
439
440 You can replay a test run from a log file:
441
442 $ yath test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2
443
444 This will be significantly faster than the initial run as no tests are actually
445 being executed. All events are simply read from the log, and processed by the
446 harness.
447
448 You can change display options and limit rendering/processing to specific test
449 jobs from the run:
450
451 $ yath test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2 -v [TEST UUID(S)]
452
453 Note: This is done using the C<$ yath replay ...> command. The C<replay>
454 command is implied if the first argument is a log file.
455
456 =head2 PER-TEST TIMING DATA
457
458 The C<-T> option will cause each test file to report how long it took to run.
459
460 $ yath -T
461
462 ( PASSED ) job 1 t/yath_script.t
463 ( TIME ) job 1 Startup: 0.07692s | Events: 0.01170s | Cleanup: 0.00190s | Total: 0.09052s
464
465 =head2 PERSISTENT RUNNER
466
467 yath supports starting a yath session that waits for tests to run. This is very
468 useful when combined with preload.
469
470 =head3 STARTING
471
472 This starts the server. Many options available to the 'test' command will work
473 here but not all. See C<$ yath help start> for more info.
474
475 $ yath start
476
477 =head3 RUNNING
478
479 This will run tests using the persistent runner. By default, it will search for
480 tests just like the 'test' command. Many options available to the C<test>
481 command will work for this as well. See C<$ yath help run> for more details.
482
483 $ yath run
484
485 =head3 STOPPING
486
487 Stopping a persistent runner is easy.
488
489 $ yath stop
490
491 =head3 INFORMATIONAL
492
493 The C<which> command will tell you which persistent runner will be used. Yath
494 searches for the persistent runner in the current directory, then searches in
495 parent directories until it either hits the root directory, or finds the
496 persistent runner tracking file.
497
498 $ yath which
499
500 The C<watch> command will tail the runner's log files.
501
502 $ yath watch
503
504 =head3 PRELOAD + PERSISTENT RUNNER
505
506 You can use preloads with the C<yath start> command. In this case, yath will
507 track all the modules pulled in during preload. If any of them change, the
508 server will reload itself to bring in the changes. Further, modified modules
509 will be blacklisted so that they are not preloaded on subsequent reloads. This
510 behavior is useful if you are actively working on a module that is normally
511 preloaded.
512
513 =head2 MAKING YOUR PROJECT ALWAYS USE YATH
514
515 $ yath init
516
517 The above command will create C<test.pl>. C<test.pl> is automatically run by
518 most build utils, in which case only the exit value matters. The generated
519 C<test.pl> will run C<yath> and execute all tests in the C<./t> and/or C<./t2>
520 directories. Tests in C<./t> will ALSO be run by prove but tests in C<./t2>
521 will only be run by yath.
522
523 =head2 PROJECT-SPECIFIC YATH CONFIG
524
525 You can write a C<.yath.rc> file. The file format is very simple. Create a
526 C<[COMMAND]> section to start the configuration for a command and then
527 provide any options normally allowed by it. When C<yath> is run inside your
528 project, it will use the config specified in the rc file, unless overridden
529 by command line options.
530
531 B<Note:> You can also add pre-command options by placing them at the top of
532 your config file I<BEFORE> any C<[cmd]> markers.
533
534 Comments start with a semi-colon.
535
536 Example .yath.rc:
537
538 -pFoo ; Load the 'foo' plugin before dealing with commands.
539
540 [test]
541 -B ;Always write a bzip2-compressed log
542
543 [start]
544 -PMoose ;Always preload Moose with a persistent runner
545
546 This file is normally committed into the project's repo.
547
548 =head3 SPECIAL PATH PSEUDO-FUNCTIONS
549
550 Sometimes you want to specify files relative to the .yath.rc so that the config
551 option works from any subdirectory of the project. Other times you may wish to
552 use a shell expansion. Sometimes you want both!
553
554 =over 4
555
556 =item rel(path/to/file)
557
558 -I rel(path/to/extra_lib)
559 -I=rel(path/to/extra_lib)
560
561 This will take the path to C<.yath.rc> and prefix it to the path inside
562 C<rel(...)>. If for example you have C</project/.yath.rc> then the path would
563 become C</project/path/to/extra_lib>.
564
565 =item glob(path/*/file)
566
567 --default-search glob(subprojects/*/t)
568 --default-search=glob(subprojects/*/t)
569
570 This will add a C<--default-search $_> for every item found in the glob. This
571 uses the perl builtin function C<glob()> under the hood.
572
573 =item relglob(path/*/file)
574
575 --default-search relglob(subprojects/*/t)
576 --default-search=relglob(subprojects/*/t)
577
578 Same as C<glob()> except paths are relative to the C<.yath.rc> file.
579
580 =back
581
582 =head2 PROJECT-SPECIFIC YATH CONFIG USER OVERRIDES
583
584 You can add a C<.yath.user.rc> file. Format is the same as the regular
585 C<.yath.rc> file. This file will be read in addition to the regular config
586 file. Directives in this file will come AFTER the directives in the primary
587 config so it may be used to override config.
588
589 This file should not normally be committed to the project repo.
590
591 =head2 HARNESS DIRECTIVES INSIDE TESTS
592
593 C<yath> will recognise a number of directive comments placed near the top of
594 test files. These directives should be placed after the C<#!> line but
595 before any real code.
596
597 Real code is defined as any line that does not start with use, require, BEGIN, package, or #
598
599 =over 4
600
601 =item good example 1
602
603 #!/usr/bin/perl
604 # HARNESS-NO-FORK
605
606 ...
607
608 =item good example 2
609
610 #!/usr/bin/perl
611 use strict;
612 use warnings;
613
614 # HARNESS-NO-FORK
615
616 ...
617
618 =item bad example 1
619
620 #!/usr/bin/perl
621
622 # blah
623
624 # HARNESS-NO-FORK
625
626 ...
627
628 =item bad example 2
629
630 #!/usr/bin/perl
631
632 print "hi\n";
633
634 # HARNESS-NO-FORK
635
636 ...
637
638 =back
639
640 =head3 HARNESS-NO-PRELOAD
641
642 #!/usr/bin/perl
643 # HARNESS-NO-PRELOAD
644
645 Use this if your test will fail when modules are preloaded. This will tell yath
646 to start a new perl process to run the script instead of forking with preloaded
647 modules.
648
649 Currently this implies HARNESS-NO-FORK, but that may not always be the case.
650
651 =head3 HARNESS-NO-FORK
652
653 #!/usr/bin/perl
654 # HARNESS-NO-FORK
655
656 Use this if your test file cannot run in a forked process, but instead must be
657 run directly with a new perl process.
658
659 This implies HARNESS-NO-PRELOAD.
660
661 =head3 HARNESS-NO-STREAM
662
663 C<yath> usually uses the L<Test2::Formatter::Stream> formatter instead of TAP.
664 Some tests depend on using a TAP formatter. This option will make C<yath> use
665 L<Test2::Formatter::TAP> or L<Test::Builder::Formatter>.
666
667 =head3 HARNESS-NO-IO-EVENTS
668
669 C<yath> can be configured to use the L<Test2::Plugin::IOEvents> plugin. This
670 plugin replaces STDERR and STDOUT in your test with tied handles that fire off
671 proper L<Test2::Event>'s when they are printed to. Most of the time this is not
672 an issue, but any fancy tests or modules which do anything with STDERR or
673 STDOUT other than print may have really messy errors.
674
675 B<Note:> This plugin is disabled by default, so you only need this directive if
676 you enable it globally but need to turn it back off for select tests.
677
678 =head3 HARNESS-NO-TIMEOUT
679
680 C<yath> will usually kill a test if no events occur within a timeout (default
681 60 seconds). You can add this directive to tests that are expected to trip the
682 timeout, but should be allowed to continue.
683
684 NOTE: you usually are doing the wrong thing if you need to set this. See:
685 C<HARNESS-TIMEOUT-EVENT>.
686
687 =head3 HARNESS-TIMEOUT-EVENT 60
688
689 C<yath> can be told to alter the default event timeout from 60 seconds to another
690 value. This is the recommended alternative to HARNESS-NO-TIMEOUT
691
692 =head3 HARNESS-TIMEOUT-POSTEXIT 15
693
694 C<yath> can be told to alter the default POSTEXIT timeout from 15 seconds to another value.
695
696 Sometimes a test will fork producing output in the child while the parent is
697 allowed to exit. In these cases we cannot rely on the original process exit to
698 tell us when a test is complete. In cases where we have an exit, and partial
699 output (assertions with no final plan, or a plan that has not been completed)
700 we wait for a timeout period to see if any additional events come into
701
702 =head3 HARNESS-DURATION-LONG
703
704 This lets you tell C<yath> that the test file is long-running. This is
705 primarily used when concurrency is turned on in order to run longer tests
706 earlier, and concurrently with shorter ones. There is also a C<yath> option to
707 skip all long tests.
708
709 This duration is set automatically if HARNESS-NO-TIMEOUT is set.
710
711 =head3 HARNESS-DURATION-MEDIUM
712
713 This lets you tell C<yath> that the test is medium.
714
715 This is the default duration.
716
717 =head3 HARNESS-DURATION-SHORT
718
719 This lets you tell C<yath> That the test is short.
720
721 =head3 HARNESS-CATEGORY-ISOLATION
722
723 This lets you tell C<yath> that the test cannot be run concurrently with other
724 tests. Yath will hold off and run these tests one at a time after all other
725 tests.
726
727 =head3 HARNESS-CATEGORY-IMMISCIBLE
728
729 This lets you tell C<yath> that the test cannot be run concurrently with other
730 tests of this class. This is helpful when you have multiple tests which would
731 otherwise have to be run sequentially at the end of the run.
732
733 Yath prioritizes running these tests above HARNESS-CATEGORY-LONG.
734
735 =head3 HARNESS-CATEGORY-GENERAL
736
737 This is the default category.
738
739 =head3 HARNESS-CONFLICTS-XXX
740
741 This lets you tell C<yath> that no other test of type XXX can be run at the
742 same time as this one. You are able to set multiple conflict types and C<yath>
743 will honor them.
744
745 XXX can be replaced with any type of your choosing.
746
747 NOTE: This directive does not alter the category of your test. You are free
748 to mark the test with LONG or MEDIUM in addition to this marker.
749
750 =over 4
751
752 =item Example with multiple lines.
753
754 #!/usr/bin/perl
755 # DASH and space are split the same way.
756 # HARNESS-CONFLICTS-DAEMON
757 # HARNESS-CONFLICTS MYSQL
758
759 ...
760
761 =item Or on a single line.
762
763 #!/usr/bin/perl
764 # HARNESS-CONFLICTS DAEMON MYSQL
765
766 ...
767
768 =back
769
770 =head3 HARNESS-SHARES-XXX
771
772 This lets you tell C<yath> that this test uses XXX, but is happy to share it
773 with other tests that merely use it too. Any number of C<HARNESS-SHARES-XXX>
774 tests may run at the same time, but none of them will run at the same time
775 as a C<HARNESS-CONFLICTS-XXX> test. If you think of the two directives as a
776 lock on the name XXX, C<CONFLICTS> takes it exclusively and C<SHARES> takes
777 it shared.
778
779 XXX can be replaced with any type of your choosing, and you may set several
780 of them.
781
782 The usual shape for this is one test that disturbs a resource and many that
783 merely read it: mark the disruptive one C<HARNESS-CONFLICTS-XXX> and the
784 rest C<HARNESS-SHARES-XXX>, and the readers keep their parallelism instead
785 of being serialized alongside the writer.
786
787 NOTE: An exclusive test has to wait for every shared test holding the name
788 to finish, and C<yath> will not hold job slots empty to make room for it. If
789 shared tests keep becoming available the exclusive one may run quite late in
790 the run, possibly last and by itself. This is still better than marking
791 every test C<CONFLICTS>, but it is worth knowing before you mark hundreds of
792 tests as sharing one name.
793
794 NOTE: This directive does not alter the category of your test. You are free
795 to mark the test with LONG or MEDIUM in addition to this marker.
796
797 =head3 HARNESS-JOB-SLOTS 2
798
799 =head3 HARNESS-JOB-SLOTS 1 10
800
801 Specify a range of job slots needed for the test to run. If set to a single
802 value then the test will only run if it can have the specified number of slots.
803 If given a range the test will require at least the lower number of slots, and
804 use up to the maximum number of slots.
805
806 =head3 HARNESS-RETRY-n
807
808 This lets you specify a number (minimum n=1) of retries on test failure
809 for a specific test. HARNESS-RETRY-1 means a failing test will be run twice
810 and is equivalent to HARNESS-RETRY.
811
812 =head3 HARNESS-NO-RETRY
813
814 Use this to avoid this test being retried regardless of your retry settings.
815
816 =head1 MODULE DOCS
817
818 This section documents the L<App::Yath> module itself.
819
820 =head2 SYNOPSIS
821
822 In practice you should never need to write your own yath script, or construct
823 an L<App::Yath> instance, or even access the main instance when yath is running.
824 However some aspects of doing so are documented here for completeness.
825
826 A minimum yath script looks like this:
827
828 BEGIN {
829 package App::Yath:Script;
830
831 require Time::HiRes;
832 require App::Yath;
833 require Test2::Harness::Settings;
834
835 my $settings = Test2::Harness::Settings->new(
836 harness => {
837 orig_argv => [@ARGV],
838 orig_inc => [grep { !ref($_) } @INC],
839 script => __FILE__,
840 start => Time::HiRes::time(),
841 version => $App::Yath::VERSION,
842 },
843 );
844
845 my $app = App::Yath->new(
846 argv => \@ARGV,
847 config => {},
848 settings => $settings,
849 );
850
851 $app->generate_run_sub('App::Yath::Script::run');
852 }
853
854 exit(App::Yath::Script::run());
855
856 It is important that most logic live in a BEGIN block. This is so that
857 L<goto::file> can be used post-fork to execute a test script.
858
859 The actual yath script is significantly more complicated with the following behaviors:
860
861 =over 4
862
863 =item pre-process essential arguments such as -D and no-scan-plugins
864
865 =item re-exec with a different yath script if in developer mode and a local copy is found
866
867 =item Parse the yath-rc config files
868
869 =item gather and store essential startup information
870
871 =back
872
873 =head2 METHODS
874
875 App::Yath does not provide many methods to use externally.
876
877 =over 4
878
879 =item $app->generate_run_sub($symbol_name)
880
881 This tells App::Yath to generate a subroutine at the specified symbol name
882 which can be run and be expected to return an exit value.
883
884 =item $lib_path = $app->app_path()
885
886 Get the include directory App::Yath was loaded from.
887
888 =back
889
890 =head1 SOURCE
891
892 The source code repository for Test2-Harness can be found at
893 F<http://github.com/Test-More/Test2-Harness/>.
894
895 =head1 MAINTAINERS
896
897 =over 4
898
899 =item Chad Granum E<lt>[email protected]<gt>
900
901 =back
902
903 =head1 AUTHORS
904
905 =over 4
906
907 =item Chad Granum E<lt>[email protected]<gt>
908
909 =back
910
911 =head1 COPYRIGHT
912
913 Copyright 2020 Chad Granum E<lt>[email protected]<gt>.
914
915 This program is free software; you can redistribute it and/or
916 modify it under the same terms as Perl itself.
917
918 See F<http://dev.perl.org/licenses/>
919
920 =cut