From: Vincent Pit Date: Sun, 23 Oct 2011 10:47:47 +0000 (+0200) Subject: Test "no indirect 'global'" with threads X-Git-Tag: v0.26~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=57da6be33e154ebfd9f3fa41ca0beb0c95568ce0;p=perl%2Fmodules%2Findirect.git Test "no indirect 'global'" with threads --- diff --git a/MANIFEST b/MANIFEST index ac8dc76..aa80709 100644 --- a/MANIFEST +++ b/MANIFEST @@ -22,6 +22,7 @@ t/31-hints.t t/32-global.t t/40-threads.t t/41-threads-teardown.t +t/42-threads-global.t t/45-memory.t t/46-stress.t t/47-stress-use.t diff --git a/t/42-threads-global.t b/t/42-threads-global.t new file mode 100644 index 0000000..c2c4d83 --- /dev/null +++ b/t/42-threads-global.t @@ -0,0 +1,41 @@ +#!perl -T + +use strict; +use warnings; + +use lib 't/lib'; +use indirect::TestThreads; + +use Test::Leaner; + +sub expect { + my ($pkg) = @_; + qr/^Indirect call of method "new" on object "$pkg" at \(eval \d+\) line \d+/; +} + +my $error; + +no indirect 'global', 'hook' => sub { $error = indirect::msg(@_) }; + +sub try { + my $tid = threads->tid(); + + for my $run (1 .. 2) { + my $desc = "global indirect hook (thread $tid, run $run)"; + my $class = "Mango$tid"; + my @warns; + { + local $SIG{__WARN__} = sub { push @warns, @_ }; + eval "return; my \$x = new $class 1, 2;" + } + is $@, '', "$desc: did not croak"; + is_deeply \@warns, [ ], "$desc: no warnings"; + like $error, expect($class), "$desc: correct error"; + } +} + +my @threads = map spawn(\&try), 1 .. 10; + +$_->join for @threads; + +done_testing(scalar(@threads) * 3 * 2);