File: 20_lexical_sub.t

package info (click to toggle)
libdata-util-perl 0.67-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: perl: 2,958; ansic: 416; makefile: 8
file content (52 lines) | stat: -rw-r--r-- 706 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
#!perl -w
use strict;
use Test::More tests => 9;
use Test::Exception;

use FindBin qw($Bin);
use lib "$Bin/../example/lib";

BEGIN{
	package Foo;
	use Sub::Exporter::Lexical
		exports => [
			qw(foo),
			bar => \&bar,
			baz => \&bar,
		],
	;

	sub foo{ 'foo' }

	sub bar{ 'bar' }

	$INC{'Foo.pm'} = __FILE__;
}

{
	use Foo;

	lives_ok{
		is foo(), 'foo';
	} 'call lexical sub';

	lives_ok{
		is bar(), 'bar';
	} 'call lexical sub';

	lives_ok{
		is baz(), 'bar';
	} 'call lexical sub';
}

throws_ok{
	isnt foo(), 'foo';
} qr/Undefined subroutine \&main::foo/;

throws_ok{
	isnt bar(), 'bar';
} qr/Undefined subroutine \&main::bar/;

throws_ok{
	isnt baz(), 'bar';
} qr/Undefined subroutine \&main::baz/;;