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