Debian Codegraph @

lib/App/Yath/Command/init.pm

raw
1 package App::Yath::Command::init;
2 use strict;
3 use warnings;
4
5 use parent 'App::Yath::Command';
6
7 our $VERSION = '1.000179';
8
9 use Test2::Harness::Util qw/open_file/;
10 use App::Yath::Util qw/is_generated_test_pl/;
11
12 sub group { 'zinit' }
13
14 sub summary { "Create/update test.pl to run tests via Test2::Harness" }
15
16 sub description {
17 return <<" EOT";
18 This command will create or update the 'test.pl' file in the current directory.
19 This 'test.pl' file this creates will run all your tests via yath.
20
21 This command will fail if there is already a test.pl file that does not look
22 like it was generated by this command.
23 EOT
24 }
25
26 sub run {
27 die "'test.pl' already exists, and does not appear to be a yath runner.\n"
28 if -f 'test.pl' && !is_generated_test_pl('test.pl');
29
30 print "\nWriting test.pl...\n\n";
31
32 my $fh = open_file('test.pl', '>');
33
34 print $fh <<' EOT';
35 #!/usr/bin/env perl
36 # HARNESS-NO-PRELOAD
37 # HARNESS-CAT-LONG
38 # THIS IS A GENERATED YATH RUNNER TEST
39 use strict;
40 use warnings;
41
42 use lib 'lib';
43 use App::Yath::Util qw/find_yath/;
44
45 system($^X, find_yath(), '-D', 'test', '--default-search' => './t', '--default-search' => './t2', @ARGV);
46 my $exit = $?;
47
48 # This makes sure it works with prove.
49 print "1..1\n";
50 print "not " if $exit;
51 print "ok 1 - Passed tests when run by yath\n";
52 print STDERR "yath exited with $exit" if $exit;
53
54 exit($exit ? 255 : 0);
55 EOT
56
57 return 0;
58 }
59
60 1;
61
62
63 __END__
64
65 =pod
66
67 =encoding UTF-8
68
69 =head1 NAME
70
71 App::Yath::Command::init - Create/update test.pl to run tests via Test2::Harness
72
73 =head1 DESCRIPTION
74
75 This command will create or update the 'test.pl' file in the current directory.
76 This 'test.pl' file this creates will run all your tests via yath.
77
78 This command will fail if there is already a test.pl file that does not look
79 like it was generated by this command.
80
81
82 =head1 USAGE
83
84 $ yath [YATH OPTIONS] init [COMMAND OPTIONS]
85
86 =head2 YATH OPTIONS
87
88 =head3 Developer
89
90 =over 4
91
92 =item --dev-lib
93
94 =item --dev-lib=lib
95
96 =item -D
97
98 =item -D=lib
99
100 =item -Dlib
101
102 =item --no-dev-lib
103
104 Add paths to @INC before loading ANYTHING. This is what you use if you are developing yath or yath plugins to make sure the yath script finds the local code instead of the installed versions of the same code. You can provide an argument (-Dfoo) to provide a custom path, or you can just use -D without and arg to add lib, blib/lib and blib/arch.
105
106 Can be specified multiple times
107
108
109 =back
110
111 =head3 Environment
112
113 =over 4
114
115 =item --persist-dir ARG
116
117 =item --persist-dir=ARG
118
119 =item --no-persist-dir
120
121 Where to find persistence files.
122
123
124 =item --persist-file ARG
125
126 =item --persist-file=ARG
127
128 =item --pfile ARG
129
130 =item --pfile=ARG
131
132 =item --no-persist-file
133
134 Where to find the persistence file. The default is /{system-tempdir}/project-yath-persist.json. If no project is specified then it will fall back to the current directory. If the current directory is not writable it will default to /tmp/yath-persist.json which limits you to one persistent runner on your system.
135
136
137 =item --project ARG
138
139 =item --project=ARG
140
141 =item --project-name ARG
142
143 =item --project-name=ARG
144
145 =item --no-project
146
147 This lets you provide a label for your current project/codebase. This is best used in a .yath.rc file. This is necessary for a persistent runner.
148
149
150 =back
151
152 =head3 Help and Debugging
153
154 =over 4
155
156 =item --show-opts
157
158 =item --no-show-opts
159
160 Exit after showing what yath thinks your options mean
161
162
163 =item --version
164
165 =item -V
166
167 =item --no-version
168
169 Exit after showing a helpful usage message
170
171
172 =back
173
174 =head3 Plugins
175
176 =over 4
177
178 =item --no-scan-plugins
179
180 =item --no-no-scan-plugins
181
182 Normally yath scans for and loads all App::Yath::Plugin::* modules in order to bring in command-line options they may provide. This flag will disable that. This is useful if you have a naughty plugin that is loading other modules when it should not.
183
184
185 =item --plugins PLUGIN
186
187 =item --plugins +App::Yath::Plugin::PLUGIN
188
189 =item --plugins PLUGIN=arg1,arg2,...
190
191 =item --plugin PLUGIN
192
193 =item --plugin +App::Yath::Plugin::PLUGIN
194
195 =item --plugin PLUGIN=arg1,arg2,...
196
197 =item -pPLUGIN
198
199 =item --no-plugins
200
201 Load a yath plugin.
202
203 Can be specified multiple times
204
205
206 =back
207
208 =head2 COMMAND OPTIONS
209
210 =head3 Cover Options
211
212 =over 4
213
214 =item --cover-aggregator ByTest
215
216 =item --cover-aggregator ByRun
217
218 =item --cover-aggregator +Custom::Aggregator
219
220 =item --cover-agg ByTest
221
222 =item --cover-agg ByRun
223
224 =item --cover-agg +Custom::Aggregator
225
226 =item --no-cover-aggregator
227
228 Choose a custom aggregator subclass
229
230
231 =item --cover-class ARG
232
233 =item --cover-class=ARG
234
235 =item --no-cover-class
236
237 Choose a Test2::Plugin::Cover subclass
238
239
240 =item --cover-dirs ARG
241
242 =item --cover-dirs=ARG
243
244 =item --cover-dir ARG
245
246 =item --cover-dir=ARG
247
248 =item --no-cover-dirs
249
250 NO DESCRIPTION - FIX ME
251
252 Can be specified multiple times
253
254
255 =item --cover-exclude-dirs ARG
256
257 =item --cover-exclude-dirs=ARG
258
259 =item --cover-exclude-dir ARG
260
261 =item --cover-exclude-dir=ARG
262
263 =item --no-cover-exclude-dirs
264
265 Directory to leave out of file coverage and coverage metrics, along with everything under it at any depth. May be specified multiple times. Wildcards are expanded when the option is parsed, so a pattern matching nothing excludes nothing. Values are word-split first, so a path containing whitespace must be quoted or backslash-escaped. A resolved path may not contain a comma.
266
267 Can be specified multiple times
268
269
270 =item --cover-exclude-private
271
272 =item --no-cover-exclude-private
273
274
275
276
277 =item --cover-files
278
279 =item --no-cover-files
280
281 Use Test2::Plugin::Cover to collect coverage data for what files are touched by what tests. Unlike Devel::Cover this has very little performance impact (About 4% difference)
282
283
284 =item --cover-from path/to/log.jsonl
285
286 =item --cover-from http://example.com/coverage
287
288 =item --cover-from path/to/coverage.jsonl
289
290 =item --no-cover-from
291
292 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will not be run if the file/url is invalid.
293
294
295 =item --cover-from-type json
296
297 =item --cover-from-type jsonl
298
299 =item --cover-from-type log
300
301 =item --no-cover-from-type
302
303 File type for coverage source. Usually it can be detected, but when it cannot be you should specify. "json" is old style single-blob coverage data, "jsonl" is the new by-test style, "log" is a logfile from a previous run.
304
305
306 =item --cover-manager My::Coverage::Manager
307
308 =item --no-cover-manager
309
310 Coverage 'from' manager to use when coverage data does not provide one
311
312
313 =item --cover-maybe-from path/to/log.jsonl
314
315 =item --cover-maybe-from http://example.com/coverage
316
317 =item --cover-maybe-from path/to/coverage.jsonl
318
319 =item --no-cover-maybe-from
320
321 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will continue even if the coverage file/url is invalid.
322
323
324 =item --cover-maybe-from-type json
325
326 =item --cover-maybe-from-type jsonl
327
328 =item --cover-maybe-from-type log
329
330 =item --no-cover-maybe-from-type
331
332 Same as "from_type" but for "maybe_from". Defaults to "from_type" if that is specified, otherwise auto-detect
333
334
335 =item --cover-metrics
336
337 =item --no-cover-metrics
338
339
340
341
342 =item --cover-types ARG
343
344 =item --cover-types=ARG
345
346 =item --cover-type ARG
347
348 =item --cover-type=ARG
349
350 =item --no-cover-types
351
352 NO DESCRIPTION - FIX ME
353
354 Can be specified multiple times
355
356
357 =item --cover-write
358
359 =item --cover-write=coverage.jsonl
360
361 =item --cover-write=coverage.json
362
363 =item --no-cover-write
364
365 Create a json or jsonl file of all coverage data seen during the run (This implies --cover-files).
366
367
368 =back
369
370 =head3 Git Options
371
372 =over 4
373
374 =item --git-change-base master
375
376 =item --git-change-base HEAD^
377
378 =item --git-change-base df22abe4
379
380 =item --no-git-change-base
381
382 Find files changed by all commits in the current branch from most recent stopping when a commit is found that is also present in the history of the branch/commit specified as the change base.
383
384
385 =back
386
387 =head3 Help and Debugging
388
389 =over 4
390
391 =item --dummy
392
393 =item -d
394
395 =item --no-dummy
396
397 Dummy run, do not actually execute anything
398
399 Can also be set with the following environment variables: C<T2_HARNESS_DUMMY>
400
401
402 =item --help
403
404 =item -h
405
406 =item --no-help
407
408 exit after showing help information
409
410
411 =item --interactive
412
413 =item -i
414
415 =item --no-interactive
416
417 Use interactive mode, 1 test at a time, stdin forwarded to it
418
419
420 =item --keep-dirs
421
422 =item --keep_dir
423
424 =item -k
425
426 =item --no-keep-dirs
427
428 Do not delete directories when done. This is useful if you want to inspect the directories used for various commands.
429
430
431 =item --procname-prefix ARG
432
433 =item --procname-prefix=ARG
434
435 =item --no-procname-prefix
436
437 Add a prefix to all proc names (as seen by ps).
438
439
440 =back
441
442 =head3 YathUI Options
443
444 =over 4
445
446 =item --yathui-api-key ARG
447
448 =item --yathui-api-key=ARG
449
450 =item --no-yathui-api-key
451
452 Yath-UI API key. This is not necessary if your Yath-UI instance is set to single-user
453
454
455 =item --yathui-grace
456
457 =item --no-yathui-grace
458
459 If yath cannot connect to yath-ui it normally throws an error, use this to make it fail gracefully. You get a warning, but things keep going.
460
461
462 =item --yathui-long-duration 10
463
464 =item --no-yathui-long-duration
465
466 Minimum duration length (seconds) before a test goes from MEDIUM to LONG
467
468
469 =item --yathui-medium-duration 5
470
471 =item --no-yathui-medium-duration
472
473 Minimum duration length (seconds) before a test goes from SHORT to MEDIUM
474
475
476 =item --yathui-mode summary
477
478 =item --yathui-mode qvf
479
480 =item --yathui-mode qvfd
481
482 =item --yathui-mode complete
483
484 =item --no-yathui-mode
485
486 Set the upload mode (default 'qvfd')
487
488
489 =item --yathui-project ARG
490
491 =item --yathui-project=ARG
492
493 =item --no-yathui-project
494
495 The Yath-UI project for your test results
496
497
498 =item --yathui-retry
499
500 =item --no-yathui-retry
501
502 How many times to try an operation before giving up
503
504 Can be specified multiple times
505
506
507 =item --yathui-url http://my-yath-ui.com/...
508
509 =item --uri http://my-yath-ui.com/...
510
511 =item --no-yathui-url
512
513 Yath-UI url
514
515
516 =back
517
518 =head1 SOURCE
519
520 The source code repository for Test2-Harness can be found at
521 F<http://github.com/Test-More/Test2-Harness/>.
522
523 =head1 MAINTAINERS
524
525 =over 4
526
527 =item Chad Granum E<lt>[email protected]<gt>
528
529 =back
530
531 =head1 AUTHORS
532
533 =over 4
534
535 =item Chad Granum E<lt>[email protected]<gt>
536
537 =back
538
539 =head1 COPYRIGHT
540
541 Copyright 2026 Chad Granum E<lt>[email protected]<gt>.
542
543 This program is free software; you can redistribute it and/or
544 modify it under the same terms as Perl itself.
545
546 See F<http://dev.perl.org/licenses/>
547
548 =cut
549