Skip to content

Commit 6078d1e

Browse files
committed
add test of XS loading other XS, using C symbols within
1 parent 87d2a45 commit 6078d1e

File tree

1 file changed

+87
-0
lines changed
  • t/lib/MakeMaker/Test/Setup

1 file changed

+87
-0
lines changed

t/lib/MakeMaker/Test/Setup/XS.pm

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,91 @@ $label2files{subdirs} = +{
179179
};
180180
virtual_rename('subdirs', 'lib/XS/Test.pm', 'Test.pm');
181181

182+
# to mimic ExtUtils::Depends-facilitated B::Hooks::OP::Check
183+
$label2files{eud_produce} = +{
184+
%{ $label2files{basic} }, # make copy
185+
'Makefile.PL' => sprintf(
186+
$MAKEFILEPL, 'Other', 'Other.pm', qq{},
187+
q{
188+
DEFINE => '-DINVAR=input',
189+
FUNCLIST => [qw(is_odd)],
190+
DL_FUNCS => { 'XS::Other' => [] },
191+
},
192+
),
193+
'Other.pm' => do {
194+
my $t = $PM_OTHER; $t =~ s:bootstrap:sub dl_load_flags { 0x01 }\n$&:g; $t
195+
},
196+
'Other.xs' => $XS_OTHER,
197+
't/is_even.t' => $T_OTHER,
198+
};
199+
delete @{ $label2files{eud_produce} }{qw(lib/XS/Test.pm Test.xs)};
200+
201+
# to mimic ExtUtils::Depends-facilitated consuming B::Hooks::OP::Check
202+
$label2files{eud_consume} = +{
203+
%{ $label2files{basic} }, # make copy
204+
'Makefile.PL' => <<'EOF' .
205+
use File::Spec::Functions;
206+
my $root; BEGIN {$root = catdir(updir, qw(XS-Testeud_produce blib arch));}
207+
EOF
208+
sprintf(
209+
$MAKEFILEPL, 'Test', 'Test.pm', qq{},
210+
q{
211+
DEFINE => '-DINVAR=input',
212+
LDFROM => join(' ', '$(OBJECT)', map _quote_if_space($_), find_extra_libs({'XS::Other'=>undef}, [$root])),
213+
},
214+
) . <<'EOF',
215+
use Config;
216+
use File::Spec::Functions;
217+
sub _quote_if_space { $_[0] =~ / / ? qq{"$_[0]"} : $_[0] }
218+
my %exts; BEGIN { %exts = (
219+
MSWin32 => [ ".lib", ".$Config{dlext}", $Config{_a} ],
220+
cygwin => [ '.dll' ],
221+
android => [ ".$Config{dlext}" ],
222+
); }
223+
sub find_extra_libs {
224+
my ($deps, $search) = @_;
225+
return () if !keys %$deps;
226+
return () unless my $exts = $exts{$^O};
227+
my @found_libs = ();
228+
DEP: foreach my $name (keys %$deps) {
229+
my @parts = split /::/, $name;
230+
my $stem = defined &DynaLoader::mod2fname
231+
? DynaLoader::mod2fname(\@parts) : $parts[-1];
232+
my @bases = map $stem.$_, @$exts;
233+
for my $dir (grep -d, @$search) { # only extant dirs
234+
my ($found) = grep -f, map catfile($dir, 'auto', @parts, $_), @bases;
235+
next if !defined $found;
236+
push @found_libs, $found;
237+
next DEP;
238+
}
239+
}
240+
@found_libs;
241+
}
242+
EOF
243+
'Test.pm' => do {
244+
my $t = $PM_TEST; $t =~ s:is_even:is_odd:g;
245+
$t =~ s/bootstrap/
246+
use File::Spec::Functions;
247+
my \$root; BEGIN {\$root = catdir(updir, qw(XS-Testeud_produce blib));}
248+
use lib map catdir(\$root, \$_), qw(lib arch);
249+
require XS::Other;\n$&
250+
/g;
251+
$t
252+
},
253+
'Test.xs' => do {
254+
my $t = $XS_OTHER; $t =~ s:Other:Test:g; $t =~ s:\{.*?\}:;:; $t
255+
},
256+
't/is_even.t' => <<'END',
257+
use strict;
258+
use warnings;
259+
use Test::More tests => 2;
260+
use XS::Test;
261+
ok XS::Test::is_odd(1);
262+
ok !XS::Test::is_odd(2);
263+
END
264+
};
265+
delete @{ $label2files{eud_consume} }{qw(lib/XS/Test.pm)};
266+
182267
# to mimic behaviour of Unicode-LineBreak version 2015.07.16
183268
$label2files{subdirscomplex} = +{
184269
%{ $label2files{'subdirs'} }, # make copy
@@ -435,6 +520,8 @@ sub list_dynamic {
435520
$^O !~ m!^(VMS|aix)$! ? ([ 'subdirscomplex', '', '' ]) : (),
436521
) : (), # DynaLoader different
437522
[ 'subdirs', '', '' ],
523+
[ 'eud_produce', '', '', 1 ],
524+
[ 'eud_consume', '', '' ],
438525
# https://github.com/Perl/perl5/issues/17601
439526
# https://rt.cpan.org/Ticket/Display.html?id=115321
440527
$^O ne 'MSWin32' ? (

0 commit comments

Comments
 (0)