Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 109 lines (86 sloc) 2.699 kB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
2 use Test;
0782842 @jnthn Add test for RT #124304.
jnthn authored
3 plan 23;
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
4
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
5 # L<S29/Context/"=item EVAL">
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
6
ab398b1 [t/spec] Converted pod markers in pod6
cosimo authored
7 =begin pod
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
8
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
9 Tests for the EVAL() builtin
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
10
ab398b1 [t/spec] Converted pod markers in pod6
cosimo authored
11 =end pod
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
12
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
13 # EVAL should evaluate the code in the lexical scope of EVAL's caller
9bfcf50 [t/spec] some test enhancements, corrections and fudging for rakudo.
moritz authored
14 {
15 sub make_eval_closure {
8dc7d4b [t/spec] mark various tests that intentionally declare things that ar…
lwall authored
16 my $a = 5; #OK not used
9bfcf50 [t/spec] some test enhancements, corrections and fudging for rakudo.
moritz authored
17 return sub ($s) {
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
18 EVAL $s
9bfcf50 [t/spec] some test enhancements, corrections and fudging for rakudo.
moritz authored
19 };
20 };
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
21 is(make_eval_closure().('$a'), 5, 'EVAL runs code in the proper lexical scope');
9bfcf50 [t/spec] some test enhancements, corrections and fudging for rakudo.
moritz authored
22 }
44d3aab [t/spec] Fudged S29-context/eval.t for rakudo
azawawi authored
23
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
24 is(EVAL('5'), 5, 'simple EVAL works and returns the value');
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
25 my $foo = 1234;
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
26 is(EVAL('$foo'), $foo, 'simple EVAL using variable defined outside');
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
27
28 # traps die?
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
29 dies-ok {EVAL('die; 1')}, "EVAL does not trap die";
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
30
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
31 dies-ok {EVAL '1 1)'}, "EVAL throws on syntax error";
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
32
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
33 dies-ok {EVAL 'use Poison; 1'}, "EVAL dies on fatal use";
d3c26da Refactored eval tests, moved under t/spec/S29-context/
cosimo authored
34
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
35 # L<S04/Exception handlers/Perl 6's EVAL function only evaluates strings, not blocks.>
709e414 @lizmat s/dies_ok/dies-ok/g
lizmat authored
36 dies-ok({EVAL {; 42} }, 'block EVAL is gone');
eeccfae [t/spec] tests for RT #63978
moritz authored
37
5bab36f @FROGGS eval => EVAL in S14 to S32
FROGGS authored
38 # RT #63978, EVAL didn't work in methods
eeccfae [t/spec] tests for RT #63978
moritz authored
39 {
376a828 [t/spec] simplfiy eval.t to not use lexical classes
moritz authored
40 class EvalTester1 {
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
41 method e($s) { EVAL $s };
eeccfae [t/spec] tests for RT #63978
moritz authored
42 }
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
43 is EvalTester1.e('5'), 5, 'EVAL works inside class methods';
44 is EvalTester1.new.e('5'), 5, 'EVAL works inside instance methods';
eeccfae [t/spec] tests for RT #63978
moritz authored
45 }
46
47 {
48 my $x = 5;
376a828 [t/spec] simplfiy eval.t to not use lexical classes
moritz authored
49 class EvalTester2 {
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
50 method e($s) { EVAL "$s + \$x" };
eeccfae [t/spec] tests for RT #63978
moritz authored
51 }
376a828 [t/spec] simplfiy eval.t to not use lexical classes
moritz authored
52 is EvalTester2.e('1'), 6,
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
53 'EVAL works inside class methods, with outer lexicals';
376a828 [t/spec] simplfiy eval.t to not use lexical classes
moritz authored
54 is EvalTester2.new.e('1'), 6,
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
55 'EVAL works inside instance methods, with outer lexicals';
eeccfae [t/spec] tests for RT #63978
moritz authored
56 }
e72d377 [t/spec] a basic test for eval(Buf) (added to spec in r2751)
moritz authored
57
8b6048b @moritz Revert "Remove # chars from fudge messages"
moritz authored
58 #?rakudo skip 'EVAL(Buf) RT #122256'
3a7da94 @coke niecza fudging
coke authored
59 #?niecza skip 'Unable to resolve method encode in class Str'
320794d @lizmat Add test for Buf.EVAL
lizmat authored
60 {
61 is EVAL("'møp'".encode('UTF-8')), 'møp', 'EVAL(Buf)';
62 is "'møp'".encode('UTF-8').EVAL, 'møp', 'Buf.EVAL';
63 }
e72d377 [t/spec] a basic test for eval(Buf) (added to spec in r2751)
moritz authored
64
62f3b93 [t/spec] "eval 1" should coerce to a string instead of die
kyle authored
65 {
5bab36f @FROGGS eval => EVAL in S14 to S32
FROGGS authored
66 is EVAL(88), 88, 'EVAL of non-string works';
4af01d7 @lizmat Unfudge now passing EVAL tests (and add .EVAL)
lizmat authored
67 is 88.EVAL, 88, '.EVAL of non-string works';
ea4d235 [t/spec] begin cleansing of eval and todos that should skip
kyle authored
68
62f3b93 [t/spec] "eval 1" should coerce to a string instead of die
kyle authored
69 my $number = 2;
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
70 is EVAL($number), $number, 'EVAL of non-string variable works';
4af01d7 @lizmat Unfudge now passing EVAL tests (and add .EVAL)
lizmat authored
71 is $number.EVAL, $number, '.EVAL of non-string variable works';
62f3b93 [t/spec] "eval 1" should coerce to a string instead of die
kyle authored
72 }
73
901c278 @moritz RT #77646, same &eval executed multiple times without outer block
moritz authored
74 # RT #77646
75 {
76 my $x = 0;
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
77 EVAL '$x++' for 1..4;
78 is $x, 4, 'can execute the same EVAL multiple times, without surrounding block';
901c278 @moritz RT #77646, same &eval executed multiple times without outer block
moritz authored
79
80 }
62f3b93 [t/spec] "eval 1" should coerce to a string instead of die
kyle authored
81
a4148aa @kyleha [eval.t] Test for RT 112472 -- bad error message for eval of bogus la…
kyleha authored
82 # RT 112472
e2f3f78 @colomon Refudge for niecza.
colomon authored
83 #?niecza todo "No :lang argument yet..."
a4148aa @kyleha [eval.t] Test for RT 112472 -- bad error message for eval of bogus la…
kyleha authored
84 {
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
85 try EVAL(:lang<rt112472>, '1');
86 ok "$!" ~~ / 'rt112472' /, 'EVAL in bogus language mentions the language';
a4148aa @kyleha [eval.t] Test for RT 112472 -- bad error message for eval of bogus la…
kyleha authored
87 }
88
6d78c06 @edwinst Added spectest for #115344: [BUG] method form of eval is lexically ch…
edwinst authored
89 # RT 115344
90 my $rt115344 = 115344;
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
91 #?niecza skip 'method form of EVAL does not see outer lexicals'
92 is('$rt115344'.EVAL, $rt115344, 'method form of EVAL sees outer lexicals');
6d78c06 @edwinst Added spectest for #115344: [BUG] method form of eval is lexically ch…
edwinst authored
93
30ac27f @coke add test for RT#115774
coke authored
94 # RT #115774
7f7fa6e @colomon Fudge for Niecza.
colomon authored
95 #?niecza skip "int NYI"
30ac27f @coke add test for RT#115774
coke authored
96 {
8fa1e64 @moritz star to switch some eval()s to EVAL
moritz authored
97 my int $a; EVAL('');
98 ok(1, "presence of low level types doesn't cause EVAL error")
30ac27f @coke add test for RT#115774
coke authored
99 }
100
0782842 @jnthn Add test for RT #124304.
jnthn authored
101 # RT #124304
102 {
103 my \a = rand;
9f47446 @lizmat s/lives_ok/lives-ok/g
lizmat authored
104 lives-ok { EVAL 'a' }, 'Can EVAL with a sigilless var';
0782842 @jnthn Add test for RT #124304.
jnthn authored
105 is EVAL('a'), a, 'EVAL with sigilless var gives correct result';
106 }
30ac27f @coke add test for RT#115774
coke authored
107
e72d377 [t/spec] a basic test for eval(Buf) (added to spec in r2751)
moritz authored
108 # vim: ft=perl6
Something went wrong with that request. Please try again.