File: 17_pointcut_returning.t

package info (click to toggle)
libaspect-perl 1.04-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: perl: 6,846; makefile: 2
file content (103 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download | duplicates (5)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl

# Copied from 16_pointcut_returning with all the tests reversed.

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 6;
use Test::NoWarnings;
use Test::Exception;
use Aspect;





######################################################################
# Test the regexp exception case

after {
	$_->exception('three');
} call qr/^Foo::/
& returning;

throws_ok(
	sub { Foo::one() },
	qr/^one/,
	'Hooked positive string exception is in the pointcut',
);

throws_ok(
	sub { Foo::two() },
	qr/^two/,
	'Hooked negative string exception is not in the pointcut',
);

throws_ok(
	sub { Foo::three() },
	'Exception1',
	'Hooked negative object exception is not in the pointcut',
);

throws_ok(
	sub { Foo::four() },
	'Exception2',
	'Hooked negative object exception is not in the pointcut',
);

throws_ok(
	sub { Foo::five() },
	qr/^three/,
	'Hooked non-exception was trapped and threw an exception',
);





######################################################################
# Support Classes

package Foo;

sub one {
	die 'one';
}

sub two {
	die 'two';
}

sub three {
	Exception1->throw('one');
}

sub four {
	Exception2->throw('two');
}

sub five {
	return 'five';
}

package Exception1;

sub throw {
	my $class = shift;
	my $self  = bless [ @_ ], $class;
	die $self;
}

package Exception2;

sub throw {
	my $class = shift;
	my $self  = bless [ @_ ], $class;
	die $self;
}

1;