Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrite S19-command-line-options/02-dash-n.t
using is_run() from Test::Util
  • Loading branch information
usev6 committed Oct 22, 2014
1 parent 0e579ae commit 14144ac
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions S19-command-line-options/02-dash-n.t
Expand Up @@ -2,56 +2,58 @@ use v6;

use Test;

use lib 't/spec/packages';
use Test::Util;

plan 3;

=begin pod
Test -n implementation
Test C<-n> implementation
The -n command line switch mimics the Perl5 -n command line
The C<-n> command line switch mimics the Perl5 C<-n> command line
switch, and wraps the whole script in
for (lines) {
...
... # your script
};
=end pod

# L<S19/Reference/"Act like awk.">

my @examples = (
'-n -e .say',
'-ne .say',
'-e "" -ne .say',
);

plan +@examples;

diag "Running under $*OS";

my ($redir_in, $redir_out) = ("<", ">");

my $str = "
foo
my $str = "foo
bar
";

sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
my ($in_fn, $out_fn) = <temp-ex-input temp-ext-output> >>~>> nonce;
my $h = open("$in_fn", :w);
$h.print($str);
$h.close();

for @examples -> $ex {
my $command = "$*EXECUTABLE_NAME $ex $redir_in $in_fn $redir_out $out_fn";
diag $command;
run $command;

my $expected = $str;
my $got = slurp $out_fn;
unlink $out_fn;
is_run(
$str, # input
{
out => $str,
},
'-n -e .say works like cat',
:compiler-args['-n -e .say'],
);

is $got, $expected, "-n -e print works like cat";
}
is_run(
$str, # input
{
out => $str,
},
'-ne .say works like cat',
:compiler-args['-ne .say'],
);

unlink $in_fn;
# RT #107992
is_run(
$str, # input
{
status => 0,
out => '',
err => '',
},
'-n -e "" works like awk ""',
:compiler-args['-n -e ""'],
);

# vim: ft=perl6

0 comments on commit 14144ac

Please sign in to comment.