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.
9 # We are now checking that the correct use $version; is present in
10 # Makefile.PL and $module.pm
15 # FIXME (or rather FIXh2xs)
17 if (($Config::Config{'extensions'} !~ m!\bDevel/PPPort\b!) ){
18 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
23 # use strict; # we are not really testing this
24 use File::Path; # for cleaning up with rmtree()
28 use ExtUtils::Manifest;
29 # Don't want its diagnostics getting in the way of ours.
30 $ExtUtils::Manifest::Quiet=1;
31 my $up = File::Spec->updir();
33 my $extracted_program = '../utils/h2xs'; # unix, nt, ...
35 my $Is_VMS_traildot = 0;
37 $extracted_program = '[-.utils]h2xs.com';
39 # We have to know if VMS is in UNIX mode. In UNIX mode, trailing dots
40 # should not be present. There are actually two settings that control this.
45 if (eval 'require VMS::Feature') {
46 $unix_rpt = VMS::Feature::current('filename_unix_report');
47 $drop_dot = VMS::Feature::current('readdir_dropdotnotype');
49 my $unix_report = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
50 $unix_rpt = $unix_report =~ /^[ET1]/i;
51 my $drop_dot_notype = $ENV{'DECC$READDIR_DROPDOTNOTYPE'} || '';
52 $drop_dot = $drop_dot_notype =~ /^[ET1]/i;
54 $Is_VMS_traildot = 0 if $drop_dot && unix_rpt;
56 if (!(-e $extracted_program)) {
57 print "1..0 # Skip: $extracted_program was not built\n";
60 # You might also wish to bail out if your perl platform does not
61 # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
63 # ok on unix, nt, VMS, ...
65 # ok on unix, nt, The extra \" are for VMS
66 my $lib = '"-I../lib" "-I../../lib"';
67 # $name should differ from system header file names and must
68 # not already be found in the t/ subdirectory for perl.
70 my $header = "$name.h";
71 my $thisversion = sprintf "%vd", $^V;
72 $thisversion =~ s/^v//;
74 # If this test has failed previously a copy may be left.
75 rmtree($name) if -e $name;
78 "-f -n $name", $], <<"EOXSFILES",
79 Defaulting to backwards compatibility with perl $thisversion
80 If you intend this module to be compatible with earlier perl versions, please
81 specify a minimum perl version with the -b option.
83 Writing $name/ppport.h
84 Writing $name/lib/$name.pm
85 Writing $name/$name.xs
86 Writing $name/fallback/const-c.inc
87 Writing $name/fallback/const-xs.inc
88 Writing $name/Makefile.PL
90 Writing $name/t/$name.t
92 Writing $name/MANIFEST
95 "-f -n $name -b $thisversion", $], <<"EOXSFILES",
96 Writing $name/ppport.h
97 Writing $name/lib/$name.pm
98 Writing $name/$name.xs
99 Writing $name/fallback/const-c.inc
100 Writing $name/fallback/const-xs.inc
101 Writing $name/Makefile.PL
103 Writing $name/t/$name.t
104 Writing $name/Changes
105 Writing $name/MANIFEST
108 "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
109 Writing $name/ppport.h
110 Writing $name/lib/$name.pm
111 Writing $name/$name.xs
112 Writing $name/fallback/const-c.inc
113 Writing $name/fallback/const-xs.inc
114 Writing $name/Makefile.PL
116 Writing $name/t/$name.t
117 Writing $name/Changes
118 Writing $name/MANIFEST
121 "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
122 Writing $name/ppport.h
123 Writing $name/lib/$name.pm
124 Writing $name/$name.xs
125 Writing $name/fallback/const-c.inc
126 Writing $name/fallback/const-xs.inc
127 Writing $name/Makefile.PL
129 Writing $name/t/$name.t
130 Writing $name/Changes
131 Writing $name/MANIFEST
134 "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
135 Writing $name/lib/$name.pm
136 Writing $name/Makefile.PL
138 Writing $name/t/$name.t
139 Writing $name/Changes
140 Writing $name/MANIFEST
143 "-f -n $name -b $thisversion $header", $], <<"EOXSFILES",
144 Writing $name/ppport.h
145 Writing $name/lib/$name.pm
146 Writing $name/$name.xs
147 Writing $name/fallback/const-c.inc
148 Writing $name/fallback/const-xs.inc
149 Writing $name/Makefile.PL
151 Writing $name/t/$name.t
152 Writing $name/Changes
153 Writing $name/MANIFEST
157 ok (open (HEADER, '>', $header), "open '$header'");
158 print HEADER <<HEADER or die $!;
161 #define Bactrian /* empty */
164 ok (close (HEADER), "close '$header'");
166 while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
167 # h2xs warns about what it is writing hence the (possibly unportable)
170 my $prog = "$^X $lib $extracted_program $args $dupe";
172 cmp_ok ($?, "==", 0, "running $prog ");
173 $result = join("",@result);
175 #print "# expectation is >$expectation<\n";
176 #print "# result is >$result<\n";
177 # Was the output the list of files that were expected?
178 is ($result, $expectation, "running $prog");
181 find (sub {$got{$File::Find::name}++ unless -d $_}, $name);
183 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
185 if ($Is_VMS_traildot) {
186 $_ .= '.' unless $_ =~ m/\./;
188 $_ = lc($_) unless exists $got{$_};
190 ok (-e $_, "check for $_") and delete $got{$_};
192 my @extra = keys %got;
193 unless (ok (!@extra, "Are any extra files present?")) {
194 print "# These files are unexpectedly present:\n";
195 print "# $_\n" foreach sort @extra;
198 chdir ($name) or die "chdir $name failed: $!";
199 # Aargh. Something wants to load a bit of regexp. And we have to chdir
200 # for ExtUtils::Manifest. Caught between a rock and a hard place, so this
201 # seems the least evil thing to do:
202 push @INC, "../../lib";
203 my ($missing, $extra) = ExtUtils::Manifest::fullcheck();
204 is_deeply ($missing, [], "No files in the MANIFEST should be missing");
205 is_deeply ($extra, [], "and all files present should be in the MANIFEST");
207 chdir ($up) or die "chdir $up failed: $!";
209 if ($args =~ / \Q$header\E$/) {
210 my $const_c = File::Spec->catfile($name, 'fallback', 'const-c.inc');
212 if (!open FILE, '<', $const_c) {
213 $diag = "can't open $const_c: $!";
217 next unless /\b Bactrian 2? \b/x;
222 ok (!$found, "generated $const_c has no Bactrian(2)");
223 diag ($diag) if defined $diag;
226 foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') {
227 my $file = File::Spec->catfile($name, $leaf);
228 if (ok (open (FILE, '<', $file), "open $file")) {
229 my $match = qr/use $version;/;
232 last if $found = /$match/;
234 ok ($found, "looking for /$match/ in $file");
235 close FILE or die "close $file: $!";
242 cmp_ok (unlink ($header), "==", 1, "unlink '$header'") or die "\$! is $!";