3 # Minimally test if dump() behaves as expected
10 skip_all_if_miniperl();
14 use File::Temp qw(tempdir);
18 skip_all("only tested on devel builds")
19 unless $Config{usedevel};
21 # there may be other operating systems where it makes sense, but
22 # there are some where it isn't, so limit the platforms we test
23 # this on. Also this needs to be a platform that fully supports
24 # fork() and waitpid().
26 skip_all("no point in dumping on $^O")
27 unless $^O =~ /^(linux|.*bsd|solaris)$/;
29 skip_all("avoid coredump under ASan")
30 if $Config{ccflags} =~ /-fsanitize=/;
32 # execute in a work directory so File::Temp can clean up core dumps
33 my $tmp = tempdir(CLEANUP => 1);
37 # on systems which don't make $^X absolute which_perl() in test.pl won't
38 # return an absolute path, so once we change directories it can't
39 # find ./perl, resulting in test failures
40 $^X = File::Spec->rel2abs($^X);
43 or skip_all("Cannot chdir to work directory");
47 # Depending on how perl is built, there may be extraneous stuff on stderr
48 # such as "Aborted", which isn't caught by the '2>&1' that
49 # fresh_perl_like() does. So execute each dump() in a sub-process.
52 # fresh_perl_like() ends up doing a `` which invokes a shell with 2 args:
54 # "sh", "-c", "perl /tmp/foo 2>&1"
56 # When the perl process coredumps after calling dump(), the parent
57 # sh sees that the exit of the child flags a coredump and so prints
58 # something like the following to stderr:
60 # sh: line 1: 17605 Aborted (core dumped)
62 # Note that the '2>&1' only applies to the perl process, not to the sh
64 # By do the dump in a child, the parent perl process exits back to sh with
65 # a normal exit value, so sh won't complain.
67 fresh_perl_like(<<'PROG', qr/\AA(?!B\z)/, {}, "plain dump quits");
70 die "fork: $!\n" unless defined $pid;
83 fresh_perl_like(<<'PROG', qr/A(?!B\z)/, {}, "dump with label quits");
86 die "fork: $!\n" unless defined $pid;
100 chdir $start if defined $start;