summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-03-18 14:10:33 +0000
committerDavid Mitchell <davem@iabyn.com>2015-03-18 14:13:45 +0000
commit49c4aee9770d41c2fd7866800ef51cfa28e02b58 (patch)
treeb85cb9c1aeeb7856a3f89236c5af8b69c9d2e954
parentcfd9941d0c907d687a244cc0da02119216157379 (diff)
downloadperl-49c4aee9770d41c2fd7866800ef51cfa28e02b58.tar.gz
t/op/dump.t: silence 'Aborted' messages on stderr
On some platforms, t/op/dump.t produces extraneous (and scary) sh: line 1: 17605 Aborted (core dumped) style messages on stderr. Do a fork in each test to avoid this.
-rw-r--r--t/op/dump.t56
1 files changed, 46 insertions, 10 deletions
diff --git a/t/op/dump.t b/t/op/dump.t
index a2e320f4da..a8586432a9 100644
--- a/t/op/dump.t
+++ b/t/op/dump.t
@@ -19,7 +19,9 @@ skip_all("only tested on devel builds")
# there may be other operating systems where it makes sense, but
# there are some where it isn't, so limit the platforms we test
-# this on
+# this on. Also this needs to be a platform that fully supports
+# fork() and waitpid().
+
skip_all("no point in dumping on $^O")
unless $^O =~ /^(linux|.*bsd|solaris)$/;
@@ -33,22 +35,56 @@ chdir $tmp
plan(2);
-# depending on how perl is built there may be extra output after
-# the A such as "Aborted".
+# Depending on how perl is built, there may be extraneous stuff on stderr
+# such as "Aborted", which isn't caught by the '2>&1' that
+# fresh_perl_like() does. So execute each dump() in a sub-process.
+#
+# In detail:
+# fresh_perl_like() ends up doing a `` which invokes a shell with 2 args:
+#
+# "sh", "-c", "perl /tmp/foo 2>&1"
+#
+# When the perl process coredumps after calling dump(), the parent
+# sh sees that the exit of the child flags a coredump and so prints
+# something like the following to stderr:
+#
+# sh: line 1: 17605 Aborted (core dumped)
+#
+# Note that the '2>&1' only applies to the perl process, not to the sh
+# command itself.
+# By do the dump in a child, the parent perl process exits back to sh with
+# a normal exit value, so sh won't complain.
fresh_perl_like(<<'PROG', qr/\AA(?!B\z)/, {}, "plain dump quits");
++$|;
-print qq(A);
-dump;
-print qq(B);
+my $pid = fork;
+die "fork: $!\n" unless defined $pid;
+if ($pid) {
+ # parent
+ waitpid($pid, 0);
+}
+else {
+ # child
+ print qq(A);
+ dump;
+ print qq(B);
+}
PROG
fresh_perl_like(<<'PROG', qr/A(?!B\z)/, {}, "dump with label quits");
++$|;
-print qq(A);
-dump foo;
-foo:
-print qq(B);
+my $pid = fork;
+die "fork: $!\n" unless defined $pid;
+if ($pid) {
+ # parent
+ waitpid($pid, 0);
+}
+else {
+ print qq(A);
+ dump foo;
+ foo:
+ print qq(B);
+}
PROG
END {