File: err.t

package info (click to toggle)
perl 5.10.1-17squeeze6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 74,280 kB
  • ctags: 49,087
  • sloc: perl: 319,380; ansic: 193,238; sh: 37,981; pascal: 8,830; lisp: 7,515; cpp: 3,893; makefile: 2,375; xml: 1,972; yacc: 1,555
file content (72 lines) | stat: -rwxr-xr-x 1,644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use strict;
use warnings;

BEGIN {
    if ($ENV{'PERL_CORE'}){
        chdir 't';
        unshift @INC, '../lib';
    }

    require($ENV{PERL_CORE} ? "./test.pl" : "./t/test.pl");

    use Config;
    if (! $Config{'useithreads'}) {
        skip_all(q/Perl not compiled with 'useithreads'/);
    }

    plan(10);
}

use ExtUtils::testlib;

use_ok('threads');

### Start of Testing ###

no warnings 'threads';

# Create a thread that generates an error
my $thr = threads->create(sub { my $x = Foo->new(); });

# Check that thread returns 'undef'
my $result = $thr->join();
ok(! defined($result), 'thread died');

# Check error
like($thr->error(), q/Can't locate object method/, 'thread error');


# Create a thread that 'die's with an object
$thr = threads->create(sub {
                    threads->yield();
                    sleep(1);
                    die(bless({ error => 'bogus' }, 'Err::Class'));
                });

my $err = $thr->error();
ok(! defined($err), 'no error yet');

# Check that thread returns 'undef'
$result = $thr->join();
ok(! defined($result), 'thread died');

# Check that error object is retrieved
$err = $thr->error();
isa_ok($err, 'Err::Class', 'error object');
is($err->{error}, 'bogus', 'error field');

# Check that another thread can reference the error object
my $thrx = threads->create(sub { die(bless($thr->error(), 'Foo')); });

# Check that thread returns 'undef'
$result = $thrx->join();
ok(! defined($result), 'thread died');

# Check that the rethrown error object is retrieved
$err = $thrx->error();
isa_ok($err, 'Foo', 'error object');
is($err->{error}, 'bogus', 'error field');

exit(0);

# EOF