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