Re: [perl #36047] perlmod.pod/CLONESKIP error
[p5sagit/p5-mst-13.2.git] / lib / h2xs.t
CommitLineData
46b277d5 1#!./perl -w
3a9c887e 2
3# Some quick tests to see if h2xs actually runs and creates files as
4# expected. File contents include date stamps and/or usernames
5# hence are not checked. File existence is checked with -e though.
6# This test depends on File::Path::rmtree() to clean up with.
7# - pvhp
3e6e4ea8 8#
9# We are now checking that the correct use $version; is present in
10# Makefile.PL and $module.pm
fa1e5b33 11
3a9c887e 12BEGIN {
13 chdir 't' if -d 't';
14 @INC = '../lib';
763a0d21 15 # FIXME (or rather FIXh2xs)
16 require Config;
98641f60 17 if (($Config::Config{'extensions'} !~ m!\bDevel/PPPort\b!) ){
763a0d21 18 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
19 exit 0;
20 }
3a9c887e 21}
22
45ea237c 23# use strict; # we are not really testing this
3a9c887e 24use File::Path; # for cleaning up with rmtree()
1cb0fb50 25use Test::More;
31022a5a 26use File::Spec;
1cb0fb50 27use File::Find;
28use ExtUtils::Manifest;
29# Don't want its diagnostics getting in the way of ours.
30$ExtUtils::Manifest::Quiet=1;
31my $up = File::Spec->updir();
3a9c887e 32
33my $extracted_program = '../utils/h2xs'; # unix, nt, ...
34if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
45ea237c 35if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
3a9c887e 36if (!(-e $extracted_program)) {
37 print "1..0 # Skip: $extracted_program was not built\n";
38 exit 0;
39}
40# You might also wish to bail out if your perl platform does not
41# do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
42
fa1e5b33 43# ok on unix, nt, VMS, ...
44my $dupe = '2>&1';
45# ok on unix, nt, The extra \" are for VMS
46my $lib = '"-I../lib" "-I../../lib"';
3a9c887e 47# The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
48# already merged).
49if ($^O eq 'MacOS') {
50 $dupe = '';
fa1e5b33 51 # -x overcomes MPW $Config{startperl} anomaly
52 $lib = '-x -I::lib: -I:::lib:';
3a9c887e 53}
54# $name should differ from system header file names and must
55# not already be found in the t/ subdirectory for perl.
56my $name = 'h2xst';
46b277d5 57my $header = "$name.h";
3e6e4ea8 58my $thisversion = sprintf "%vd", $^V;
3a9c887e 59
98d84473 60# If this test has failed previously a copy may be left.
61rmtree($name);
62
46b277d5 63my @tests = (
3e6e4ea8 64"-f -n $name", $], <<"EOXSFILES",
65Defaulting to backwards compatibility with perl $thisversion
66If you intend this module to be compatible with earlier perl versions, please
67specify a minimum perl version with the -b option.
68
0a7c7f4f 69Writing $name/ppport.h
4a660237 70Writing $name/lib/$name.pm
3a9c887e 71Writing $name/$name.xs
1cb0fb50 72Writing $name/fallback/const-c.inc
73Writing $name/fallback/const-xs.inc
3a9c887e 74Writing $name/Makefile.PL
75Writing $name/README
4a660237 76Writing $name/t/$name.t
3a9c887e 77Writing $name/Changes
78Writing $name/MANIFEST
79EOXSFILES
80
3e6e4ea8 81"-f -n $name -b $thisversion", $], <<"EOXSFILES",
0a7c7f4f 82Writing $name/ppport.h
4a660237 83Writing $name/lib/$name.pm
3e6e4ea8 84Writing $name/$name.xs
1cb0fb50 85Writing $name/fallback/const-c.inc
86Writing $name/fallback/const-xs.inc
3e6e4ea8 87Writing $name/Makefile.PL
88Writing $name/README
4a660237 89Writing $name/t/$name.t
3e6e4ea8 90Writing $name/Changes
91Writing $name/MANIFEST
92EOXSFILES
93
94"-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
0a7c7f4f 95Writing $name/ppport.h
4a660237 96Writing $name/lib/$name.pm
3e6e4ea8 97Writing $name/$name.xs
1cb0fb50 98Writing $name/fallback/const-c.inc
99Writing $name/fallback/const-xs.inc
3e6e4ea8 100Writing $name/Makefile.PL
101Writing $name/README
4a660237 102Writing $name/t/$name.t
3e6e4ea8 103Writing $name/Changes
104Writing $name/MANIFEST
105EOXSFILES
106
107"-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
0a7c7f4f 108Writing $name/ppport.h
4a660237 109Writing $name/lib/$name.pm
3e6e4ea8 110Writing $name/$name.xs
1cb0fb50 111Writing $name/fallback/const-c.inc
112Writing $name/fallback/const-xs.inc
3e6e4ea8 113Writing $name/Makefile.PL
114Writing $name/README
4a660237 115Writing $name/t/$name.t
3e6e4ea8 116Writing $name/Changes
117Writing $name/MANIFEST
118EOXSFILES
119
120"\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
4a660237 121Writing $name/lib/$name.pm
3a9c887e 122Writing $name/Makefile.PL
123Writing $name/README
4a660237 124Writing $name/t/$name.t
3a9c887e 125Writing $name/Changes
126Writing $name/MANIFEST
127EONOXSFILES
128
f1c8c936 129"-f -n $name -b $thisversion $header", $], <<"EOXSFILES",
0a7c7f4f 130Writing $name/ppport.h
4a660237 131Writing $name/lib/$name.pm
46b277d5 132Writing $name/$name.xs
1cb0fb50 133Writing $name/fallback/const-c.inc
134Writing $name/fallback/const-xs.inc
46b277d5 135Writing $name/Makefile.PL
136Writing $name/README
4a660237 137Writing $name/t/$name.t
46b277d5 138Writing $name/Changes
139Writing $name/MANIFEST
140EOXSFILES
141);
142
143my $total_tests = 3; # opening, closing and deleting the header file.
3e6e4ea8 144for (my $i = $#tests; $i > 0; $i-=3) {
46b277d5 145 # 1 test for running it, 1 test for the expected result, and 1 for each file
4a660237 146 # plus 1 to open and 1 to check for the use in lib/$name.pm and Makefile.PL
1cb0fb50 147 # And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest.
46b277d5 148 # use the () to force list context and hence count the number of matches.
1cb0fb50 149 $total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg);
46b277d5 150}
151
152plan tests => $total_tests;
153
1cb0fb50 154ok (open (HEADER, ">$header"), "open '$header'");
46b277d5 155print HEADER <<HEADER or die $!;
156#define Camel 2
157#define Dromedary 1
158HEADER
1cb0fb50 159ok (close (HEADER), "close '$header'");
46b277d5 160
3e6e4ea8 161while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
46b277d5 162 # h2xs warns about what it is writing hence the (possibly unportable)
163 # 2>&1 dupe:
164 # does it run?
165 my $prog = "$^X $lib $extracted_program $args $dupe";
166 @result = `$prog`;
1cb0fb50 167 cmp_ok ($?, "==", 0, "running $prog ");
46b277d5 168 $result = join("",@result);
169
170 # accomodate MPW # comment character prependage
171 if ($^O eq 'MacOS') {
172 $result =~ s/#\s*//gs;
173 }
174
175 #print "# expectation is >$expectation<\n";
176 #print "# result is >$result<\n";
177 # Was the output the list of files that were expected?
1cb0fb50 178 is ($result, $expectation, "running $prog");
179
180 my (%got);
181 find (sub {$got{$File::Find::name}++ unless -d $_}, $name);
46b277d5 182
3e6e4ea8 183 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
45ea237c 184 if ($^O eq 'MacOS') {
46b277d5 185 $_ = ':' . join(':',split(/\//,$_));
186 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
45ea237c 187 }
7ce7e561 188 if ($^O eq 'VMS') {
189 $_ .= '.' unless $_ =~ m/\./;
190 $_ = lc($_) unless exists $got{$_};
191 }
1cb0fb50 192 ok (-e $_, "check for $_") and delete $got{$_};
193 }
194 my @extra = keys %got;
195 unless (ok (!@extra, "Are any extra files present?")) {
196 print "# These files are unexpectedly present:\n";
197 print "# $_\n" foreach sort @extra;
46b277d5 198 }
3a9c887e 199
1cb0fb50 200 chdir ($name) or die "chdir $name failed: $!";
201 # Aargh. Something wants to load a bit of regexp. And we have to chdir
202 # for ExtUtils::Manifest. Caught between a rock and a hard place, so this
203 # seems the least evil thing to do:
204 push @INC, "../../lib";
205 my ($missing, $extra) = ExtUtils::Manifest::fullcheck();
206 is_deeply ($missing, [], "No files in the MANIFEST should be missing");
207 is_deeply ($extra, [], "and all files present should be in the MANIFEST");
208 pop @INC;
209 chdir ($up) or die "chdir $up failed: $!";
210
4a660237 211 foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') {
31022a5a 212 my $file = File::Spec->catfile($name, $leaf);
1cb0fb50 213 if (ok (open (FILE, $file), "open $file")) {
3e6e4ea8 214 my $match = qr/use $version;/;
215 my $found;
216 while (<FILE>) {
217 last if $found = /$match/;
218 }
1cb0fb50 219 ok ($found, "looking for /$match/ in $file");
3e6e4ea8 220 close FILE or die "close $file: $!";
221 }
222 }
46b277d5 223 # clean up
224 rmtree($name);
225}
3a9c887e 226
1cb0fb50 227cmp_ok (unlink ($header), "==", 1, "unlink '$header'") or die "\$! is $!";