This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
threads::shared 1.13
[perl5.git] / ext / threads / shared / t / 0nothread.t
CommitLineData
6b85e4fe 1use strict;
13c1b207 2use warnings;
7473853a 3
38506751 4BEGIN {
7473853a
SP
5 if ($ENV{'PERL_CORE'}){
6 chdir 't';
7 unshift @INC, '../lib';
38506751 8 }
7473853a
SP
9 use Config;
10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
12 exit(0);
38506751 13 }
5f64702c
NIS
14}
15
7473853a
SP
16use Test::More (tests => 53);
17
18### Start of Testing ###
6b85e4fe
NIS
19
20my @array;
21my %hash;
22
23sub hash
24{
7473853a
SP
25 my @val = @_;
26 is(keys %hash, 0, "hash empty");
27 $hash{0} = $val[0];
28 is(keys %hash,1, "Assign grows hash");
29 is($hash{0},$val[0],"Value correct");
30 $hash{2} = $val[2];
31 is(keys %hash,2, "Assign grows hash");
32 is($hash{0},$val[0],"Value correct");
33 is($hash{2},$val[2],"Value correct");
34 $hash{1} = $val[1];
35 is(keys %hash,3,"Size correct");
36 my @keys = keys %hash;
37 is(join(',',sort @keys),'0,1,2',"Keys correct");
38 my @hval = @hash{0,1,2};
39 is(join(',',@hval),join(',',@val),"Values correct");
40 my $val = delete $hash{1};
41 is($val,$val[1],"Delete value correct");
42 is(keys %hash,2,"Size correct");
43 while (my ($k,$v) = each %hash) {
44 is($v,$val[$k],"each works");
45 }
46 %hash = ();
47 is(keys %hash,0,"Clear hash");
6b85e4fe
NIS
48}
49
50sub array
51{
7473853a
SP
52 my @val = @_;
53 is(@array, 0, "array empty");
54 $array[0] = $val[0];
55 is(@array,1, "Assign grows array");
56 is($array[0],$val[0],"Value correct");
57 unshift(@array,$val[2]);
58 is($array[0],$val[2],"Unshift worked");
59 is($array[-1],$val[0],"-ve index");
60 push(@array,$val[1]);
61 is($array[-1],$val[1],"Push worked");
62 is(@array,3,"Size correct");
63 is(shift(@array),$val[2],"Shift worked");
64 is(@array,2,"Size correct");
65 is(pop(@array),$val[1],"Pop worked");
66 is(@array,1,"Size correct");
67 @array = ();
68 is(@array,0,"Clear array");
6b85e4fe
NIS
69}
70
71ok((require threads::shared),"Require module");
72
7473853a
SP
73if ($threads::shared::VERSION && ! exists($ENV{'PERL_CORE'})) {
74 diag('Testing threads::shared ' . $threads::shared::VERSION);
75}
6b85e4fe 76
7473853a
SP
77array(24, [], 'Thing');
78hash(24, [], 'Thing');
5f64702c 79
7c8caac0 80threads::shared->import();
6b85e4fe 81
7473853a
SP
82share(\@array);
83array(24, 42, 'Thing');
6b85e4fe
NIS
84
85share(\%hash);
7473853a 86hash(24, 42, 'Thing');
6b85e4fe 87
7473853a 88# EOF