Commit | Line | Data |
7483b81c |
1 | #!/usr/bin/perl -w |
ccbd73a4 |
2 | # $Id: /mirror/googlecode/test-more-trunk/t/is_deeply_with_threads.t 60989 2008-09-10T03:05:54.548376Z schwern $ |
7483b81c |
3 | |
6b38a9b9 |
4 | # Test to see if is_deeply() plays well with threads. |
7483b81c |
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 { |
b7f9bbeb |
20 | unless ( $] >= 5.008001 && $Config{'useithreads'} && |
0257f296 |
21 | eval { require threads; 'threads'->import; 1; }) |
22 | { |
ccbd73a4 |
23 | print "1..0 # Skip no working threads\n"; |
0257f296 |
24 | exit 0; |
25 | } |
705e6672 |
26 | |
27 | unless ( $ENV{AUTHOR_TESTING} ) { |
ccbd73a4 |
28 | print "1..0 # Skip many perls have broken threads. Enable with AUTHOR_TESTING.\n"; |
705e6672 |
29 | exit 0; |
30 | } |
7483b81c |
31 | } |
32 | use Test::More; |
33 | |
6b38a9b9 |
34 | my $Num_Threads = 5; |
7483b81c |
35 | |
705e6672 |
36 | plan tests => $Num_Threads * 100 + 6; |
7483b81c |
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; |
4d845874 |
45 | print "# kid $kid before is_deeply\n"; |
7483b81c |
46 | |
6b38a9b9 |
47 | for my $j (1..100) { |
48 | is_deeply(\@list, \@list2); |
7483b81c |
49 | } |
50 | print "# kid $kid exit\n"; |
51 | return 42; |
52 | } |
53 | |
54 | my @kids = (); |
0257f296 |
55 | for my $i (1..$Num_Threads) { |
7483b81c |
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 | } |
705e6672 |
65 | |
66 | pass("End of test"); |