]> git.vpit.fr Git - perl/modules/indirect.git/commitdiff
Test "no indirect 'global'" with threads
authorVincent Pit <vince@profvince.com>
Sun, 23 Oct 2011 10:47:47 +0000 (12:47 +0200)
committerVincent Pit <vince@profvince.com>
Sun, 23 Oct 2011 10:47:47 +0000 (12:47 +0200)
MANIFEST
t/42-threads-global.t [new file with mode: 0644]

index ac8dc765b4b5b30d1f52200cbf932b523ed3ea26..aa80709899f6b241f42a5884a2fa17e3f3dcd5f3 100644 (file)
--- 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 (file)
index 0000000..c2c4d83
--- /dev/null
@@ -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);