File: code_const.t

package info (click to toggle)
liblexical-var-perl 0.010-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 464 kB
  • sloc: perl: 76; makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (4)
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
use warnings;
use strict;

use Test::More;
BEGIN {
	plan skip_all => "bare subs impossible on this perl"
		if "$]" < 5.011002;
}
plan tests => 6;

BEGIN { $SIG{__WARN__} = sub { die "WARNING: $_[0]" }; }

is eval q{
	use Lexical::Var '&foo' => sub () { my $x=123 };
	foo();
}, 123;

# test that non-constant foo() is not a const op
eval q{
	use Lexical::Var '&foo' => sub () { my $x=123 };
	foo() = 456;
	die;
};
like $@, qr/\ACan't modify non-lvalue subroutine call /;

# test that non-constant foo() does not participate in constant folding
eval q{
	die;
	use Lexical::Var '&foo' => sub () { my $x=123 };
	!foo() = 456;
};
like $@, qr/\ACan't modify not /;

is eval q{
	use Lexical::Var '&foo' => sub () { 123 };
	foo();
}, 123;

# test that constant foo() is a const op
eval q{
	die;
	use Lexical::Var '&foo' => sub () { 123 };
	foo() = 456;
};
like $@, qr/\ACan't modify constant item /;

# test that constant foo() participates in constant folding
eval q{
	die;
	use Lexical::Var '&foo' => sub () { 123 };
	!foo() = 456;
};
like $@, qr/\ACan't modify constant item /;

1;