Permalink
Browse files

Moved test to the corresponding spec folder and added smartlinks.

git-svn-id: http://svn.pugscode.org/pugs@27074 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 709a6f2 commit d13c85b71ce6fe7203069c3913f8d4c20758f136 rocket committed Jun 13, 2009
@@ -0,0 +1,69 @@
+use v6;
+
+use Test;
+
+=begin pod
+
+Test evaluation of multiple C<-e> switches.
+
+Multiple C<-e> switches are supposed to work just
+like C<join "\n"> concatenation .
+
+=end pod
+
+# L<S19/Reference/"Execute a single-line program.">
+
+my @examples = (
+ '-e print -e qq.Hello -e Pugs.',
+ '-e print -we qq.Hello -e Pugs.',
+ '-e print -wle qq.Hello -e Pugs.',
+ '-e print -weqq.Hello -e Pugs.',
+ '-e print -e qq.Hel. -e ";print" -e qq.lo. -e ";print" -e "qq.\nPugs."',
+ '-e print -e qq.Hel. -w -e ";print" -e qq.lo. -w -e ";print" -e "qq.\nPugs."',
+);
+
+plan +@examples +1;
+if $*OS eq "browser" {
+ skip_rest "Programs running in browsers don't have access to regular IO.";
+ exit;
+}
+
+diag "Running under $*OS";
+
+my $redir = ">";
+
+if $*OS eq any <MSWin32 mingw msys cygwin> {
+ $redir = '>';
+};
+
+sub nonce () { return (".{$*PID}." ~ (1..1000).pick) }
+my $out_fn = "temp-ex-output" ~ nonce;
+
+for @examples -> $ex {
+ my $command = "$*EXECUTABLE_NAME $ex $redir $out_fn";
+ diag $command;
+ run $command;
+
+ my $expected = "Hello\nPugs";
+ my $got = slurp $out_fn;
+
+ is $got, $expected, "Multiple -e switches work and append the script";
+}
+
+my $command = qq[$*EXECUTABLE_NAME -e @ARGS.perl.say -e "" Hello Pugs $redir $out_fn];
+diag $command;
+run $command;
+
+my @expected = <Hello Pugs>;
+my $got = slurp $out_fn;
+$got .= chomp;
+if (substr($got,0,1) ~~ "\\") {
+ $got = substr($got,1);
+};
+
+my @got = eval $got;
+# fail "FIXME platform specific";
+# ??? Worksforme on win32 (CORION)
+is @got, @expected, "-e '' does not eat a following argument";
+
+unlink $out_fn;
@@ -0,0 +1,59 @@
+use v6;
+
+use Test;
+
+=begin pod
+
+Test -n implementation
+
+The -n command line switch mimics the Perl5 -n command line
+switch, and wraps the whole script in
+
+ for (lines) {
+ ...
+ };
+
+=end pod
+
+# L<S19/Reference/"Act like awk.">
+
+my @examples = (
+ '-n -e .say',
+ '-ne .say',
+ '-e "" -ne .say',
+);
+
+plan +@examples;
+if $*OS eq "browser" {
+ skip_rest "Programs running in browsers don't have access to regular IO.";
+ exit;
+}
+
+diag "Running under $*OS";
+
+my ($redir_in, $redir_out) = ("<", ">");
+
+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 $got, $expected, "-n -e print works like cat";
+}
+
+unlink $in_fn;
@@ -0,0 +1,63 @@
+use v6;
+
+use Test;
+
+=begin pod
+
+Test C<-p> implementation
+
+The C<-p> command line switch mimics the Perl5 C<-p> command line
+switch, and wraps the whole script in
+
+ for (lines) {
+ ... # your script
+ .say;
+ };
+
+=end pod
+
+# L<S19/Reference/"Act like sed.">
+
+my @examples = (
+ '-p',
+ '-p "-e1;"',
+ '-pe ";"',
+ '-pe ""',
+ '-p "-e1;" "-e1;"',
+ '"-e1;" -p "-e1;"',
+);
+
+plan +@examples;
+if $*OS eq "browser" {
+ skip_rest "Programs running in browsers don't have access to regular IO.";
+ exit;
+}
+
+diag "Running under $*OS";
+
+my ($redir_in,$redir_out) = ("<", ">");
+
+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 $got, $expected, "$ex works like cat";
+}
+
+unlink $in_fn;

0 comments on commit d13c85b

Please sign in to comment.