|
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 | |
|---|
| 1 | use v6; |
|---|
| 2 | |
|---|
| 3 | use Test; |
|---|
| 4 | |
|---|
| 5 | =begin pod |
|---|
| 6 | |
|---|
| 7 | Test C<-p> implementation |
|---|
| 8 | |
|---|
| 9 | The C<-p> command line switch mimics the Perl5 C<-p> command line |
|---|
| 10 | switch, and wraps the whole script in |
|---|
| 11 | |
|---|
| 12 | while ($_ = =<>) { |
|---|
| 13 | ... # your script |
|---|
| 14 | say; |
|---|
| 15 | }; |
|---|
| 16 | |
|---|
| 17 | =end pod |
|---|
| 18 | |
|---|
| 19 | my @examples = ( |
|---|
| 20 | '-p', |
|---|
| 21 | '-p "-e1;"', |
|---|
| 22 | '-pe ";"', |
|---|
| 23 | '-pe ""', |
|---|
| 24 | '-p "-e1;" "-e1;"', |
|---|
| 25 | '"-e1;" -p "-e1;"', |
|---|
| 26 | ); |
|---|
| 27 | |
|---|
| 28 | plan +@examples; |
|---|
| 29 | if $*OS eq "browser" { |
|---|
| 30 | skip_rest "Programs running in browsers don't have access to regular IO."; |
|---|
| 31 | exit; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | diag "Running under $*OS"; |
|---|
| 35 | |
|---|
| 36 | my ($redir_in,$redir_out) = ("<", ">"); |
|---|
| 37 | |
|---|
| 38 | my $str = " |
|---|
| 39 | foo |
|---|
| 40 | bar |
|---|
| 41 | "; |
|---|
| 42 | |
|---|
| 43 | sub nonce () { return (".{$*PID}." ~ (1..1000).pick) } |
|---|
| 44 | my($in_fn, $out_fn) = <temp-ex-input temp-ext-output> >>~<< nonce; |
|---|
| 45 | my $h = open("$in_fn", :w); |
|---|
| 46 | $h.print($str); |
|---|
| 47 | $h.close(); |
|---|
| 48 | |
|---|
| 49 | for @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 | |
|---|
| 61 | unlink $in_fn; |
|---|