1use strict; 2use warnings; 3# HARNESS-NO-STREAM 4 5use Test2::Util qw/CAN_THREAD/; 6BEGIN { 7 unless(CAN_THREAD) { 8 print "1..0 # Skip threads are not supported.\n"; 9 exit 0; 10 } 11} 12 13BEGIN { 14 unless ( $ENV{AUTHOR_TESTING} ) { 15 print "1..0 # Skip many perls have broken threads. Enable with AUTHOR_TESTING.\n"; 16 exit 0; 17 } 18} 19 20use Test2::IPC; 21use threads; 22use Test::More; 23 24plan 'skip_all' => "This test cannot be run with the current formatter" 25 unless Test::Builder->new->{Stack}->top->format->isa('Test::Builder::Formatter'); 26 27ok 1 for (1 .. 2); 28 29# used to reset the counter after thread finishes 30my $ct_num = Test::More->builder->current_test; 31 32my $subtest_out = async { 33 my $out = ''; 34 35 #simulate a subtest to not confuse the parent TAP emission 36 my $tb = Test::More->builder; 37 $tb->reset; 38 for (qw/output failure_output todo_output/) { 39 close $tb->$_; 40 open($tb->$_, '>', \$out); 41 } 42 43 ok 1 for (1 .. 3); 44 45 done_testing; 46 47 close $tb->$_ for (qw/output failure_output todo_output/); 48 49 $out; 50} 51->join; 52 53$subtest_out =~ s/^/ /gm; 54print $subtest_out; 55 56# reset as if the thread never "said" anything 57Test::More->builder->current_test($ct_num); 58 59ok 1 for (1 .. 4); 60 61done_testing; 62