| 1 | use v6; |
|---|
| 2 | |
|---|
| 3 | use Test; |
|---|
| 4 | |
|---|
| 5 | =begin pod |
|---|
| 6 | |
|---|
| 7 | Test evaluation of multiple C<-e> switches. |
|---|
| 8 | |
|---|
| 9 | Multiple C<-e> switches are supposed to work just |
|---|
| 10 | like C<join "\n"> concatenation . |
|---|
| 11 | |
|---|
| 12 | =end pod |
|---|
| 13 | |
|---|
| 14 | my @examples = ( |
|---|
| 15 | '-e print -e qq.Hello -e Pugs.', |
|---|
| 16 | '-e print -we qq.Hello -e Pugs.', |
|---|
| 17 | '-e print -wle qq.Hello -e Pugs.', |
|---|
| 18 | '-e print -weqq.Hello -e Pugs.', |
|---|
| 19 | '-e print -e qq.Hel. -e ";print" -e qq.lo. -e ";print" -e "qq.\nPugs."', |
|---|
| 20 | '-e print -e qq.Hel. -w -e ";print" -e qq.lo. -w -e ";print" -e "qq.\nPugs."', |
|---|
| 21 | ); |
|---|
| 22 | |
|---|
| 23 | plan +@examples +1; |
|---|
| 24 | if $*OS eq "browser" { |
|---|
| 25 | skip_rest "Programs running in browsers don't have access to regular IO."; |
|---|
| 26 | exit; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | diag "Running under $*OS"; |
|---|
| 30 | |
|---|
| 31 | my $redir = ">"; |
|---|
| 32 | |
|---|
| 33 | if $*OS eq any <MSWin32 mingw msys cygwin> { |
|---|
| 34 | $redir = '>'; |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | sub nonce () { return (".{$*PID}." ~ (1..1000).pick) } |
|---|
| 38 | my $out_fn = "temp-ex-output" ~ nonce; |
|---|
| 39 | |
|---|
| 40 | for @examples -> $ex { |
|---|
| 41 | my $command = "$*EXECUTABLE_NAME $ex $redir $out_fn"; |
|---|
| 42 | diag $command; |
|---|
| 43 | run $command; |
|---|
| 44 | |
|---|
| 45 | my $expected = "Hello\nPugs"; |
|---|
| 46 | my $got = slurp $out_fn; |
|---|
| 47 | |
|---|
| 48 | is $got, $expected, "Multiple -e switches work and append the script"; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | my $command = qq[$*EXECUTABLE_NAME -e @ARGS.perl.say -e "" Hello Pugs $redir $out_fn]; |
|---|
| 52 | diag $command; |
|---|
| 53 | run $command; |
|---|
| 54 | |
|---|
| 55 | my @expected = <Hello Pugs>; |
|---|
| 56 | my $got = slurp $out_fn; |
|---|
| 57 | $got .= chomp; |
|---|
| 58 | if (substr($got,0,1) ~~ "\\") { |
|---|
| 59 | $got = substr($got,1); |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | my @got = eval $got; |
|---|
| 63 | # fail "FIXME platform specific"; |
|---|
| 64 | # ??? Worksforme on win32 (CORION) |
|---|
| 65 | is @got, @expected, "-e '' does not eat a following argument"; |
|---|
| 66 | |
|---|
| 67 | unlink $out_fn; |
|---|