root/t/run/02-dash-n.t

Revision 22093, 0.9 kB (checked in by lwall, 4 months ago)

[t] more system, require, does, defer, label cleanup

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1use v6;
2
3use Test;
4
5=begin pod
6
7Test -n implementation
8
9The -n command line switch mimics the Perl5 -n command line
10switch, and wraps the whole script in
11
12  while (=<>) {
13    ...
14  };
15
16=end pod
17
18my @examples = (
19  '-n -e .say',
20  '-ne .say',
21  '-e "" -ne .say',
22);
23
24plan +@examples;
25if $*OS eq "browser" {
26  skip_rest "Programs running in browsers don't have access to regular IO.";
27  exit;
28}
29
30diag "Running under $*OS";
31
32my ($redir_in, $redir_out) = ("<", ">");
33
34my $str = "
35foo
36bar
37";
38
39sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
40my($in_fn, $out_fn) = <temp-ex-input temp-ext-output> >>~<< nonce;
41my $h = open("$in_fn", :w);
42$h.print($str);
43$h.close();
44
45for @examples -> $ex {
46  my $command = "$*EXECUTABLE_NAME $ex $redir_in $in_fn $redir_out $out_fn";
47  diag $command;
48  run $command;
49
50  my $expected = $str;
51  my $got      = slurp $out_fn;
52  unlink $out_fn;
53
54  is $got, $expected, "-n -e print works like cat";
55}
56
57unlink $in_fn;
Note: See TracBrowser for help on using the browser.