Upgrade to Attribute::Handlers 0.87 (which is just a core sync) -- for real
[p5sagit/p5-mst-13.2.git] / ext / Thread-Queue / t / 03_peek.t
1 use strict;
2 use warnings;
3
4 BEGIN {
5     if ($ENV{'PERL_CORE'}){
6         chdir('t');
7         unshift(@INC, '../lib');
8     }
9     use Config;
10     if (! $Config{'useithreads'}) {
11         print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
12         exit(0);
13     }
14 }
15
16 use threads;
17 use Thread::Queue;
18
19 if ($] == 5.008) {
20     require 't/test.pl';   # Test::More work-alike for Perl 5.8.0
21 } else {
22     require Test::More;
23 }
24 Test::More->import();
25 plan('tests' => 19);
26
27 my $q = Thread::Queue->new(1..10);
28 ok($q, 'New queue');
29
30 $q->enqueue([ qw/foo bar/ ]);
31
32 sub q_check
33 {
34     is($q->peek(3), 4, 'Peek at queue');
35     is($q->peek(-3), 9, 'Negative peek');
36
37     my $nada = $q->peek(20);
38     ok(! defined($nada), 'Big peek');
39     $nada = $q->peek(-20);
40     ok(! defined($nada), 'Big negative peek');
41
42     my $ary = $q->peek(-1);
43     is_deeply($ary, [ qw/foo bar/ ], 'Peek array');
44
45     is($q->pending(), 11, 'Queue count in thread');
46 }
47
48 threads->create(sub {
49     q_check();
50     threads->create('q_check')->join();
51 })->join();
52 q_check();
53
54 exit(0);
55
56 # EOF