/
evalfile.t
54 lines (46 loc) 路 1.54 KB
/
evalfile.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
use v6;
use lib $?FILE.IO.parent(2).add("packages");
use Test;
use Test::Util;
plan 3;
# L<S29/Context/"=item EVALFILE">
sub nonce () { return (".{$*PID}." ~ 1000.rand.Int) }
{
my $tmpfile = "temp-evalfile" ~ nonce();
{
my $fh = open("$tmpfile", :w);
say $fh: "32 + 10";
close $fh;
}
is EVALFILE($tmpfile), 42, "EVALFILE() works";
END { unlink $tmpfile }
}
{
my $tmpfile = "temp-evalfile-lexical" ~ nonce();
{
my $fh = open("$tmpfile", :w);
say $fh: '$some_var';
close $fh;
}
my $some_var = 'samovar';
is EVALFILE($tmpfile), 'samovar', "EVALFILE() evaluated code can see lexicals";
END { unlink $tmpfile }
}
subtest '&EVALFILE respects compiler encoding options' => {
plan 3;
my $path = make-temp-file;
$path.spurt: :enc<iso-8859-1>, 'print "I 庐 U"';
# The $result Buf was obtained by running:
# perl6 -e '"foo".IO.spurt: q|print "I 庐 U"|, :enc<iso-8859-1>' |
# perl6 -e 'run(:out, 芦perl6 --encoding=iso-8859-1 foo禄).out.slurp-rest(:bin).perl.say'
my $result = Buf[uint8].new(73,32,194,174,32,85);
given run :out, :err, $*EXECUTABLE, '--encoding=iso-8859-1', '-e',
'use MONKEY-SEE-NO-EVAL; EVALFILE \qq[$path.absolute.perl()]'
{
#?rakudo.jvm todo 'problem with equivalence of Buf objects, RT #128041'
is-deeply .out.slurp-rest(:bin), $result, 'STDOUT has right data';
is-deeply .err.slurp, '', 'STDERR is empty';
is-deeply .exitcode, 0, 'exitcode is correct';
}
}
# vim: ft=perl6