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
CommitLineData
54c7876f 1use strict;
2use warnings;
3
4BEGIN {
5 if ($ENV{'PERL_CORE'}){
6 chdir('t');
7 unshift(@INC, '../lib');
8 }
9 use Config;
10 if (! $Config{'useithreads'}) {
3d4f2f89 11 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
54c7876f 12 exit(0);
13 }
14}
15
16use threads;
17use Thread::Queue;
18
19if ($] == 5.008) {
20 require 't/test.pl'; # Test::More work-alike for Perl 5.8.0
21} else {
22 require Test::More;
23}
24Test::More->import();
25plan('tests' => 19);
26
27my $q = Thread::Queue->new(1..10);
28ok($q, 'New queue');
29
30$q->enqueue([ qw/foo bar/ ]);
31
32sub 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
48threads->create(sub {
49 q_check();
50 threads->create('q_check')->join();
51})->join();
52q_check();
53
3d4f2f89 54exit(0);
55
54c7876f 56# EOF