]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blobdiff - t/81-threads-teardown.t
Revamp module setup/teardown
[perl/modules/Lexical-Types.git] / t / 81-threads-teardown.t
index 741d2242e506b8216c4dd9b2ab716522298cf813..6fc843780f6281ab2792a76ce762c0dd2386f4f5 100644 (file)
@@ -4,22 +4,14 @@ use strict;
 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);
@@ -40,5 +32,26 @@ sub run_perl {
   $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';
+}