Upgrade to Test::Simple 0.53
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / sort_bug.t
1 #!/usr/bin/perl -w
2
3 # Test to see if we've worked around some wacky sort/threading bug
4 # See [rt.cpan.org 6782]
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     require threads if $Config{useithreads};
21 }
22 use Test::More;
23
24 # Passes with $nthreads = 1 and with eq_set().
25 # Passes with $nthreads = 2 and with eq_array().
26 # Fails  with $nthreads = 2 and with eq_set().
27 my $nthreads = 2;
28
29 if( $Config{useithreads} ) {
30     plan tests => $nthreads;
31 }
32 else {
33     plan skip_all => 'no threads';
34 }
35
36
37 sub do_one_thread {
38     my $kid = shift;
39     my @list = ( 'x', 'yy', 'zzz', 'a', 'bb', 'ccc', 'aaaaa', 'z',
40                  'hello', 's', 'thisisalongname', '1', '2', '3',
41                  'abc', 'xyz', '1234567890', 'm', 'n', 'p' );
42     my @list2 = @list;
43     print "# kid $kid before eq_set\n";
44
45     for my $j (1..99) {
46         # With eq_set, either crashes or panics
47         eq_set(\@list, \@list2);
48         eq_array(\@list, \@list2);
49     }
50     print "# kid $kid exit\n";
51     return 42;
52 }
53
54 my @kids = ();
55 for my $i (1..$nthreads) {
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 }