Skip to content

Commit 3bfca3a

Browse files
committed
Bring tests back from bitrot since 2009
1 parent bf3ad8c commit 3bfca3a

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

S04-phasers/in-eval.t

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,62 @@ use v6;
44

55
use Test;
66

7+
plan 35;
78

89
# L<S04/Phasers/Code "generated at run time" "still fire off"
910
# "can't" "travel back in time" >
10-
11-
my ($handle);
12-
13-
our $h;
14-
1511
{
1612
my $h;
13+
my $handle;
1714

18-
eval '$handle = { $h ~= "1"; START { $h ~= "F" }; $h ~= "2" }';
19-
ok $! !~~ Exception, 'eval START {...} works';
15+
eval '$handle = { $h ~= "1"; once { $h ~= "F" }; $h ~= "2" }';
16+
ok $! !~~ Exception, 'eval once {...} works';
2017

21-
nok $h.defined, 'START {...} has not run yet';
22-
lives_ok { $handle() }, 'can run code with START block';
23-
is $h, '1F2', 'START {...} fired';
24-
lives_ok { $handle() }, 'can run code with START block again';
25-
is $h, '1F212', 'START {...} fired only once';
18+
nok $h.defined, 'once {...} has not run yet';
19+
lives_ok { $handle() }, 'can run code with once block';
20+
is $h, '1F2', 'once {...} fired';
21+
lives_ok { $handle() }, 'can run code with once block again';
22+
is $h, '1F212', 'once {...} fired only once';
2623

2724
# test that it runs again for a clone of $handle
2825
$h = '';
29-
my $start_clone = $handle.clone;
26+
my $clone = $handle.clone;
3027
is $h, '', 'cloning code does not run anything';
31-
lives_ok { $start_clone() }, 'can run clone of code with START block';
32-
#?rakudo todo 'clone of code with START should run START again'
33-
is $h, '1F2', 'START {...} fired again for the clone';
34-
lives_ok { $start_clone() }, 'can run clone of START block code again';
35-
#?rakudo todo 'clone of code with START should not run START again'
36-
is $h, '1F212', 'cloned START {...} fired only once';
28+
lives_ok { $clone() }, 'can run clone of code with once block';
29+
is $h, '1F2', 'once {...} fired again for the clone';
30+
lives_ok { $clone() }, 'can run clone of once block code again';
31+
is $h, '1F212', 'cloned once {...} fired only once';
3732
}
3833

3934
{
4035
my $h;
36+
my $handle;
4137

42-
eval '$handle = { $h =~ "r"; INIT { $h ~= "I" }; $h ~= "R" }';
38+
eval '$handle = { $h ~= "r"; INIT { $h ~= "I" }; $h ~= "R" }';
4339
ok $! !~~ Exception, 'eval INIT {...} works';
40+
#?rakudo todo 'not sure'
4441
nok $h.defined, 'INIT did not run at compile time';
45-
#?rakudo 4 todo 'Could not find non-existent sub INIT'
4642
lives_ok { $handle() }, 'can run code with INIT block';
4743
is $h, 'IrR', 'INIT {...} fires at run-time';
4844
lives_ok { $handle() }, 'can run code with INIT block again';
4945
is $h, 'IrRrR', 'INIT runs only once';
5046

51-
# TODO: test that it does not run again for a clone of $handle (?)
47+
# test that it runs again for a clone of $handle
48+
$h = '';
49+
my $clone = $handle.clone;
50+
is $h, '', 'cloning code does not run anything';
51+
lives_ok { $clone() }, 'can run clone of code with INIT block';
52+
is $h, 'rR', 'INIT {...} did not fire again for the clone';
5253
}
5354

5455
{
55-
our $h = Mu;
56+
my $h;
57+
my $handle;
5658

57-
eval '$handle = { our $h ~= "1"; CHECK { our $h ~= "C" };'
58-
~ ' our $h ~= "2"; BEGIN { our $h ~= "B" }; our $h ~= "3" }';
59+
eval '$handle = { $h ~= "1"; CHECK { $h ~= "C" };'
60+
~ '$h ~= "2"; BEGIN { $h ~= "B" }; $h ~= "3" }';
5961
ok $! !~~ Exception, 'eval CHECK {...} (and BEGIN {...}) works';
6062

61-
#?rakudo 5 todo 'Could not find non-existent sub CHECK'
6263
is $h, 'BC', 'CHECK and BEGIN blocks ran before run time';
6364
lives_ok { $handle() }, 'can run code with CHECK and BEGIN blocks';
6465
is $h, 'BC123', 'CHECK {...} runs at compile time after BEGIN';
@@ -67,32 +68,31 @@ our $h;
6768
}
6869

6970
{
70-
our $h = Mu;
71+
my $h;
72+
my $handle;
7173

72-
eval '$handle = { our $h ~= "1"; BEGIN { our $h ~= "B" }; our $h ~= "2" }';
74+
eval '$handle = { $h ~= "1"; BEGIN { $h ~= "B" }; $h ~= "2" }';
7375
ok $! !~~ Exception, 'eval BEGIN {...} works';
7476

7577
is $h, 'B', 'BEGIN ran before run time';
7678
lives_ok { $handle() }, 'can run code with BEGIN block';
7779
is $h, 'B12', 'BEGIN does not run again at run time';
7880
}
7981

80-
#?rakudo skip 'test harness does not see test result in END'
8182
{
83+
my $h = '';
84+
my $handle;
85+
8286
END {
83-
is our $end, '12E', 'the END {...} in eval has run already';
87+
is $h, '12E', 'the END {...} in eval has run already';
8488
}
85-
}
86-
87-
{
88-
our $end = Mu;
8989

90-
eval '$handle = { our $end ~= "1"; END { our $end ~= "E" }; our $end ~= "2" }';
90+
eval '$handle = { $h ~= "1"; END { $h ~= "E" }; $h ~= "2" }';
9191
ok $! !~~ Exception, 'eval END {...} works';
9292

93-
nok $end.defined, 'END {} has not run yet';
93+
is $h, '' , 'END {} has not run yet';
9494
lives_ok { $handle() }, 'can call code with END block';
95-
is $end, '12', 'END {} does not run at run time either';
95+
is $h, '12', 'END {} does not run at run time either';
9696
}
9797

9898
done;

0 commit comments

Comments
 (0)