-
Notifications
You must be signed in to change notification settings - Fork 135
/
check.t
37 lines (28 loc) · 853 Bytes
/
check.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
use v6;
use Test;
plan 5;
# L<S04/"Phasers"/CHECK "at compile time" ALAP>
# CHECK {...} block in "void" context
{
my $str;
BEGIN { $str ~= "begin1 "; }
CHECK { $str ~= "check "; }
BEGIN { $str ~= "begin2 "; }
is $str, "begin1 begin2 check ", "check blocks run after begin blocks";
}
{
my $str;
CHECK { $str ~= "check1 "; }
BEGIN { $str ~= "begin "; }
CHECK { $str ~= "check2 "; }
is $str, "begin check2 check1 ", "check blocks run in reverse order";
}
# CHECK {...} blocks as rvalues
{
my $str;
my $handle = { my $retval = CHECK { $str ~= 'C' } };
is $handle(), 'C', 'our CHECK {...} block returned the correct var (1)';
is $handle(), 'C', 'our CHECK {...} block returned the correct var (2)';
is $str, 'C', 'our rvalue CHECK {...} block was executed exactly once';
}
# vim: ft=perl6