-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypealias.t
executable file
·66 lines (55 loc) · 1.17 KB
/
typealias.t
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
#!/usr/bin/env perl
# -*- mode: perl; coding: utf-8 -*-
#----------------------------------------
use strict;
use warnings qw(FATAL all NONFATAL misc);
use FindBin; BEGIN { do "$FindBin::Bin/t_lib.pl" }
#----------------------------------------
use YATT::Lite::Util qw/define_const/;
sub make_type_alias {
my $callpack = caller;
foreach my $name (@_) {
my $fullname = join("::", $callpack, $name);
{
local $@; eval "package $fullname"; die $@ if $@;
}
define_const($fullname, $fullname);
}
}
use Test::More;
my $common = <<'END';
package testing::dummy%d; sub MY () {__PACKAGE__}
use strict;
BEGIN {::make_type_alias(qw/Foo Bar Baz/)}
END
{
my $script = sprintf($common, 1). <<'END';
sub t1 {
join(", ", Foo);
}
1;
END
ok eval($script), "use of constant sub";
is $@, '', "no error";
}
{
my $script = sprintf($common, 2). <<'END';
sub t2 {
(my Foo $foo) = @_;
}
1;
END
ok eval($script), "use of constant sub for my Dog \$spot";
is $@, '', "no error";
}
{
my $script = sprintf($common, 3). <<'END';
sub t3 {
(my MY $foo) = @_;
}
1;
END
ok eval($script), "use of constant sub for my Dog \$spot";
is $@, '', "no error";
}
done_testing();