Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Spec &EVAL(Blob) and &EVALFILE's encoding use
- EVAL/EVALFILE must eval using the same encoding as reading the
    source file in $lang would, per S29

RT#122256: https://rt.perl.org/Ticket/Display.html?id=122256
Rakudo impl: rakudo/rakudo@6c928d61d9
  • Loading branch information
zoffixznet committed Oct 5, 2017
1 parent 48ea502 commit 6949cb1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
40 changes: 39 additions & 1 deletion S01-perl-5-integration/eval_lex.t
@@ -1,6 +1,8 @@
use v6;
use lib <t/spec/packages/>;
use Test;
plan 1;
use Test::Util;
plan 2;

unless (try { EVAL("1", :lang<Perl5>) }) {
skip-rest;
Expand All @@ -12,4 +14,40 @@ my $self = "some text";
#?rakudo todo ''
is ~EVAL(q/"self is $self"/,:lang<Perl5>),"self is some text","lexical inside an EVAL";

subtest 'EVAL/EVALFILE evals Buf like perl would execute source file' => {
plan 2;

# The $result Buf was obtained by running:
# perl -e 'no warnings; print qq|♥\x{26666}|; { use utf8; print qq|♥\x{26666}| }' |
# ./perl6 -e '$*IN.encoding(Nil); $*IN.slurp.perl.say'
my $result = Buf[uint8].new(195,162,194,153,194,165,240,166,153,166,226,153,165,240,166,153,166);

my $code = no warnings; print qq|♥\x{26666}|; { use utf8; print qq|♥\x{26666}| };

subtest 'EVAL' => {
plan 3;
given run :out, :err, $*EXECUTABLE, '-e',
'use MONKEY-SEE-NO-EVAL; EVAL :lang<Perl5>, \qq[$code.perl()]'
{
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';
}
}

subtest 'EVALFILE' => {
plan 3;
my $path = make-temp-file;
$path.spurt: $code;
given run :out, :err, $*EXECUTABLE, '-e',
'use MONKEY-SEE-NO-EVAL; EVALFILE :lang<Perl5>,'
~ $path.absolute.perl
{
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
26 changes: 25 additions & 1 deletion S29-context/eval.t
@@ -1,7 +1,9 @@
use v6;
use lib <t/spec/packages>;
use nqp;
use Test;
plan 24;
use Test::Util;
plan 25;

# L<S29/Context/"=item EVAL">

Expand Down Expand Up @@ -110,4 +112,26 @@ is('$rt115344'.EVAL, $rt115344, 'method form of EVAL sees outer lexicals');
"EVAL's package does not leak to the surrounding compilation unit";
}

subtest 'EVAL(Buf)' => {
plan 2;
is_run 'use MONKEY-SEE-NO-EVAL; EVAL q|print "I ® U"|.encode',
{:out('I ® U'), :err(''), :0status}, 'utf8 Buf';

subtest '--encoding=iso-8859-1 + iso-8859-1 buf' => {
plan 3;
# 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; EVAL q|print "I ® U"|.encode: "iso-8859-1"'
{
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
22 changes: 21 additions & 1 deletion S29-context/evalfile.t
@@ -1,7 +1,9 @@
use v6;
use lib <t/spec/packages/>;
use Test;
use Test::Util;

plan 2;
plan 3;

# L<S29/Context/"=item EVALFILE">

Expand Down Expand Up @@ -30,4 +32,22 @@ sub nonce () { return (".{$*PID}." ~ 1000.rand.Int) }
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()]'
{
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

0 comments on commit 6949cb1

Please sign in to comment.