Commit | Line | Data |
---|---|---|
0a9af0ff MS |
1 | #!./perl -Tw |
2 | ||
3 | # Tests of threads::shared's behavior when threads are disabled. | |
4 | ||
5 | BEGIN { | |
6 | chdir 't'; | |
7 | @INC = '../lib'; | |
8 | } | |
9 | ||
10 | # Can't use Test::More, it turns threads on. | |
11 | use Test; | |
12 | plan tests => 31; | |
13 | ||
14 | use threads::shared; | |
15 | ||
16 | # Make sure threads are really off. | |
17 | ok( !$INC{"threads.pm"} ); | |
18 | ||
19 | # Check each faked function. | |
20 | foreach my $func (qw(share cond_wait cond_signal cond_broadcast)) { | |
21 | ok( my $func_ref = __PACKAGE__->can($func) ? 1 : 0 ); | |
22 | ||
23 | eval qq{$func()}; | |
24 | ok( $@, qr/^Not enough arguments / ); | |
25 | ||
26 | my %hash = (foo => 42, bar => 23); | |
27 | eval qq{$func(\%hash)}; | |
28 | ok( $@, '' ); | |
29 | ok( $hash{foo}, 42 ); | |
30 | ok( $hash{bar}, 23 ); | |
31 | } | |
32 | ||
33 | # These all have no return value. | |
34 | foreach my $func (qw(cond_wait cond_signal cond_broadcast)) { | |
35 | my @array = qw(1 2 3 4); | |
36 | ok( eval qq{$func(\@array)}, undef ); | |
37 | ok( "@array", "1 2 3 4" ); | |
38 | } | |
39 | ||
40 | # share() is supposed to return back it's argument as a ref. | |
41 | { | |
42 | my @array = qw(1 2 3 4); | |
43 | ok( share(@array), \@array ); | |
44 | ok( ref &share({}), 'HASH' ); | |
45 | ok( "@array", "1 2 3 4" ); | |
46 | } | |
47 | ||
48 | # lock() should be a no-op. The return value is currently undefined. | |
49 | { | |
50 | my @array = qw(1 2 3 4); | |
51 | lock(@array); | |
52 | ok( "@array", "1 2 3 4" ); | |
53 | } |