diff options
Diffstat (limited to 'cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup')
8 files changed, 351 insertions, 527 deletions
diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm index e5af93c4b1..3d093fcfbd 100644 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm +++ b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/BFD.pm @@ -55,16 +55,20 @@ program - this is a program 1; END - 'Big-Dummy/t/compile.t' => <<'END', -print "1..2\n"; + 'Big-Dummy/test.pl' => <<'END', +print "1..1\n"; +print "ok 1 - testing test.pl\n"; +END + 'Big-Dummy/t/compile.t' => <<'END', +print "1..3\n"; print eval "use Big::Dummy; 1;" ? "ok 1\n" : "not ok 1\n"; print "ok 2 - TEST_VERBOSE\n"; +print "ok 3 - testing t/*.t\n"; END 'Big-Dummy/Liar/t/sanity.t' => <<'END', print "1..3\n"; - print eval "use Big::Dummy; 1;" ? "ok 1\n" : "not ok 1\n"; print eval "use Big::Liar; 1;" ? "ok 2\n" : "not ok 2\n"; print "ok 3 - TEST_VERBOSE\n"; @@ -96,11 +100,13 @@ END ); +# if given args, those are inserted as components in resulting path, eg: +# setup_recurs('dir') means instead of creating Big-Dummy/*, dir/Big-Dummy/* sub setup_recurs { - while(my($file, $text) = each %Files) { # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); + $file = File::Spec->catfile(File::Spec->curdir, @_, split m{\/}, $file); + $file = File::Spec->rel2abs($file); my $dir = dirname($file); mkpath $dir; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/MPV.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/MPV.pm deleted file mode 100644 index f30d65f567..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/MPV.pm +++ /dev/null @@ -1,67 +0,0 @@ -package MakeMaker::Test::Setup::MPV; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup_recurs teardown_recurs); - -use strict; -use File::Path; -use File::Basename; - -my %Files = ( - 'Min-PerlVers/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => 'Min::PerlVers', - AUTHOR => 'John Doe <jd@example.com>', - VERSION_FROM => 'lib/Min/PerlVers.pm', - PREREQ_PM => { strict => 0 }, - MIN_PERL_VERSION => '5.005', -); -END - - 'Min-PerlVers/lib/Min/PerlVers.pm' => <<'END', -package Min::PerlVers; - -$VERSION = 0.05; - -=head1 NAME - -Min::PerlVers - being picky about perl versions - -=cut - -1; -END - -); - - -sub setup_recurs { - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; - } - - return 1; -} - -sub teardown_recurs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} - - -1; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/PL_FILES.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/PL_FILES.pm deleted file mode 100644 index f412368317..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/PL_FILES.pm +++ /dev/null @@ -1,119 +0,0 @@ -package MakeMaker::Test::Setup::PL_FILES; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup teardown); - -use strict; -use File::Path; -use File::Basename; -use File::Spec; -use MakeMaker::Test::Utils; - -my %Files = ( - 'PL_FILES-Module/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -# A module for testing PL_FILES -WriteMakefile( - NAME => 'PL_FILES::Module', - PL_FILES => { 'single.PL' => 'single.out', - 'multi.PL' => [qw(1.out 2.out)], - 'Bar_pm.PL' => '$(INST_LIB)/PL/Bar.pm', - } -); -END - - 'PL_FILES-Module/single.PL' => _gen_pl_files(), - 'PL_FILES-Module/multi.PL' => _gen_pl_files(), - 'PL_FILES-Module/Bar_pm.PL' => _gen_pm_files(), - 'PL_FILES-Module/lib/PL/Foo.pm' => <<'END', -# Module to load to ensure PL_FILES have blib in @INC. -package PL::Foo; -sub bar { 42 } -1; -END - -); - - -sub _gen_pl_files { - my $test = <<'END'; -#!/usr/bin/perl -w - -# Ensure we have blib in @INC -use PL::Foo; -die unless PL::Foo::bar() == 42; - -# Had a bug where PL_FILES weren't sent the file to generate -die "argv empty\n" unless @ARGV; -die "too many in argv: @ARGV\n" unless @ARGV == 1; - -my $file = $ARGV[0]; -open OUT, ">$file" or die $!; - -print OUT "Testing\n"; -close OUT -END - - $test =~ s/^\n//; - - return $test; -} - - -sub _gen_pm_files { - my $test = <<'END'; -#!/usr/bin/perl -w - -# Ensure we do NOT have blib in @INC when building a module -eval { require PL::Foo; }; -#die $@ unless $@ =~ m{^Can't locate PL/Foo.pm in \@INC }; - -# Had a bug where PL_FILES weren't sent the file to generate -die "argv empty\n" unless @ARGV; -die "too many in argv: @ARGV\n" unless @ARGV == 1; - -my $file = $ARGV[0]; -open OUT, ">$file" or die $!; - -print OUT "Testing\n"; -close OUT -END - - $test =~ s/^\n//; - - return $test; -} - - -sub setup { - - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; - - # ensure file at least 1 second old for makes that assume - # files with the same time are out of date. - my $time = calibrate_mtime(); - utime $time, $time - 1, $file; - } - - return 1; -} - -sub teardown { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Problem.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Problem.pm deleted file mode 100644 index 59ac1517a6..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Problem.pm +++ /dev/null @@ -1,62 +0,0 @@ -package MakeMaker::Test::Setup::Problem; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup_recurs teardown_recurs); - -use strict; -use File::Path; -use File::Basename; -use MakeMaker::Test::Utils; - -my %Files = ( - 'Problem-Module/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => 'Problem::Module', -); -END - - 'Problem-Module/subdir/Makefile.PL' => <<'END', -printf "\@INC %s .\n", (grep { $_ eq '.' } @INC) ? "has" : "doesn't have"; - -warn "I think I'm going to be sick\n"; -die "YYYAaaaakkk\n"; -END - -); - - -sub setup_recurs { - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; - - # ensure file at least 1 second old for makes that assume - # files with the same time are out of date. - my $time = calibrate_mtime(); - utime $time, $time - 1, $file; - } - - return 1; -} - -sub teardown_recurs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} - - -1; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Recurs.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Recurs.pm deleted file mode 100644 index 8694321358..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Recurs.pm +++ /dev/null @@ -1,72 +0,0 @@ -package MakeMaker::Test::Setup::Recurs; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup_recurs teardown_recurs); - -use strict; -use File::Path; -use File::Basename; -use MakeMaker::Test::Utils; - -my %Files = ( - 'Recurs/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => 'Recurs', - VERSION => 1.00, -); -END - - 'Recurs/prj2/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => 'Recurs::prj2', - VERSION => 1.00, -); -END - - # Check if a test failure in a subdir causes make test to fail - 'Recurs/prj2/t/fail.t' => <<'END', -#!/usr/bin/perl -w - -print "1..1\n"; -print "not ok 1\n"; -END - ); - -sub setup_recurs { - - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; - - # ensure file at least 1 second old for makes that assume - # files with the same time are out of date. - my $time = calibrate_mtime(); - utime $time, $time - 1, $file; - } - - return 1; -} - -sub teardown_recurs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} - - -1; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/SAS.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/SAS.pm deleted file mode 100644 index 04d9bd3259..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/SAS.pm +++ /dev/null @@ -1,67 +0,0 @@ -package MakeMaker::Test::Setup::SAS; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup_recurs teardown_recurs); - -use strict; -use File::Path; -use File::Basename; - -our $dirname='Multiple-Authors'; -my %Files = ( - $dirname.'/Makefile.PL' => <<'END', -use ExtUtils::MakeMaker; - -WriteMakefile( - NAME => 'Multiple::Authors', - AUTHOR => ['John Doe <jd@example.com>', 'Jane Doe <jd@example.com>'], - VERSION_FROM => 'lib/Multiple/Authors.pm', - PREREQ_PM => { strict => 0 }, -); -END - - $dirname.'/lib/Multiple/Authors.pm' => <<'END', -package Multiple::Authors; - -$VERSION = 0.05; - -=head1 NAME - -Multiple::Authors - several authors - -=cut - -1; -END - -); - - -sub setup_recurs { - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; - } - - return 1; -} - -sub teardown_recurs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} - - -1; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Unicode.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Unicode.pm deleted file mode 100644 index 76641f055c..0000000000 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/Unicode.pm +++ /dev/null @@ -1,90 +0,0 @@ -package MakeMaker::Test::Setup::Unicode; - -@ISA = qw(Exporter); -require Exporter; -@EXPORT = qw(setup_recurs teardown_recurs); - -use strict; -use File::Path; -use File::Basename; -use MakeMaker::Test::Utils; -use utf8; -use Config; - -my %Files = ( - 'Problem-Module/Makefile.PL' => <<'PL_END', -use ExtUtils::MakeMaker; -use utf8; - -WriteMakefile( - NAME => 'Problem::Module', - ABSTRACT_FROM => 'lib/Problem/Module.pm', - AUTHOR => q{Danijel Tašov}, - EXE_FILES => [ qw(bin/probscript) ], - INSTALLMAN1DIR => "some", # even if disabled in $Config{man1dir} - MAN1EXT => 1, # set to 0 if man pages disabled -); -PL_END - - 'Problem-Module/lib/Problem/Module.pm' => <<'pm_END', -use utf8; - -=pod - -=encoding utf8 - -=head1 NAME - -Problem::Module - Danijel Tašov's great new module - -=cut - -1; -pm_END - - 'Problem-Module/bin/probscript' => <<'pl_END', -#!/usr/bin/perl -use utf8; - -=encoding utf8 - -=head1 NAME - -文档 - Problem script -pl_END -); - - -sub setup_recurs { - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); - - my $dir = dirname($file); - mkpath $dir; - my $utf8 = ($] < 5.008 or !$Config{useperlio}) ? "" : ":utf8"; - open(FILE, ">$utf8", $file) || die "Can't create $file: $!"; - print FILE $text; - close FILE; - - # ensure file at least 1 second old for makes that assume - # files with the same time are out of date. - my $time = calibrate_mtime(); - utime $time, $time - 1, $file; - } - - return 1; -} - -sub teardown_recurs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; - } - } - return 1; -} - - -1; diff --git a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/XS.pm b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/XS.pm index 6ebca59834..2c3ac61f18 100644 --- a/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/XS.pm +++ b/cpan/ExtUtils-MakeMaker/t/lib/MakeMaker/Test/Setup/XS.pm @@ -2,101 +2,396 @@ package MakeMaker::Test::Setup::XS; @ISA = qw(Exporter); require Exporter; -@EXPORT = qw(setup_xs teardown_xs); +@EXPORT = qw(run_tests list_dynamic list_static); use strict; use File::Path; -use File::Basename; use MakeMaker::Test::Utils; use Config; +use Carp qw(croak); +use Test::More; +use File::Spec; +use File::Temp qw[tempdir]; +use Cwd; use ExtUtils::MM; +# this is to avoid MM->new overwriting _eumm in top dir +my $tempdir = tempdir(DIR => getcwd, CLEANUP => 1); +chdir $tempdir; my $typemap = 'type map'; -$typemap =~ s/ //g unless MM->new({NAME=>'name'})->can_dep_space; +$typemap =~ s/ //g unless MM->new({NAME=>'name', NORECURS=>1})->can_dep_space; +chdir File::Spec->updir; -my %Files = ( - 'XS-Test/lib/XS/Test.pm' => <<'END', +my $PM_TEST = <<'END'; package XS::Test; - require Exporter; require DynaLoader; - $VERSION = 1.01; @ISA = qw(Exporter DynaLoader); @EXPORT = qw(is_even); - bootstrap XS::Test $VERSION; - 1; END - 'XS-Test/Makefile.PL' => <<END, -use ExtUtils::MakeMaker; +my $XS_TEST = <<'END'; +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +MODULE = XS::Test PACKAGE = XS::Test +PROTOTYPES: DISABLE +int +is_even(input) + int input + CODE: + RETVAL = (input % 2 == 0); + OUTPUT: + RETVAL +END +my $T_TEST = <<'END'; +#!/usr/bin/perl -w +use Test::More tests => 3; +use_ok "XS::Test"; +ok !is_even(1); +ok is_even(2); +END + +my $MAKEFILEPL = <<'END'; +use ExtUtils::MakeMaker; WriteMakefile( - NAME => 'XS::Test', - VERSION_FROM => 'lib/XS/Test.pm', - TYPEMAPS => [ '$typemap' ], - PERL => "\$^X -w", + NAME => 'XS::%s', + VERSION_FROM => '%s', + TYPEMAPS => [ %s ], + PERL => "$^X -w", + %s ); END - "XS-Test/$typemap" => '', +my $BS_TEST = '$DynaLoader::bscode = q(warn "BIG NOISE";)'; + +my $T_BOOTSTRAP = <<'EOF'; +use Test::More tests => 1; +my $w = ''; +$SIG{__WARN__} = sub { $w .= join '', @_; }; +require XS::Test; +like $w, qr/NOISE/; +EOF + +my $PM_OTHER = <<'END'; +package XS::Other; +require Exporter; +require DynaLoader; +$VERSION = 1.20; +@ISA = qw(Exporter DynaLoader); +@EXPORT = qw(is_odd); +bootstrap XS::Other $VERSION; +1; +END - 'XS-Test/Test.xs' => <<'END', +my $XS_OTHER = <<'END'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" - -MODULE = XS::Test PACKAGE = XS::Test - +MODULE = XS::Other PACKAGE = XS::Other PROTOTYPES: DISABLE - int -is_even(input) +is_odd(input) int input CODE: - RETVAL = (input % 2 == 0); + RETVAL = (INVAR % 2 == 1); OUTPUT: RETVAL END - 'XS-Test/t/is_even.t' => <<'END', +my $T_OTHER = <<'END'; #!/usr/bin/perl -w - use Test::More tests => 3; +use_ok "XS::Other"; +ok is_odd(1); +ok !is_odd(2); +END -use_ok "XS::Test"; -ok !is_even(1); -ok is_even(2); +my $PLUS1_C = <<'EOF'; +#ifdef __cplusplus +extern "C" { +int plus1(int i) +#else +int plus1(i) +int i; +#endif +{ return i + 1; } +#ifdef __cplusplus +} +#endif +EOF + +my %Files = ( + 'lib/XS/Test.pm' => $PM_TEST, + $typemap => '', + 'Test.xs' => $XS_TEST, + 't/is_even.t' => $T_TEST, + 'Makefile.PL' => sprintf($MAKEFILEPL, 'Test', 'lib/XS/Test.pm', qq{'$typemap'}, ''), +); + +my %label2files = (basic => \%Files); + +$label2files{bscode} = +{ + %{ $label2files{'basic'} }, # make copy + 'Test_BS' => $BS_TEST, + 't/bs.t' => $T_BOOTSTRAP, +}; +delete $label2files{bscode}->{'t/is_even.t'}; + +$label2files{static} = +{ + %{ $label2files{'basic'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'lib/XS/Test.pm', qq{'$typemap'}, + q{LINKTYPE => 'static'}, + ), +}; + +$label2files{subdirs} = +{ + %{ $label2files{'basic'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'Test.pm', qq{'$typemap'}, + q{DEFINE => '-DINVAR=input', INC => "-Inewline\n", LIBS => "-Lnewline\n",}, + ), + 'Other/Makefile.PL' => sprintf($MAKEFILEPL, 'Other', 'Other.pm', qq{}, ''), + 'Other/Other.pm' => $PM_OTHER, + 'Other/Other.xs' => $XS_OTHER, + 't/is_odd.t' => $T_OTHER, +}; +virtual_rename('subdirs', 'lib/XS/Test.pm', 'Test.pm'); + +# to mimic behaviour of Unicode-LineBreak version 2015.07.16 +$label2files{subdirscomplex} = +{ + %{ $label2files{'subdirs'} }, # make copy + 'Other/Makefile.PL' => sprintf( + $MAKEFILEPL, + 'Other', 'Other.pm', qq{}, + <<'EOF', +C => [qw(lib$(DIRFILESEP)file.c)], +OBJECT => 'lib$(DIRFILESEP)file$(OBJ_EXT)', +EOF + ) . <<'EOF', +sub MY::c_o { + package MY; + my $self = shift; + my $inherited = $self->SUPER::c_o(@_); + $inherited =~ s{(:\n\t)(.*(?:\n\t.*)*)} + { $1 . $self->cd('lib', split /(?<!\\)\n\t/, $2) }eg; + $inherited =~ s{(\s)(\$\*\.c\s)} + { "$1..\$(DIRFILESEP)$2" }eg; + $inherited; +} + +sub MY::top_targets { + <<'SNIP'; +all :: lib$(DIRFILESEP)file$(OBJ_EXT) + $(NOECHO) $(NOOP) + +config :: + $(NOECHO) $(NOOP) + +pure_all :: + $(NOECHO) $(NOOP) +SNIP +} +EOF + 'Other/lib/file.c' => $PLUS1_C, +}; +delete $label2files{subdirscomplex}{'Other/Other.xs'}; +delete $label2files{subdirscomplex}{'t/is_odd.t'}; + +$label2files{subdirsstatic} = +{ + %{ $label2files{'subdirs'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'Test.pm', qq{'$typemap'}, + q{DEFINE => '-DINVAR=input', LINKTYPE => 'static',}, + ), +}; + +my $XS_MULTI = $XS_OTHER; +# check compiling from top dir still can include local +$XS_MULTI =~ s:(#include "XSUB.h"):$1\n#include "header.h":; +$label2files{multi} = +{ + %{ $label2files{'basic'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'lib/XS/Test.pm', qq{'lib/XS/$typemap'}, + q{XSMULTI => 1,}, + ), + 'lib/XS/Other.pm' => $PM_OTHER, + 'lib/XS/Other.xs' => $XS_MULTI, + 't/is_odd.t' => $T_OTHER, + 'lib/XS/header.h' => "#define INVAR input\n", +}; +virtual_rename('multi', $typemap, "lib/XS/$typemap"); +virtual_rename('multi', 'Test.xs', 'lib/XS/Test.xs'); + +$label2files{bscodemulti} = +{ + %{ $label2files{'multi'} }, # make copy + 'lib/XS/Test_BS' => $BS_TEST, + 't/bs.t' => $T_BOOTSTRAP, +}; +delete $label2files{bscodemulti}->{'t/is_even.t'}; +delete $label2files{bscodemulti}->{'t/is_odd.t'}; + +$label2files{staticmulti} = +{ + %{ $label2files{'multi'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'lib/XS/Test.pm', qq{'$typemap'}, + q{LINKTYPE => 'static', XSMULTI => 1,}, + ), +}; + +$label2files{xsbuild} = +{ + %{ $label2files{'multi'} }, # make copy + 'Makefile.PL' => sprintf( + $MAKEFILEPL, 'Test', 'lib/XS/Test.pm', qq{'$typemap'}, + q{ + XSMULTI => 1, + XSBUILD => { + xs => { + 'lib/XS/Other' => { + DEFINE => '-DINVAR=input', + OBJECT => 'lib/XS/Other$(OBJ_EXT) lib/XS/plus1$(OBJ_EXT)' + } + }, + }, + }, + ), + + 'lib/XS/Other.xs' => <<EOF, +#ifdef __cplusplus +extern "C" { +#endif +int plus1(int); +#ifdef __cplusplus +} +#endif +$XS_OTHER +int +plus1(input) + int input + CODE: + RETVAL = plus1(INVAR); + OUTPUT: + RETVAL +EOF + + 'lib/XS/plus1.c' => $PLUS1_C, + + 't/is_odd.t' => <<'END', +#!/usr/bin/perl -w +use Test::More tests => 4; +use_ok "XS::Other"; +ok is_odd(1); +ok !is_odd(2); +is XS::Other::plus1(3), 4; END - ); +}; + +sub virtual_rename { + my ($label, $oldfile, $newfile) = @_; + $label2files{$label}->{$newfile} = delete $label2files{$label}->{$oldfile}; +} sub setup_xs { + my ($label, $sublabel) = @_; + croak "Must supply label" unless defined $label; + my $files = $label2files{$label}; + croak "Must supply valid label" unless defined $files; + croak "Must supply sublabel" unless defined $sublabel; + my $prefix = "XS-Test$label$sublabel"; + hash2files($prefix, $files); + return $prefix; +} + +sub list_static { + ( + ( !$Config{usedl} ? [ 'basic', '', '' ] : ()), # still needs testing on static perl + [ 'static', '', '' ], + [ 'basic', ' static', '_static' ], + [ 'multi', ' static', '_static' ], + [ 'subdirs', ' LINKTYPE=static', ' LINKTYPE=static' ], + [ 'subdirsstatic', '', '' ], + [ 'staticmulti', '', '' ], + ); +} + +sub list_dynamic { + ( + [ 'basic', '', '' ], + $^O ne 'MSWin32' ? ( + [ 'bscode', '', '' ], + [ 'bscodemulti', '', '' ], + [ 'subdirscomplex', '', '' ], + ) : (), # DynaLoader different + [ 'subdirs', '', '' ], + [ 'subdirsstatic', ' LINKTYPE=dynamic', ' LINKTYPE=dynamic' ], + [ 'subdirsstatic', ' dynamic', '_dynamic' ], + [ 'multi', '', '' ], + [ 'staticmulti', ' LINKTYPE=dynamic', ' LINKTYPE=dynamic' ], + [ 'staticmulti', ' dynamic', '_dynamic' ], + [ 'xsbuild', '', '' ], + ); +} - while(my($file, $text) = each %Files) { - # Convert to a relative, native file path. - $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file); +sub run_tests { + my ($perl, $label, $add_target, $add_testtarget) = @_; + my $sublabel = $add_target; + $sublabel =~ s#[\s=]##g; + ok( my $dir = setup_xs($label, $sublabel), "setup $label$sublabel" ); - my $dir = dirname($file); - mkpath $dir; - open(FILE, ">$file") || die "Can't create $file: $!"; - print FILE $text; - close FILE; + ok( chdir($dir), "chdir'd to $dir" ) || diag("chdir failed: $!"); + + my @mpl_out = run(qq{$perl Makefile.PL}); + SKIP: { + unless (cmp_ok( $?, '==', 0, 'Makefile.PL exited with zero' )) { + diag(@mpl_out); + skip 'perl Makefile.PL failed', 2; } - return 1; -} + my $make = make_run(); + my $target = ''; + my %macros = (); + if (defined($add_target)) { + if ($add_target =~ m/(\S+)=(\S+)/) { + $macros{$1} = $2; + } + else { + $target = $add_target; + } + } + my $make_cmd = make_macro($make, $target, %macros); + my $make_out = run($make_cmd); + unless (is( $?, 0, "$make_cmd exited normally" )) { + diag $make_out; + skip 'Make failed - skipping test', 1; + } -sub teardown_xs { - foreach my $file (keys %Files) { - my $dir = dirname($file); - if( -e $dir ) { - rmtree($dir) || return; + $target = 'test'; + %macros = (); + if (defined($add_testtarget) && length($add_testtarget)) { + if ($add_testtarget =~ m/(\S+)=(\S+)/) { + $macros{$1} = $2; + } + else { + # an underscore prefix means combine, e.g. 'test' + '_dynamic' + unless ($add_testtarget =~ m/^_/) { + $target .= ($make =~ m/^MM(K|S)/i) ? ',' : ' '; + } + $target .= $add_testtarget; } } - return 1; + my $test_cmd = make_macro($make, $target, %macros); + my $test_out = run($test_cmd); + is( $?, 0, "$test_cmd exited normally" ) || diag "$make_out\n$test_out"; + } + + chdir File::Spec->updir or die; + ok rmtree($dir), "teardown $dir"; } 1; |