X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F21-ctl.t;fp=t%2F21-ctl.t;h=4029b90c5c25ebf4d974b5d39efb25f7efb7e251;hb=f178c1e569b78464ea63bf184389cf1b00804690;hp=0000000000000000000000000000000000000000;hpb=ba8793aed63c1cd66942055b1c2d934bd1c28a9d;p=perl%2Fmodules%2FThread-Cleanup.git diff --git a/t/21-ctl.t b/t/21-ctl.t new file mode 100644 index 0000000..4029b90 --- /dev/null +++ b/t/21-ctl.t @@ -0,0 +1,58 @@ +#!perl -T + +use strict; +use warnings; + +use Config qw/%Config/; + +BEGIN { + if (!$Config{useithreads}) { + require Test::More; + Test::More->import; + plan(skip_all => 'This perl wasn\'t built to support threads'); + } +} + +use threads; +use threads::shared; + +use Test::More tests => 5 + 1; + +BEGIN { + defined and diag "Using threads $_" for $threads::VERSION; + defined and diag "Using threads::shared $_" for $threads::shared::VERSION; +} + +use Thread::Cleanup; + +my @stack : shared; + +sub msg { lock @stack; push @stack, join ':', @_ } + +Thread::Cleanup::register { + msg 'cleanup'; + die 'cleanup'; + msg 'not reached 1'; +}; + +{ + local $SIG{__DIE__} = sub { msg 'sig', @_ }; + no warnings 'threads'; + threads->create(sub { + msg 'spawn'; + die 'thread'; + msg 'not reached 2'; + })->join; +} + +msg 'done'; + +{ + lock @stack; + is shift(@stack), 'spawn'; + like shift(@stack), qr/sig:thread at \Q$0\E line \d+/; + is shift(@stack), 'cleanup'; + like shift(@stack), qr/sig:cleanup at \Q$0\E line \d+/; + is shift(@stack), 'done'; + is_deeply \@stack, [ ], 'nothing more'; +}