Skip new threads::shared test unless -Duseithreads
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / 0nothread.t
1 use strict;
2 use Test::More ();
3 use Config;
4 if ($Config{'useithreads'}) {
5   Test::More->import( tests => 53 );
6 }
7 else {
8   Test::More->import(skip_all => "no useithreads");
9 }
10
11
12 my @array;
13 my %hash;
14
15 sub hash
16 {
17  my @val = @_;
18  is(keys %hash, 0, "hash empty");
19  $hash{0} = $val[0];
20  is(keys %hash,1, "Assign grows hash");
21  is($hash{0},$val[0],"Value correct");
22  $hash{2} = $val[2];
23  is(keys %hash,2, "Assign grows hash");
24  is($hash{0},$val[0],"Value correct");
25  is($hash{2},$val[2],"Value correct");
26  $hash{1} = $val[1];
27  is(keys %hash,3,"Size correct");
28  my @keys = keys %hash;
29  is(join(',',sort @keys),'0,1,2',"Keys correct");
30  my @hval = @hash{0,1,2};
31  is(join(',',@hval),join(',',@val),"Values correct");
32  my $val = delete $hash{1};
33  is($val,$val[1],"Delete value correct");
34  is(keys %hash,2,"Size correct");
35  while (my ($k,$v) = each %hash)
36   {
37    is($v,$val[$k],"each works");
38   }
39  %hash = ();
40  is(keys %hash,0,"Clear hash");
41 }
42
43 sub array
44 {
45  my @val = @_;
46  is(@array, 0, "array empty");
47  $array[0] = $val[0];
48  is(@array,1, "Assign grows array");
49  is($array[0],$val[0],"Value correct");
50  unshift(@array,$val[2]);
51  is($array[0],$val[2],"Unshift worked");
52  is($array[-1],$val[0],"-ve index");
53  push(@array,$val[1]);
54  is($array[-1],$val[1],"Push worked");
55  is(@array,3,"Size correct");
56  is(shift(@array),$val[2],"Shift worked");
57  is(@array,2,"Size correct");
58  is(pop(@array),$val[1],"Pop worked");
59  is(@array,1,"Size correct");
60  @array = ();
61  is(@array,0,"Clear array");
62 }
63
64 ok((require threads::shared),"Require module");
65
66 array(24,[],'Thing');
67 hash(24,[],'Thing');
68
69
70 import threads::shared;
71 share(\@array);
72
73 #SKIP:
74 # {
75 #  skip("Wibble",1);
76 #  ok(0,"No it isn't");
77 # }
78
79 array(24,42,'Thing');
80
81 share(\%hash);
82 hash(24,42,'Thing');
83