9 Test::More::plan(skip_all => $msg);
12 use Config qw<%Config>;
15 my $force = $ENV{PERL_RE_ENGINE_PLUGIN_TEST_THREADS} ? 1 : !1;
16 my $t_v = $force ? '0' : '1.67';
17 my $ts_v = $force ? '0' : '1.14';
18 skipall 'This perl wasn\'t built to support threads'
19 unless $Config{useithreads};
20 skipall 'perl 5.13.4 required to test thread safety'
21 unless $force or "$]" >= 5.013_004;
22 skipall "threads $t_v required to test thread safety"
23 unless eval "use threads $t_v; 1";
24 skipall "threads::shared $ts_v required to test thread safety"
25 unless eval "use threads::shared $ts_v; 1";
28 use Test::More; # after threads
31 BEGIN { $threads = 10 }
34 require re::engine::Plugin;
35 skipall 'This re::engine::Plugin isn\'t thread safe'
36 unless re::engine::Plugin::REP_THREADSAFE();
37 plan tests => 2 * 2 * $threads + 1;
38 defined and diag "Using threads $_" for $threads::VERSION;
39 defined and diag "Using threads::shared $_" for $threads::shared::VERSION;
42 my $matches : shared = '';
44 use re::engine::Plugin comp => sub {
47 my $pat = $re->pattern;
55 $matches .= "$str==$pat\n";
64 my $tid = threads->tid;
68 ok $tid =~ $rx, "'$tid' is matched in thread $tid";
71 ok $wrong !~ $rx, "'$wrong' is not matched in thread $tid";
76 no re::engine::Plugin;
78 my @tids = map threads->create(\&try), 1 .. $threads;
82 my %matches = map { $_ => 1 }
85 do { lock $matches; $matches };
87 is keys(%matches), 2 * $threads, 'regexps matched the correct number of times';
89 for my $i (1 .. $threads) {
90 ok $matches{"$i==$i"}, "match '$i==$i' was correctly executed";
92 ok $matches{"$j==$i"}, "match '$j==$i' was correctly executed";