Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / is_deeply_with_threads.t
1 #!/usr/bin/perl -w
2 # $Id: /mirror/googlecode/test-more-trunk/t/is_deeply_with_threads.t 60989 2008-09-10T03:05:54.548376Z schwern  $
3
4 # Test to see if is_deeply() plays well with threads.
5
6 BEGIN {
7     if( $ENV{PERL_CORE} ) {
8         chdir 't';
9         @INC = ('../lib', 'lib');
10     }
11     else {
12         unshift @INC, 't/lib';
13     }
14 }
15
16 use strict;
17 use Config;
18
19 BEGIN {
20     unless ( $] >= 5.008001 && $Config{'useithreads'} && 
21              eval { require threads; 'threads'->import; 1; }) 
22     {
23         print "1..0 # Skip no working threads\n";
24         exit 0;
25     }
26     
27     unless ( $ENV{AUTHOR_TESTING} ) {
28         print "1..0 # Skip many perls have broken threads.  Enable with AUTHOR_TESTING.\n";
29         exit 0;
30     }
31 }
32 use Test::More;
33
34 my $Num_Threads = 5;
35
36 plan tests => $Num_Threads * 100 + 6;
37
38
39 sub do_one_thread {
40     my $kid = shift;
41     my @list = ( 'x', 'yy', 'zzz', 'a', 'bb', 'ccc', 'aaaaa', 'z',
42                  'hello', 's', 'thisisalongname', '1', '2', '3',
43                  'abc', 'xyz', '1234567890', 'm', 'n', 'p' );
44     my @list2 = @list;
45     print "# kid $kid before is_deeply\n";
46
47     for my $j (1..100) {
48         is_deeply(\@list, \@list2);
49     }
50     print "# kid $kid exit\n";
51     return 42;
52 }
53
54 my @kids = ();
55 for my $i (1..$Num_Threads) {
56     my $t = threads->new(\&do_one_thread, $i);
57     print "# parent $$: continue\n";
58     push(@kids, $t);
59 }
60 for my $t (@kids) {
61     print "# parent $$: waiting for join\n";
62     my $rc = $t->join();
63     cmp_ok( $rc, '==', 42, "threads exit status is $rc" );
64 }
65
66 pass("End of test");