xref: /openbsd-src/gnu/usr.bin/perl/ext/XS-APItest/t/clone-with-stack.t (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1#!perl
2
3use strict;
4use warnings;
5
6require "../../t/test.pl";
7
8use XS::APItest;
9
10# clone_with_stack creates a clone of the perl interpreter including
11# the stack, then destroys the original interpreter and runs the
12# remaining code using the new one.
13# This is like doing a psuedo-fork and exiting the parent.
14
15use Config;
16if (not $Config{'useithreads'}) {
17    skip_all("clone_with_stack requires threads");
18}
19
20plan(4);
21
22fresh_perl_is( <<'----', <<'====', undef, "minimal clone_with_stack" );
23use XS::APItest;
24clone_with_stack();
25print "ok\n";
26----
27ok
28====
29
30fresh_perl_is( <<'----', <<'====', undef, "inside a subroutine" );
31use XS::APItest;
32sub f {
33    clone_with_stack();
34}
35f();
36print "ok\n";
37----
38ok
39====
40
41{
42    local our $TODO = "clone_with_stack inside a begin block";
43    fresh_perl_is( <<'----', <<'====', undef, "inside a BEGIN block" );
44use XS::APItest;
45BEGIN {
46    clone_with_stack();
47}
48print "ok\n";
49----
50ok
51====
52
53}
54
55{
56    fresh_perl_is( <<'----', <<'====', undef, "clone stack" );
57use XS::APItest;
58sub f {
59    clone_with_stack();
60    0..4;
61}
62print 'X-', 'Y-', join(':', f()), "-Z\n";
63----
64X-Y-0:1:2:3:4-Z
65====
66
67}
68