Skip to content

Instantly share code, notes, and snippets.

@usev6
Created February 25, 2015 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usev6/f9d0f6ca4e213e89b546 to your computer and use it in GitHub Desktop.
Save usev6/f9d0f6ca4e213e89b546 to your computer and use it in GitHub Desktop.
testing REPL behaviour
use v6;
use Test;
plan 1;
my $repl-input = 'my Int $t=4; $t.say;
$t.say';
my $cmd = $*DISTRO.is-win
?? "echo $repl-input | $*EXECUTABLE"
!! "echo '$repl-input' | $*EXECUTABLE";
is qqx[$cmd], "4\n4\n", 'OK';
@usev6
Copy link
Author

usev6 commented Feb 28, 2015

The following seems to work on Windows and Unix platforms.
[My goal was to feed multiple lines to rakudo's REPL and check the resulting output.]

use v6;
use Test;
plan 1;

my $quote;
my $separator;
if $*DISTRO.is-win {
    $quote     = "";
    $separator = "& ";
}
else {
    $quote     = "'";
    $separator = "; ";
}

sub feed_repl_with ( @lines ) {
    my $repl-input = '(' ~ (@lines.map: { 'echo ' ~ $quote ~ $_ ~ $quote }).join($separator) ~ ')';
    #say "Input: " ~ $repl-input;
    return qqx[$repl-input | $*EXECUTABLE];
}

my @input-lines;
@input-lines[0] = 'my Int $t=4; $t.say';
@input-lines[1] = '$t.say';

is feed_repl_with( @input-lines ).lines, (4, 4), 'OK';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment