This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
37d46804118b056a3ad70f510f8d44e2e6c65103
[perl5.git] / t / thread_it.pl
1 #!perl
2 use strict;
3 use warnings;
4
5 # As perlfunc.pod says:
6 # Note that the file will not be included twice under the same specified name.
7 # So ensure that this, textually, is the same name as all the loaded tests use.
8 # Otherwise if we require 'test.pl' and they require './test.pl', it is loaded
9 # twice.
10 require './test.pl';
11 skip_all_without_config('useithreads');
12 skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
13
14 require threads;
15
16 # Which file called us?
17 my $caller = (caller)[1];
18
19 die "Can't figure out which test to run from filename '$caller'"
20     unless $caller =~ m!((?:op|re)/[-_a-z0-9A-Z]+)_thr\.t\z!;
21
22 my $file = "$1.t";
23
24 $::running_as_thread = "running tests in a new thread";
25 require $file;
26
27 note('running tests in a new thread');
28
29 my $curr = threads->create(sub {
30                                run_tests();
31                                return defined &curr_test ? curr_test() : ()
32                            })->join();
33
34 curr_test($curr) if defined $curr;
35
36 1;