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