Skip new threads::shared test unless -Duseithreads
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / 0nothread.t
CommitLineData
6b85e4fe 1use strict;
5f64702c 2use Test::More ();
3use Config;
4if ($Config{'useithreads'}) {
5 Test::More->import( tests => 53 );
6}
7else {
8 Test::More->import(skip_all => "no useithreads");
9}
10
6b85e4fe 11
12my @array;
13my %hash;
14
15sub 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
43sub 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
64ok((require threads::shared),"Require module");
65
66array(24,[],'Thing');
67hash(24,[],'Thing');
68
5f64702c 69
6b85e4fe 70import threads::shared;
71share(\@array);
72
73#SKIP:
74# {
75# skip("Wibble",1);
76# ok(0,"No it isn't");
77# }
78
79array(24,42,'Thing');
80
81share(\%hash);
82hash(24,42,'Thing');
83