1N/A#!./perl -w
1N/A
1N/A# Some quick tests to see if h2xs actually runs and creates files as
1N/A# expected. File contents include date stamps and/or usernames
1N/A# hence are not checked. File existence is checked with -e though.
1N/A# This test depends on File::Path::rmtree() to clean up with.
1N/A# - pvhp
1N/A#
1N/A# We are now checking that the correct use $version; is present in
1N/A# Makefile.PL and $module.pm
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/A# use strict; # we are not really testing this
1N/Ause File::Path; # for cleaning up with rmtree()
1N/Ause Test::More;
1N/Ause File::Spec;
1N/Ause File::Find;
1N/Ause ExtUtils::Manifest;
1N/A# Don't want its diagnostics getting in the way of ours.
1N/A$ExtUtils::Manifest::Quiet=1;
1N/Amy $up = File::Spec->updir();
1N/A
1N/Amy $extracted_program = '../utils/h2xs'; # unix, nt, ...
1N/Aif ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
1N/Aif ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
1N/Aif (!(-e $extracted_program)) {
1N/A print "1..0 # Skip: $extracted_program was not built\n";
1N/A exit 0;
1N/A}
1N/A# You might also wish to bail out if your perl platform does not
1N/A# do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
1N/A
1N/A# ok on unix, nt, VMS, ...
1N/Amy $dupe = '2>&1';
1N/A# ok on unix, nt, The extra \" are for VMS
1N/Amy $lib = '"-I../lib" "-I../../lib"';
1N/A# The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
1N/A# already merged).
1N/Aif ($^O eq 'MacOS') {
1N/A $dupe = '';
1N/A # -x overcomes MPW $Config{startperl} anomaly
1N/A $lib = '-x -I::lib: -I:::lib:';
1N/A}
1N/A# $name should differ from system header file names and must
1N/A# not already be found in the t/ subdirectory for perl.
1N/Amy $name = 'h2xst';
1N/Amy $header = "$name.h";
1N/Amy $thisversion = sprintf "%vd", $^V;
1N/A
1N/Amy @tests = (
1N/A"-f -n $name", $], <<"EOXSFILES",
1N/ADefaulting to backwards compatibility with perl $thisversion
1N/AIf you intend this module to be compatible with earlier perl versions, please
1N/Aspecify a minimum perl version with the -b option.
1N/A
1N/AWriting $name/ppport.h
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/$name.xs
1N/AWriting $name/fallback/const-c.inc
1N/AWriting $name/fallback/const-xs.inc
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEOXSFILES
1N/A
1N/A"-f -n $name -b $thisversion", $], <<"EOXSFILES",
1N/AWriting $name/ppport.h
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/$name.xs
1N/AWriting $name/fallback/const-c.inc
1N/AWriting $name/fallback/const-xs.inc
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEOXSFILES
1N/A
1N/A"-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
1N/AWriting $name/ppport.h
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/$name.xs
1N/AWriting $name/fallback/const-c.inc
1N/AWriting $name/fallback/const-xs.inc
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEOXSFILES
1N/A
1N/A"-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
1N/AWriting $name/ppport.h
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/$name.xs
1N/AWriting $name/fallback/const-c.inc
1N/AWriting $name/fallback/const-xs.inc
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEOXSFILES
1N/A
1N/A"\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEONOXSFILES
1N/A
1N/A"-f -n $name $header -b $thisversion", $], <<"EOXSFILES",
1N/AWriting $name/ppport.h
1N/AWriting $name/lib/$name.pm
1N/AWriting $name/$name.xs
1N/AWriting $name/fallback/const-c.inc
1N/AWriting $name/fallback/const-xs.inc
1N/AWriting $name/Makefile.PL
1N/AWriting $name/README
1N/AWriting $name/t/$name.t
1N/AWriting $name/Changes
1N/AWriting $name/MANIFEST
1N/AEOXSFILES
1N/A);
1N/A
1N/Amy $total_tests = 3; # opening, closing and deleting the header file.
1N/Afor (my $i = $#tests; $i > 0; $i-=3) {
1N/A # 1 test for running it, 1 test for the expected result, and 1 for each file
1N/A # plus 1 to open and 1 to check for the use in lib/$name.pm and Makefile.PL
1N/A # And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest.
1N/A # use the () to force list context and hence count the number of matches.
1N/A $total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg);
1N/A}
1N/A
1N/Aplan tests => $total_tests;
1N/A
1N/Aok (open (HEADER, ">$header"), "open '$header'");
1N/Aprint HEADER <<HEADER or die $!;
1N/A#define Camel 2
1N/A#define Dromedary 1
1N/AHEADER
1N/Aok (close (HEADER), "close '$header'");
1N/A
1N/Awhile (my ($args, $version, $expectation) = splice @tests, 0, 3) {
1N/A # h2xs warns about what it is writing hence the (possibly unportable)
1N/A # 2>&1 dupe:
1N/A # does it run?
1N/A my $prog = "$^X $lib $extracted_program $args $dupe";
1N/A @result = `$prog`;
1N/A cmp_ok ($?, "==", 0, "running $prog ");
1N/A $result = join("",@result);
1N/A
1N/A # accomodate MPW # comment character prependage
1N/A if ($^O eq 'MacOS') {
1N/A $result =~ s/#\s*//gs;
1N/A }
1N/A
1N/A #print "# expectation is >$expectation<\n";
1N/A #print "# result is >$result<\n";
1N/A # Was the output the list of files that were expected?
1N/A is ($result, $expectation, "running $prog");
1N/A
1N/A my (%got);
1N/A find (sub {$got{$File::Find::name}++ unless -d $_}, $name);
1N/A
1N/A foreach ($expectation =~ /Writing\s+(\S+)/gm) {
1N/A if ($^O eq 'MacOS') {
1N/A $_ = ':' . join(':',split(/\//,$_));
1N/A $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
1N/A }
1N/A if ($^O eq 'VMS') {
1N/A $_ .= '.' unless $_ =~ m/\./;
1N/A $_ = lc($_) unless exists $got{$_};
1N/A }
1N/A ok (-e $_, "check for $_") and delete $got{$_};
1N/A }
1N/A my @extra = keys %got;
1N/A unless (ok (!@extra, "Are any extra files present?")) {
1N/A print "# These files are unexpectedly present:\n";
1N/A print "# $_\n" foreach sort @extra;
1N/A }
1N/A
1N/A chdir ($name) or die "chdir $name failed: $!";
1N/A # Aargh. Something wants to load a bit of regexp. And we have to chdir
1N/A # for ExtUtils::Manifest. Caught between a rock and a hard place, so this
1N/A # seems the least evil thing to do:
1N/A push @INC, "../../lib";
1N/A my ($missing, $extra) = ExtUtils::Manifest::fullcheck();
1N/A is_deeply ($missing, [], "No files in the MANIFEST should be missing");
1N/A is_deeply ($extra, [], "and all files present should be in the MANIFEST");
1N/A pop @INC;
1N/A chdir ($up) or die "chdir $up failed: $!";
1N/A
1N/A foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') {
1N/A my $file = File::Spec->catfile($name, $leaf);
1N/A if (ok (open (FILE, $file), "open $file")) {
1N/A my $match = qr/use $version;/;
1N/A my $found;
1N/A while (<FILE>) {
1N/A last if $found = /$match/;
1N/A }
1N/A ok ($found, "looking for /$match/ in $file");
1N/A close FILE or die "close $file: $!";
1N/A }
1N/A }
1N/A # clean up
1N/A rmtree($name);
1N/A}
1N/A
1N/Acmp_ok (unlink ($header), "==", 1, "unlink '$header'") or die "\$! is $!";