root/t/run/03-dash-p.t

Revision 22093, 1.0 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 C<-p> implementation
8
9The C<-p> command line switch mimics the Perl5 C<-p> command line
10switch, and wraps the whole script in
11
12  while ($_ = =<>) {
13    ...         # your script
14    say;
15  };
16
17=end pod
18
19my @examples = (
20  '-p',
21  '-p "-e1;"',
22  '-pe ";"',
23  '-pe ""',
24  '-p "-e1;" "-e1;"',
25  '"-e1;" -p "-e1;"',
26);
27
28plan +@examples;
29if $*OS eq "browser" {
30  skip_rest "Programs running in browsers don't have access to regular IO.";
31  exit;
32}
33
34diag "Running under $*OS";
35
36my ($redir_in,$redir_out) = ("<", ">");
37
38my $str = "
39foo
40bar
41";
42
43sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
44my($in_fn, $out_fn) = <temp-ex-input temp-ext-output> >>~<< nonce;
45my $h = open("$in_fn", :w);
46$h.print($str);
47$h.close();
48
49for @examples -> $ex {
50  my $command = "$*EXECUTABLE_NAME $ex $redir_in $in_fn $redir_out $out_fn";
51  diag $command;
52  run $command;
53
54  my $expected = $str;
55  my $got      = slurp $out_fn;
56  unlink $out_fn;
57
58  is $got, $expected, "$ex works like cat";
59}
60
61unlink $in_fn;
Note: See TracBrowser for help on using the browser.