-
Notifications
You must be signed in to change notification settings - Fork 26
/
test.pm
927 lines (714 loc) · 24.4 KB
/
test.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
package App::Yath::Command::test;
use strict;
use warnings;
our $VERSION = '1.000156';
use App::Yath::Options;
use Test2::Harness::Run;
use Test2::Harness::Event;
use Test2::Harness::Util::Queue;
use Test2::Harness::Util::File::JSON;
use Test2::Harness::IPC;
use Test2::Harness::Runner::State;
use Test2::Harness::Util::JSON qw/encode_json decode_json JSON/;
use Test2::Harness::Util qw/mod2file open_file chmod_tmp/;
use Test2::Util::Table qw/table/;
use Test2::Harness::Util::Term qw/USE_ANSI_COLOR/;
use File::Spec;
use Fcntl();
use Time::HiRes qw/sleep time/;
use List::Util qw/sum max min/;
use Carp qw/croak/;
use parent 'App::Yath::Command';
use Test2::Harness::Util::HashBase qw/
<runner_pid +ipc +signal
+run <run_id
+auditor_reader
+collector_writer
+renderer_reader
+auditor_writer
+renderers
+logger
+last_log
+tests_seen
+asserts_seen
+run_queue
+tasks_queue
+state
<cleanup_subs
<final_data
/;
include_options(
'App::Yath::Options::Debug',
'App::Yath::Options::Display',
'App::Yath::Options::Finder',
'App::Yath::Options::Logging',
'App::Yath::Options::PreCommand',
'App::Yath::Options::Run',
'App::Yath::Options::Runner',
'App::Yath::Options::Workspace',
'App::Yath::Options::Collector',
);
sub MAX_ATTACH() { 1_048_576 }
sub group { ' test' }
sub summary { "Run tests" }
sub cli_args { '[--] [test files/dirs] [::] [arguments to test scripts] [test_file.t] [test_file2.t="--arg1 --arg2 --param=\'foo bar\'"] [:: --argv-for-all-tests]' }
sub description {
return <<" EOT";
This yath command (which is also the default command) will run all the test
files for the current project. If no test files are specified this command will
look for the 't', and 't2' directories, as well as the 'test.pl' file.
This command is always recursive when given directories.
This command will add 'lib', 'blib/arch' and 'blib/lib' to the perl path for
you by default (after any -I's). You can specify -l if you just want lib, -b if
you just want the blib paths. If you specify both -l and -b both will be added
in the order you specify (order relative to any -I options will also be
preserved. If you do not specify they will be added in this order: -I's, lib,
blib/lib, blib/arch. You can also add --no-lib and --no-blib to avoid both.
Any command line argument that is not an option will be treated as a test file
or directory of test files to be run.
If you wish to specify the ARGV for tests you may append them after '::'. This
is mainly useful for Test::Class::Moose and similar tools. EVERY test run will
get the same ARGV.
EOT
}
sub spawn_args {
my $self = shift;
my ($settings) = @_;
my @out;
if ($ENV{T2_DEVEL_COVER} && $ENV{T2_COVER_SELF}) {
push @out => '-MDevel::Cover=-silent,1,+ignore,^t/,+ignore,^t2/,+ignore,^xt,+ignore,^test.pl';
}
my $plugins = $settings->harness->plugins;
if (@$plugins) {
push @out => $_->spawn_args($settings) for grep { $_->can('spawn_args') } @$plugins;
}
return @out;
}
sub init {
my $self = shift;
$self->SUPER::init() if $self->can('SUPER::init');
$self->{+TESTS_SEEN} //= 0;
$self->{+ASSERTS_SEEN} //= 0;
$self->{+CLEANUP_SUBS} = [];
}
sub _resize_pipe {
return unless defined &Fcntl::F_SETPIPE_SZ;
my ($fh) = @_;
# 1mb if we can
my $size = 1024 * 1024 * 1;
# On linux systems lets go for the smaller of the two between 1mb and
# system max.
if (-e '/proc/sys/fs/pipe-max-size') {
open(my $max, '<', '/proc/sys/fs/pipe-max-size');
chomp(my $val = <$max>);
close($max);
$size = min($size, $val);
}
fcntl($fh, Fcntl::F_SETPIPE_SZ(), $size);
}
sub auditor_reader {
my $self = shift;
return $self->{+AUDITOR_READER} if $self->{+AUDITOR_READER};
pipe($self->{+AUDITOR_READER}, $self->{+COLLECTOR_WRITER}) or die "Could not create pipe: $!";
_resize_pipe($self->{+COLLECTOR_WRITER});
return $self->{+AUDITOR_READER};
}
sub collector_writer {
my $self = shift;
return $self->{+COLLECTOR_WRITER} if $self->{+COLLECTOR_WRITER};
pipe($self->{+AUDITOR_READER}, $self->{+COLLECTOR_WRITER}) or die "Could not create pipe: $!";
_resize_pipe($self->{+COLLECTOR_WRITER});
return $self->{+COLLECTOR_WRITER};
}
sub renderer_reader {
my $self = shift;
return $self->{+RENDERER_READER} if $self->{+RENDERER_READER};
pipe($self->{+RENDERER_READER}, $self->{+AUDITOR_WRITER}) or die "Could not create pipe: $!";
_resize_pipe($self->{+AUDITOR_WRITER});
return $self->{+RENDERER_READER};
}
sub auditor_writer {
my $self = shift;
return $self->{+AUDITOR_WRITER} if $self->{+AUDITOR_WRITER};
pipe($self->{+RENDERER_READER}, $self->{+AUDITOR_WRITER}) or die "Could not create pipe: $!";
_resize_pipe($self->{+AUDITOR_WRITER});
return $self->{+AUDITOR_WRITER};
}
sub workdir {
my $self = shift;
$self->settings->workspace->workdir;
}
sub ipc {
my $self = shift;
return $self->{+IPC} //= Test2::Harness::IPC->new(
handlers => {
INT => sub { $self->handle_sig(@_) },
TERM => sub { $self->handle_sig(@_) },
}
);
}
sub handle_sig {
my $self = shift;
my ($sig) = @_;
eval { $_->signal($sig) } for grep { $_->can('signal') } @{$self->renderers};
print STDERR "\nCaught SIG$sig, forwarding signal to child processes...\n";
$self->ipc->killall($sig);
if ($self->{+SIGNAL}) {
print STDERR "\nSecond signal ($self->{+SIGNAL} followed by $sig), exiting now without waiting\n";
exit 1;
}
$self->{+SIGNAL} = $sig;
}
sub monitor_preloads { 0 }
sub run {
my $self = shift;
my $settings = $self->settings;
my $plugins = $self->settings->harness->plugins;
if ($self->start()) {
$self->render();
$self->stop();
my $final_data = $self->{+FINAL_DATA} or die "Final data never received from auditor!\n";
my $pass = $self->{+TESTS_SEEN} && $final_data->{pass};
$self->render_final_data($final_data);
$self->produce_summary($pass);
if (@$plugins) {
my %args = (
settings => $settings,
final_data => $final_data,
pass => $pass ? 1 : 0,
tests_seen => $self->{+TESTS_SEEN} // 0,
asserts_seen => $self->{+ASSERTS_SEEN} // 0,
);
$_->finish(%args) for @$plugins;
}
return $pass ? 0 : 1;
}
$self->stop();
return 1;
}
sub DESTROY {
my $self = shift;
local ($?, $!, $@, $_);
my $cleanup = delete $self->{+CLEANUP_SUBS} or return;
for my $sub (@$cleanup) {
eval { $sub->(); 1 } or warn $@;
}
}
sub write_test_info {
my $self = shift;
return if $ENV{TEST2_HARNESS_NO_WRITE_TEST_INFO};
my $info_file = "./.test_info.$$.json";
my $workdir = $self->workdir;
Test2::Harness::Util::File::JSON->new(name => $info_file)->write({
workdir => $self->workdir,
job_count => $self->job_count,
});
push @{$self->{+CLEANUP_SUBS}} => sub {
return unless -e $info_file;
return unless Test2::Harness::Util::File::JSON->new(name => $info_file)->read->{workdir} eq $workdir;
unlink($info_file) or die "Could not unlink info file: $!";
};
$ENV{TEST2_HARNESS_NO_WRITE_TEST_INFO} = 1;
}
sub start {
my $self = shift;
$self->ipc->start();
$self->parse_args;
$self->write_settings_to($self->workdir, 'settings.json');
$self->write_test_info();
my $pop = $self->populate_queue();
$self->terminate_queue();
return unless $pop;
$self->setup_plugins();
$self->setup_resources();
$self->start_runner(jobs_todo => $pop);
$self->start_collector();
$self->start_auditor();
return 1;
}
sub render {
my $self = shift;
my $ipc = $self->ipc;
my $settings = $self->settings;
my $renderers = $self->renderers;
my $logger = $self->logger;
my $plugins = $self->settings->harness->plugins;
my $handle_plugins = [grep { $_->can('handle_event') } @$plugins];
my $annotate_plugins = [grep { $_->can('annotate_event') } @$plugins];
# render results from log
my $reader = $self->renderer_reader();
$reader->blocking(0);
my $buffer;
while (1) {
return if $self->{+SIGNAL};
$_->step for @{$renderers};
my $line = <$reader>;
unless(defined $line) {
$ipc->wait() if $ipc;
sleep 0.02;
next;
}
if ($buffer) {
$line = $buffer . $line;
$buffer = undef;
}
unless (substr($line, -1, 1) eq "\n") {
$buffer //= "";
$buffer .= $line;
next;
}
my $e = decode_json($line);
if (defined $e) {
bless($e, 'Test2::Harness::Event');
my $fd = $e->{facet_data} //= {};
my $changed = 0;
for my $p (@$annotate_plugins) {
my %inject = $p->annotate_event($e, $settings);
next unless keys %inject;
$changed++;
# Can add new facets, but not modify existing ones.
# Someone could force the issue by modifying the event directly
# inside 'annotate_event', this is not supported, but also not
# forbidden, user beware.
for my $f (keys %inject) {
if (exists $fd->{$f}) {
if ('ARRAY' eq ref($fd->{$f})) {
push @{$fd->{$f}} => @{$inject{$f}};
}
else {
warn "Plugin '$p' tried to add facet '$f' via 'annotate_event()', but it is already present and not a list, ignoring plugin annotation.\n";
}
}
else {
$fd->{$f} = $inject{$f};
}
}
}
if ($logger) {
if ($changed) {
my $newline = $e->as_json;
print $logger $newline, "\n";
}
else {
print $logger $line;
}
}
}
else {
last;
}
if (my $final = $e->{facet_data}->{harness_final}) {
$self->{+FINAL_DATA} = $final;
}
$_->render_event($e) for @$renderers;
$self->{+TESTS_SEEN}++ if $e->{facet_data}->{harness_job_launch};
$self->{+ASSERTS_SEEN}++ if $e->{facet_data}->{assert};
$_->handle_event($e, $settings) for @$handle_plugins;
$ipc->wait() if $ipc;
}
}
sub get_job_pid {
my $self = shift;
my ($run_id, $job_id) = @_;
return undef unless $run_id && $job_id;
my $run_dir = File::Spec->catdir($self->workdir, $run_id);
my $jobs_file = File::Spec->catfile($run_dir, 'jobs.jsonl');
return undef unless -f $jobs_file;
my $queue = Test2::Harness::Util::Queue->new(file => $jobs_file);
my $found;
for my $item ($queue->poll) {
my $task = $item->[-1];
next unless $task->{job_id} && $task->{job_id} eq $job_id;
$found = $task;
}
return undef unless $found;
return $found->{pid} // undef;
}
sub stop {
my $self = shift;
my $settings = $self->settings;
my $renderers = $self->renderers;
my $logger = $self->logger;
$self->teardown_plugins($renderers, $logger);
if ($logger) {
print $logger "null\n";
close($logger);
}
$_->finish() for @$renderers;
my $ipc = $self->ipc;
print STDERR "Waiting for child processes to exit...\n" if $self->{+SIGNAL};
if ($self->{+SIGNAL}) {
my $state = $self->state;
delete $state->{no_poll};
$state->poll;
my $running = $state->running_tasks;
$state->halt_run($self->{+RUN_ID});
for my $task (values %$running) {
next unless $task->{run_id} && $task->{run_id} eq $self->{+RUN_ID};
my $pid = $self->get_job_pid($task->{run_id}, $task->{job_id}) // next;
my $file = $task->{rel_file};
print "Killing test $pid - $file...\n";
kill('INT', $pid);
}
}
$ipc->wait(all => 1);
$ipc->stop;
unless ($settings->display->quiet > 2) {
printf STDERR "\nNo tests were seen!\n" unless $self->{+TESTS_SEEN};
printf("\nKeeping work dir: %s\n", $self->workdir)
if $settings->debug->keep_dirs;
if ($settings->logging->log) {
print "\n";
print "Wrote log file: " . $settings->logging->log_file . "\n";
print " (Symlinked to: " . $self->{+LAST_LOG} . ")\n";
}
$self->finalize_plugins();
}
}
sub terminate_queue {
my $self = shift;
$self->tasks_queue->end();
$self->state->end_queue();
}
sub build_run {
my $self = shift;
return $self->{+RUN} if $self->{+RUN};
my $settings = $self->settings;
my $dir = $self->workdir;
my $run = $settings->build(run => 'Test2::Harness::Run');
mkdir($run->run_dir($dir)) or die "Could not make run dir: $!";
chmod_tmp($dir);
return $self->{+RUN} = $run;
}
sub state {
my $self = shift;
$self->{+STATE} //= Test2::Harness::Runner::State->new(
workdir => $self->workdir,
job_count => $self->job_count,
no_poll => 1,
);
}
sub job_count {
my $self = shift;
return $self->settings->runner->job_count;
}
sub run_queue {
my $self = shift;
my $dir = $self->workdir;
return $self->{+RUN_QUEUE} //= Test2::Harness::Util::Queue->new(file => File::Spec->catfile($dir, 'run_queue.jsonl'));
}
sub tasks_queue {
my $self = shift;
$self->{+TASKS_QUEUE} //= Test2::Harness::Util::Queue->new(
file => File::Spec->catfile($self->build_run->run_dir($self->workdir), 'queue.jsonl'),
);
}
sub finder_args {()}
sub populate_queue {
my $self = shift;
my $run = $self->build_run();
$self->{+RUN_ID} = $run->run_id;
my $settings = $self->settings;
my $finder = $settings->build(finder => $settings->finder->finder, $self->finder_args);
my $state = $self->state;
my $tasks_queue = $self->tasks_queue;
my $plugins = $settings->harness->plugins;
$state->queue_run($run->queue_item($plugins));
my @files = @{$finder->find_files($plugins, $self->settings)};
for my $plugin (@$plugins) {
if ($plugin->can('sort_files_2')) {
@files = $plugin->sort_files_2(settings => $settings, files => \@files);
}
elsif ($plugin->can('sort_files')) {
@files = $plugin->sort_files(@files);
}
}
my $job_count = 0;
for my $file (@files) {
my $task = $file->queue_item(++$job_count, $run->run_id,
$settings->check_prefix('display') ? (verbose => $settings->display->verbose) : (),
);
$task->{category} = 'isolation' if $settings->debug->interactive;
$state->queue_task($task);
$tasks_queue->enqueue($task);
}
$state->stop_run($run->run_id);
return $job_count;
}
sub produce_summary {
my $self = shift;
my ($pass) = @_;
my $settings = $self->settings;
my $time_data = {
start => $settings->harness->start,
stop => time(),
};
$time_data->{wall} = $time_data->{stop} - $time_data->{start};
my @times = times();
@{$time_data}{qw/user system cuser csystem/} = @times;
$time_data->{cpu} = sum @times;
my $cpu_usage = int($time_data->{cpu} / $time_data->{wall} * 100);
$self->write_summary($pass, $time_data, $cpu_usage);
$self->render_summary($pass, $time_data, $cpu_usage);
}
sub write_summary {
my $self = shift;
my ($pass, $time_data, $cpu_usage) = @_;
my $file = $self->settings->debug->summary or return;
my $final_data = $self->{+FINAL_DATA};
my $failures = @{$final_data->{failed} // []};
my %data = (
%$final_data,
pass => $pass ? JSON->true : JSON->false,
total_failures => $failures // 0,
total_tests => $self->{+TESTS_SEEN} // 0,
total_asserts => $self->{+ASSERTS_SEEN} // 0,
cpu_usage => $cpu_usage,
times => $time_data,
);
require Test2::Harness::Util::File::JSON;
my $jfile = Test2::Harness::Util::File::JSON->new(name => $file);
$jfile->write(\%data);
print "\nWrote summary file: $file\n\n";
return;
}
sub render_summary {
my $self = shift;
my ($pass, $time_data, $cpu_usage) = @_;
return if $self->settings->display->quiet > 1;
my $final_data = $self->{+FINAL_DATA};
my $failures = @{$final_data->{failed} // []};
my @summary = (
$failures ? (" Fail Count: $failures") : (),
" File Count: $self->{+TESTS_SEEN}",
"Assertion Count: $self->{+ASSERTS_SEEN}",
$time_data ? (
sprintf(" Wall Time: %.2f seconds", $time_data->{wall}),
sprintf(" CPU Time: %.2f seconds (usr: %.2fs | sys: %.2fs | cusr: %.2fs | csys: %.2fs)", @{$time_data}{qw/cpu user system cuser csystem/}),
sprintf(" CPU Usage: %i%%", $cpu_usage),
) : (),
);
my $res = " --> Result: " . ($pass ? 'PASSED' : 'FAILED') . " <--";
if ($self->settings->display->color && USE_ANSI_COLOR) {
my $color = $pass ? Term::ANSIColor::color('bold bright_green') : Term::ANSIColor::color('bold bright_red');
my $reset = Term::ANSIColor::color('reset');
$res = "$color$res$reset";
}
push @summary => $res;
my $msg = "Yath Result Summary";
my $length = max map { length($_) } @summary;
my $prefix = ($length - length($msg)) / 2;
print "\n";
print " " x $prefix;
print "$msg\n";
print "-" x $length;
print "\n";
print join "\n" => @summary;
print "\n";
}
sub render_final_data {
my $self = shift;
my ($final_data) = @_;
return if $self->settings->display->quiet > 1;
if (my $rows = $final_data->{retried}) {
print "\nThe following jobs failed at least once:\n";
print join "\n" => table(
header => ['Job ID', 'Times Run', 'Test File', "Succeeded Eventually?"],
rows => $rows,
);
print "\n";
}
if (my $rows = $final_data->{failed}) {
print "\nThe following jobs failed:\n";
print join "\n" => table(
collapse => 1,
header => ['Job ID', 'Test File', 'Subtests'],
rows => [map { my $r = [@{$_}]; $r->[2] = stringify_subtest_map($r->[2]) if $r->[2]; $r} @$rows],
);
print "\n";
}
if (my $rows = $final_data->{halted}) {
print "\nThe following jobs requested all testing be halted:\n";
print join "\n" => table(
header => ['Job ID', 'Test File', "Reason"],
rows => $rows,
);
print "\n";
}
if (my $rows = $final_data->{unseen}) {
print "\nThe following jobs never ran:\n";
print join "\n" => table(
header => ['Job ID', 'Test File'],
rows => $rows,
);
print "\n";
}
}
sub stringify_subtest_map {
my ($map) = @_;
my $out = "";
my @todo = @$map;
my @state;
while (my $st = shift @todo) {
if (!ref($st)) {
pop @state if $st eq 'pop';
next;
}
push @state => $st->[0];
$out .= join(' -> ' => @state) . "\n";
unshift @todo => (@{$st->[1]}, 'pop');
}
return $out;
}
sub logger {
my $self = shift;
return $self->{+LOGGER} if $self->{+LOGGER};
my $settings = $self->{+SETTINGS};
return unless $settings->logging->log;
my $file = $settings->logging->log_file;
if ($settings->logging->bzip2) {
no warnings 'once';
require IO::Compress::Bzip2;
$self->{+LOGGER} = IO::Compress::Bzip2->new($file) or die "Could not open log file '$file': $IO::Compress::Bzip2::Bzip2Error";
}
elsif ($settings->logging->gzip) {
no warnings 'once';
require IO::Compress::Gzip;
$self->{+LOGGER} = IO::Compress::Gzip->new($file) or die "Could not open log file '$file': $IO::Compress::Gzip::GzipError";
}
else {
$self->{+LOGGER} = open_file($file, '>');
}
for my $ext ('jsonl', 'jsonl.bz2', 'jsonl.gz') {
my $name = "./lastlog.$ext";
next unless -f $name;
local ($!, $@) = (0, '');
eval { unlink($name) } or warn "Could not unlink '$name': ($!) $@";
}
if ($file =~ m/\.(jsonl(?:\.(?:bz2|gz))?)$/) {
my $ext = $1;
my $name = "./lastlog.$ext";
if (eval { symlink($file, $name); 1 }) {
$self->{+LAST_LOG} = $name;
}
else {
warn "Could not symlink the log file to '$name': $@";
}
}
return $self->{+LOGGER};
}
sub renderers {
my $self = shift;
return $self->{+RENDERERS} if $self->{+RENDERERS};
my $settings = $self->{+SETTINGS};
my @renderers;
for my $class (@{$settings->display->renderers->{'@'}}) {
require(mod2file($class));
my $args = $settings->display->renderers->{$class};
my $renderer = $class->new(@$args, settings => $settings, command_class => ref($self));
push @renderers => $renderer;
}
return $self->{+RENDERERS} = \@renderers;
}
sub start_auditor {
my $self = shift;
my $run = $self->build_run();
my $settings = $self->settings;
my $ipc = $self->ipc;
$ipc->spawn(
stdin => $self->auditor_reader(),
stdout => $self->auditor_writer(),
no_set_pgrp => 1,
command => [
$^X, $self->spawn_args($settings), $settings->harness->script,
(map { "-D$_" } @{$settings->harness->dev_libs}),
'--no-scan-plugins', # Do not preload any plugin modules
auditor => 'Test2::Harness::Auditor',
$run->run_id,
procname_prefix => $settings->debug->procname_prefix,
],
);
close($self->auditor_writer());
}
sub collector_options { () }
sub start_collector {
my $self = shift;
my $dir = $self->workdir;
my $run = $self->build_run();
my $settings = $self->settings;
my $runner_pid = $self->runner_pid;
my ($rh, $wh);
pipe($rh, $wh) or die "Could not create pipe";
my %options = (show_runner_output => 1);
if ($settings->check_prefix('display')) {
$options{show_runner_output} = $settings->display->hide_runner_output ? 0 : 1;
$options{truncate_runner_output} = $settings->display->truncate_runner_output;
}
%options = (
%options,
$self->collector_options(),
);
my $ipc = $self->ipc;
$ipc->spawn(
stdout => $self->collector_writer,
stdin => $rh,
no_set_pgrp => 1,
command => [
$^X, $self->spawn_args($settings), $settings->harness->script,
(map { "-D$_" } @{$settings->harness->dev_libs}),
'--no-scan-plugins', # Do not preload any plugin modules
collector => 'Test2::Harness::Collector',
$dir, $run->run_id, $runner_pid,
%options,
],
);
close($rh);
print $wh encode_json($run) . "\n";
close($wh);
close($self->collector_writer());
}
sub start_runner {
my $self = shift;
my %args = @_;
$args{monitor_preloads} //= $self->monitor_preloads;
my $settings = $self->settings;
my $dir = $settings->workspace->workdir;
my @prof;
if ($settings->runner->nytprof) {
push @prof => '-d:NYTProf';
}
my $ipc = $self->ipc;
my $proc = $ipc->spawn(
stderr => File::Spec->catfile($dir, 'error.log'),
stdout => File::Spec->catfile($dir, 'output.log'),
env_vars => { @prof ? (NYTPROF => 'start=no:addpid=1') : () },
no_set_pgrp => 1,
command => [
$^X, @prof, $self->spawn_args($settings), $settings->harness->script,
(map { "-D$_" } @{$settings->harness->dev_libs}),
'--no-scan-plugins', # Do not preload any plugin modules
runner => $dir,
%args,
],
);
$self->{+RUNNER_PID} = $proc->pid;
return $proc;
}
sub parse_args {
my $self = shift;
my $settings = $self->settings;
my $args = $self->args;
my $dest = $settings->finder->search;
for my $arg (@$args) {
next if $arg eq '--';
if ($arg eq '::') {
$dest = $settings->run->test_args;
next;
}
push @$dest => $arg;
}
return;
}
1;
__END__
=head1 POD IS AUTO-GENERATED