use warnings;
use lib 't/lib';
-use Lexical::Types::TestThreads;
+use VPIT::TestHelpers (
+ threads => [ 'Lexical::Types' => 'Lexical::Types::LT_THREADSAFE()' ],
+ 'run_perl',
+);
-use Test::More tests => 1;
+use Test::Leaner tests => 2;
-sub run_perl {
- my $code = shift;
-
- my ($SystemRoot, $PATH) = @ENV{qw<SystemRoot PATH>};
- local %ENV;
- $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
- $ENV{PATH} = $PATH if $^O eq 'cygwin' and defined $PATH;
-
- system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
-}
-
-{
+SKIP: {
my $status = run_perl <<' RUN';
{ package IntX; package IntY; package IntZ; }
my ($code, @expected);
$code += 256 if $code < 0;
exit $code;
RUN
+ skip RUN_PERL_FAILED() => 1 unless defined $status;
is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
}
+
+SKIP: {
+ my $status = run_perl <<' RUN';
+ use threads;
+ BEGIN { require Lexical::Types; }
+ sub X::DESTROY {
+ my $res = eval 'use Lexical::Types; sub Z::TYPEDSCALAR { 123 } my Z $z';
+ exit 1 if $@;
+ exit 2 if not defined $res or $res != 123;
+ }
+ threads->create(sub {
+ my $x = bless { }, 'X';
+ $x->{self} = $x;
+ return;
+ })->join;
+ exit 0;
+ RUN
+ skip RUN_PERL_FAILED() => 1 unless defined $status;
+ is $status, 0, 'Lexical::Types can be loaded in eval STRING during global destruction at the end of a thread';
+}