Debian Codegraph @

README

raw
1 NAME
2
3 App::Yath - Yet Another Test Harness (Test2-Harness) Command Line
4 Interface (CLI)
5
6 DESCRIPTION
7
8 This is the primary documentation for yath, App::Yath, Test2::Harness.
9
10 The canonical source of up-to-date command options are the help output
11 when using $ yath help and $ yath help COMMAND.
12
13 This document is mainly an overview of yath usage and common recipes.
14
15 App::Yath is an alternative to App::Prove, and Test2::Harness is an
16 alternative to Test::Harness. It is not designed to replace
17 Test::Harness/prove. Test2::Harness is designed to take full advantage
18 of the rich data Test2 can provide. Test2::Harness is also able to use
19 non-core modules and provide more functionality than prove can achieve
20 with its restrictions.
21
22 PLATFORM SUPPORT
23
24 Test2::Harness/App::Yath is is focused on unix-like platforms. Most
25 development happens on linux, but bsd, macos, etc should work fine as
26 well.
27
28 Patches are welcome for any/all platforms, but the primary author (Chad
29 'Exodist' Granum) does not directly develop against non-unix platforms.
30
31 WINDOWS
32
33 Currently windows is not supported, and it is known that the package
34 will not install on windows. Patches are be welcome, and it would be
35 great if someone wanted to take on the windows-support role, but it is
36 not a primary goal for the project.
37
38 OVERVIEW
39
40 To use Test2::Harness, you use the yath command. Yath will find the
41 tests (or use the ones you specify) and run them. As it runs, it will
42 output diagnostic information such as failures. At the end, yath will
43 print a summary of the test run.
44
45 yath can be thought of as a more powerful alternative to prove
46 (Test::Harness)
47
48 RECIPES
49
50 These are common recipes for using yath.
51
52 RUN PROJECT TESTS
53
54 $ yath
55
56 Simply running yath with no arguments means "Run all tests for the
57 current project". Yath will look for tests in ./t, ./t2, and ./test.pl
58 and run any which are found.
59
60 Normally this implies the test command but will instead imply the run
61 command if a persistent test runner is detected.
62
63 PRELOAD MODULES
64
65 Yath has the ability to preload modules. Yath normally forks to start
66 new tests, so preloading can reduce the time spent loading modules over
67 and over in each test.
68
69 Note that some tests may depend on certain modules not being loaded. In
70 these cases you can add the # HARNESS-NO-PRELOAD directive to the top
71 of the test files that cannot use preload.
72
73 SIMPLE PRELOAD
74
75 Any module can be preloaded:
76
77 $ yath -PMoose
78
79 You can preload as many modules as you want:
80
81 $ yath -PList::Util -PScalar::Util
82
83 COMPLEX PRELOAD
84
85 If your preload is a subclass of Test2::Harness::Runner::Preload then
86 more complex preload behavior is possible. See those docs for more
87 info.
88
89 LOGGING
90
91 RECORDING A LOG
92
93 You can turn on logging with a flag. The filename of the log will be
94 printed at the end.
95
96 $ yath -L
97 ...
98 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl
99
100 The event log can be quite large. It can be compressed with bzip2.
101
102 $ yath -B
103 ...
104 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2
105
106 gzip compression is also supported.
107
108 $ yath -G
109 ...
110 Wrote log file: test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.gz
111
112 -B and -G both imply -L.
113
114 REPLAYING FROM A LOG
115
116 You can replay a test run from a log file:
117
118 $ yath test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2
119
120 This will be significantly faster than the initial run as no tests are
121 actually being executed. All events are simply read from the log, and
122 processed by the harness.
123
124 You can change display options and limit rendering/processing to
125 specific test jobs from the run:
126
127 $ yath test-logs/2017-09-12~22:44:34~1505281474~25709.jsonl.bz2 -v [TEST UUID(S)]
128
129 Note: This is done using the $ yath replay ... command. The replay
130 command is implied if the first argument is a log file.
131
132 PER-TEST TIMING DATA
133
134 The -T option will cause each test file to report how long it took to
135 run.
136
137 $ yath -T
138
139 ( PASSED ) job 1 t/yath_script.t
140 ( TIME ) job 1 Startup: 0.07692s | Events: 0.01170s | Cleanup: 0.00190s | Total: 0.09052s
141
142 PERSISTENT RUNNER
143
144 yath supports starting a yath session that waits for tests to run. This
145 is very useful when combined with preload.
146
147 STARTING
148
149 This starts the server. Many options available to the 'test' command
150 will work here but not all. See $ yath help start for more info.
151
152 $ yath start
153
154 RUNNING
155
156 This will run tests using the persistent runner. By default, it will
157 search for tests just like the 'test' command. Many options available
158 to the test command will work for this as well. See $ yath help run for
159 more details.
160
161 $ yath run
162
163 STOPPING
164
165 Stopping a persistent runner is easy.
166
167 $ yath stop
168
169 INFORMATIONAL
170
171 The which command will tell you which persistent runner will be used.
172 Yath searches for the persistent runner in the current directory, then
173 searches in parent directories until it either hits the root directory,
174 or finds the persistent runner tracking file.
175
176 $ yath which
177
178 The watch command will tail the runner's log files.
179
180 $ yath watch
181
182 PRELOAD + PERSISTENT RUNNER
183
184 You can use preloads with the yath start command. In this case, yath
185 will track all the modules pulled in during preload. If any of them
186 change, the server will reload itself to bring in the changes. Further,
187 modified modules will be blacklisted so that they are not preloaded on
188 subsequent reloads. This behavior is useful if you are actively working
189 on a module that is normally preloaded.
190
191 MAKING YOUR PROJECT ALWAYS USE YATH
192
193 $ yath init
194
195 The above command will create test.pl. test.pl is automatically run by
196 most build utils, in which case only the exit value matters. The
197 generated test.pl will run yath and execute all tests in the ./t and/or
198 ./t2 directories. Tests in ./t will ALSO be run by prove but tests in
199 ./t2 will only be run by yath.
200
201 PROJECT-SPECIFIC YATH CONFIG
202
203 You can write a .yath.rc file. The file format is very simple. Create a
204 [COMMAND] section to start the configuration for a command and then
205 provide any options normally allowed by it. When yath is run inside
206 your project, it will use the config specified in the rc file, unless
207 overridden by command line options.
208
209 Note: You can also add pre-command options by placing them at the top
210 of your config file BEFORE any [cmd] markers.
211
212 Comments start with a semi-colon.
213
214 Example .yath.rc:
215
216 -pFoo ; Load the 'foo' plugin before dealing with commands.
217
218 [test]
219 -B ;Always write a bzip2-compressed log
220
221 [start]
222 -PMoose ;Always preload Moose with a persistent runner
223
224 This file is normally committed into the project's repo.
225
226 SPECIAL PATH PSEUDO-FUNCTIONS
227
228 Sometimes you want to specify files relative to the .yath.rc so that
229 the config option works from any subdirectory of the project. Other
230 times you may wish to use a shell expansion. Sometimes you want both!
231
232 rel(path/to/file)
233
234 -I rel(path/to/extra_lib)
235 -I=rel(path/to/extra_lib)
236
237 This will take the path to .yath.rc and prefix it to the path inside
238 rel(...). If for example you have /project/.yath.rc then the path
239 would become /project/path/to/extra_lib.
240
241 glob(path/*/file)
242
243 --default-search glob(subprojects/*/t)
244 --default-search=glob(subprojects/*/t)
245
246 This will add a --default-search $_ for every item found in the glob.
247 This uses the perl builtin function glob() under the hood.
248
249 relglob(path/*/file)
250
251 --default-search relglob(subprojects/*/t)
252 --default-search=relglob(subprojects/*/t)
253
254 Same as glob() except paths are relative to the .yath.rc file.
255
256 PROJECT-SPECIFIC YATH CONFIG USER OVERRIDES
257
258 You can add a .yath.user.rc file. Format is the same as the regular
259 .yath.rc file. This file will be read in addition to the regular config
260 file. Directives in this file will come AFTER the directives in the
261 primary config so it may be used to override config.
262
263 This file should not normally be committed to the project repo.
264
265 HARNESS DIRECTIVES INSIDE TESTS
266
267 yath will recognise a number of directive comments placed near the top
268 of test files. These directives should be placed after the #! line but
269 before any real code.
270
271 Real code is defined as any line that does not start with use, require,
272 BEGIN, package, or #
273
274 good example 1
275
276 #!/usr/bin/perl
277 # HARNESS-NO-FORK
278
279 ...
280
281 good example 2
282
283 #!/usr/bin/perl
284 use strict;
285 use warnings;
286
287 # HARNESS-NO-FORK
288
289 ...
290
291 bad example 1
292
293 #!/usr/bin/perl
294
295 # blah
296
297 # HARNESS-NO-FORK
298
299 ...
300
301 bad example 2
302
303 #!/usr/bin/perl
304
305 print "hi\n";
306
307 # HARNESS-NO-FORK
308
309 ...
310
311 HARNESS-NO-PRELOAD
312
313 #!/usr/bin/perl
314 # HARNESS-NO-PRELOAD
315
316 Use this if your test will fail when modules are preloaded. This will
317 tell yath to start a new perl process to run the script instead of
318 forking with preloaded modules.
319
320 Currently this implies HARNESS-NO-FORK, but that may not always be the
321 case.
322
323 HARNESS-NO-FORK
324
325 #!/usr/bin/perl
326 # HARNESS-NO-FORK
327
328 Use this if your test file cannot run in a forked process, but instead
329 must be run directly with a new perl process.
330
331 This implies HARNESS-NO-PRELOAD.
332
333 HARNESS-NO-STREAM
334
335 yath usually uses the Test2::Formatter::Stream formatter instead of
336 TAP. Some tests depend on using a TAP formatter. This option will make
337 yath use Test2::Formatter::TAP or Test::Builder::Formatter.
338
339 HARNESS-NO-IO-EVENTS
340
341 yath can be configured to use the Test2::Plugin::IOEvents plugin. This
342 plugin replaces STDERR and STDOUT in your test with tied handles that
343 fire off proper Test2::Event's when they are printed to. Most of the
344 time this is not an issue, but any fancy tests or modules which do
345 anything with STDERR or STDOUT other than print may have really messy
346 errors.
347
348 Note: This plugin is disabled by default, so you only need this
349 directive if you enable it globally but need to turn it back off for
350 select tests.
351
352 HARNESS-NO-TIMEOUT
353
354 yath will usually kill a test if no events occur within a timeout
355 (default 60 seconds). You can add this directive to tests that are
356 expected to trip the timeout, but should be allowed to continue.
357
358 NOTE: you usually are doing the wrong thing if you need to set this.
359 See: HARNESS-TIMEOUT-EVENT.
360
361 HARNESS-TIMEOUT-EVENT 60
362
363 yath can be told to alter the default event timeout from 60 seconds to
364 another value. This is the recommended alternative to
365 HARNESS-NO-TIMEOUT
366
367 HARNESS-TIMEOUT-POSTEXIT 15
368
369 yath can be told to alter the default POSTEXIT timeout from 15 seconds
370 to another value.
371
372 Sometimes a test will fork producing output in the child while the
373 parent is allowed to exit. In these cases we cannot rely on the
374 original process exit to tell us when a test is complete. In cases
375 where we have an exit, and partial output (assertions with no final
376 plan, or a plan that has not been completed) we wait for a timeout
377 period to see if any additional events come into
378
379 HARNESS-DURATION-LONG
380
381 This lets you tell yath that the test file is long-running. This is
382 primarily used when concurrency is turned on in order to run longer
383 tests earlier, and concurrently with shorter ones. There is also a yath
384 option to skip all long tests.
385
386 This duration is set automatically if HARNESS-NO-TIMEOUT is set.
387
388 HARNESS-DURATION-MEDIUM
389
390 This lets you tell yath that the test is medium.
391
392 This is the default duration.
393
394 HARNESS-DURATION-SHORT
395
396 This lets you tell yath That the test is short.
397
398 HARNESS-CATEGORY-ISOLATION
399
400 This lets you tell yath that the test cannot be run concurrently with
401 other tests. Yath will hold off and run these tests one at a time after
402 all other tests.
403
404 HARNESS-CATEGORY-IMMISCIBLE
405
406 This lets you tell yath that the test cannot be run concurrently with
407 other tests of this class. This is helpful when you have multiple tests
408 which would otherwise have to be run sequentially at the end of the
409 run.
410
411 Yath prioritizes running these tests above HARNESS-CATEGORY-LONG.
412
413 HARNESS-CATEGORY-GENERAL
414
415 This is the default category.
416
417 HARNESS-CONFLICTS-XXX
418
419 This lets you tell yath that no other test of type XXX can be run at
420 the same time as this one. You are able to set multiple conflict types
421 and yath will honor them.
422
423 XXX can be replaced with any type of your choosing.
424
425 NOTE: This directive does not alter the category of your test. You are
426 free to mark the test with LONG or MEDIUM in addition to this marker.
427
428 Example with multiple lines.
429
430 #!/usr/bin/perl
431 # DASH and space are split the same way.
432 # HARNESS-CONFLICTS-DAEMON
433 # HARNESS-CONFLICTS MYSQL
434
435 ...
436
437 Or on a single line.
438
439 #!/usr/bin/perl
440 # HARNESS-CONFLICTS DAEMON MYSQL
441
442 ...
443
444 HARNESS-SHARES-XXX
445
446 This lets you tell yath that this test uses XXX, but is happy to share
447 it with other tests that merely use it too. Any number of
448 HARNESS-SHARES-XXX tests may run at the same time, but none of them
449 will run at the same time as a HARNESS-CONFLICTS-XXX test. If you think
450 of the two directives as a lock on the name XXX, CONFLICTS takes it
451 exclusively and SHARES takes it shared.
452
453 XXX can be replaced with any type of your choosing, and you may set
454 several of them.
455
456 The usual shape for this is one test that disturbs a resource and many
457 that merely read it: mark the disruptive one HARNESS-CONFLICTS-XXX and
458 the rest HARNESS-SHARES-XXX, and the readers keep their parallelism
459 instead of being serialized alongside the writer.
460
461 NOTE: An exclusive test has to wait for every shared test holding the
462 name to finish, and yath will not hold job slots empty to make room for
463 it. If shared tests keep becoming available the exclusive one may run
464 quite late in the run, possibly last and by itself. This is still
465 better than marking every test CONFLICTS, but it is worth knowing
466 before you mark hundreds of tests as sharing one name.
467
468 NOTE: This directive does not alter the category of your test. You are
469 free to mark the test with LONG or MEDIUM in addition to this marker.
470
471 HARNESS-JOB-SLOTS 2
472
473 HARNESS-JOB-SLOTS 1 10
474
475 Specify a range of job slots needed for the test to run. If set to a
476 single value then the test will only run if it can have the specified
477 number of slots. If given a range the test will require at least the
478 lower number of slots, and use up to the maximum number of slots.
479
480 HARNESS-RETRY-n
481
482 This lets you specify a number (minimum n=1) of retries on test failure
483 for a specific test. HARNESS-RETRY-1 means a failing test will be run
484 twice and is equivalent to HARNESS-RETRY.
485
486 HARNESS-NO-RETRY
487
488 Use this to avoid this test being retried regardless of your retry
489 settings.
490
491 MODULE DOCS
492
493 This section documents the App::Yath module itself.
494
495 SYNOPSIS
496
497 In practice you should never need to write your own yath script, or
498 construct an App::Yath instance, or even access the main instance when
499 yath is running. However some aspects of doing so are documented here
500 for completeness.
501
502 A minimum yath script looks like this:
503
504 BEGIN {
505 package App::Yath:Script;
506
507 require Time::HiRes;
508 require App::Yath;
509 require Test2::Harness::Settings;
510
511 my $settings = Test2::Harness::Settings->new(
512 harness => {
513 orig_argv => [@ARGV],
514 orig_inc => [grep { !ref($_) } @INC],
515 script => __FILE__,
516 start => Time::HiRes::time(),
517 version => $App::Yath::VERSION,
518 },
519 );
520
521 my $app = App::Yath->new(
522 argv => \@ARGV,
523 config => {},
524 settings => $settings,
525 );
526
527 $app->generate_run_sub('App::Yath::Script::run');
528 }
529
530 exit(App::Yath::Script::run());
531
532 It is important that most logic live in a BEGIN block. This is so that
533 goto::file can be used post-fork to execute a test script.
534
535 The actual yath script is significantly more complicated with the
536 following behaviors:
537
538 pre-process essential arguments such as -D and no-scan-plugins
539
540 re-exec with a different yath script if in developer mode and a local
541 copy is found
542
543 Parse the yath-rc config files
544
545 gather and store essential startup information
546
547 METHODS
548
549 App::Yath does not provide many methods to use externally.
550
551 $app->generate_run_sub($symbol_name)
552
553 This tells App::Yath to generate a subroutine at the specified symbol
554 name which can be run and be expected to return an exit value.
555
556 $lib_path = $app->app_path()
557
558 Get the include directory App::Yath was loaded from.
559
560 SOURCE
561
562 The source code repository for Test2-Harness can be found at
563 http://github.com/Test-More/Test2-Harness/.
564
565 MAINTAINERS
566
567 Chad Granum <[email protected]>
568
569 AUTHORS
570
571 Chad Granum <[email protected]>
572
573 COPYRIGHT
574
575 Copyright 2020 Chad Granum <[email protected]>.
576
577 This program is free software; you can redistribute it and/or modify it
578 under the same terms as Perl itself.
579
580 See http://dev.perl.org/licenses/
581