This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
AIX needs an explicit symbol export list.
[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
3a9c887e
PK
11BEGIN {
12 chdir 't' if -d 't';
13 @INC = '../lib';
14}
15
45ea237c 16# use strict; # we are not really testing this
3a9c887e 17use File::Path; # for cleaning up with rmtree()
46b277d5 18use Test;
31022a5a 19use File::Spec;
3a9c887e
PK
20
21my $extracted_program = '../utils/h2xs'; # unix, nt, ...
22if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
45ea237c 23if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
3a9c887e
PK
24if (!(-e $extracted_program)) {
25 print "1..0 # Skip: $extracted_program was not built\n";
26 exit 0;
27}
28# You might also wish to bail out if your perl platform does not
29# do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
30
31my $dupe = '2>&1'; # ok on unix, nt, VMS, ...
32my $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS
33# The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
34# already merged).
35if ($^O eq 'MacOS') {
36 $dupe = '';
45ea237c 37 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
3a9c887e
PK
38}
39# $name should differ from system header file names and must
40# not already be found in the t/ subdirectory for perl.
41my $name = 'h2xst';
46b277d5 42my $header = "$name.h";
3e6e4ea8 43my $thisversion = sprintf "%vd", $^V;
3a9c887e 44
46b277d5 45my @tests = (
3e6e4ea8
NC
46"-f -n $name", $], <<"EOXSFILES",
47Defaulting to backwards compatibility with perl $thisversion
48If you intend this module to be compatible with earlier perl versions, please
49specify a minimum perl version with the -b option.
50
3a9c887e
PK
51Writing $name/$name.pm
52Writing $name/$name.xs
9a7df4f2
NC
53Writing $name/fallback.c
54Writing $name/fallback.xs
3a9c887e
PK
55Writing $name/Makefile.PL
56Writing $name/README
57Writing $name/t/1.t
58Writing $name/Changes
59Writing $name/MANIFEST
60EOXSFILES
61
3e6e4ea8
NC
62"-f -n $name -b $thisversion", $], <<"EOXSFILES",
63Writing $name/$name.pm
64Writing $name/$name.xs
65Writing $name/fallback.c
66Writing $name/fallback.xs
67Writing $name/Makefile.PL
68Writing $name/README
69Writing $name/t/1.t
70Writing $name/Changes
71Writing $name/MANIFEST
72EOXSFILES
73
74"-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
75Writing $name/$name.pm
76Writing $name/$name.xs
77Writing $name/fallback.c
78Writing $name/fallback.xs
79Writing $name/Makefile.PL
80Writing $name/README
81Writing $name/t/1.t
82Writing $name/Changes
83Writing $name/MANIFEST
84EOXSFILES
85
86"-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
87Writing $name/$name.pm
88Writing $name/$name.xs
89Writing $name/fallback.c
90Writing $name/fallback.xs
91Writing $name/Makefile.PL
92Writing $name/README
93Writing $name/t/1.t
94Writing $name/Changes
95Writing $name/MANIFEST
96EOXSFILES
97
98"\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
3a9c887e
PK
99Writing $name/$name.pm
100Writing $name/Makefile.PL
101Writing $name/README
102Writing $name/t/1.t
103Writing $name/Changes
104Writing $name/MANIFEST
105EONOXSFILES
106
3e6e4ea8 107"-f -n $name $header -b $thisversion", $], <<"EOXSFILES",
46b277d5
NC
108Writing $name/$name.pm
109Writing $name/$name.xs
9a7df4f2
NC
110Writing $name/fallback.c
111Writing $name/fallback.xs
46b277d5
NC
112Writing $name/Makefile.PL
113Writing $name/README
114Writing $name/t/1.t
115Writing $name/Changes
116Writing $name/MANIFEST
117EOXSFILES
118);
119
120my $total_tests = 3; # opening, closing and deleting the header file.
3e6e4ea8 121for (my $i = $#tests; $i > 0; $i-=3) {
46b277d5 122 # 1 test for running it, 1 test for the expected result, and 1 for each file
3e6e4ea8 123 # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL
46b277d5 124 # use the () to force list context and hence count the number of matches.
3e6e4ea8 125 $total_tests += 6 + (() = $tests[$i] =~ /(Writing)/sg);
46b277d5
NC
126}
127
128plan tests => $total_tests;
129
130ok (open (HEADER, ">$header"));
131print HEADER <<HEADER or die $!;
132#define Camel 2
133#define Dromedary 1
134HEADER
135ok (close (HEADER));
136
3e6e4ea8 137while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
46b277d5
NC
138 # h2xs warns about what it is writing hence the (possibly unportable)
139 # 2>&1 dupe:
140 # does it run?
141 my $prog = "$^X $lib $extracted_program $args $dupe";
142 @result = `$prog`;
143 ok ($?, 0, "running $prog");
144 $result = join("",@result);
145
146 # accomodate MPW # comment character prependage
147 if ($^O eq 'MacOS') {
148 $result =~ s/#\s*//gs;
149 }
150
151 #print "# expectation is >$expectation<\n";
152 #print "# result is >$result<\n";
153 # Was the output the list of files that were expected?
154 ok ($result, $expectation, "running $prog");
155
3e6e4ea8 156 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
45ea237c 157 if ($^O eq 'MacOS') {
46b277d5
NC
158 $_ = ':' . join(':',split(/\//,$_));
159 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
45ea237c 160 }
46b277d5
NC
161 ok (-e $_, 1, "$_ missing");
162 }
3a9c887e 163
3e6e4ea8 164 foreach my $leaf ("$name.pm", 'Makefile.PL') {
31022a5a 165 my $file = File::Spec->catfile($name, $leaf);
3e6e4ea8
NC
166 if (ok (open (FILE, $file), 1, "open $file")) {
167 my $match = qr/use $version;/;
168 my $found;
169 while (<FILE>) {
170 last if $found = /$match/;
171 }
172 ok ($found, 1, "looking for /$match/ in $file");
173 close FILE or die "close $file: $!";
174 }
175 }
46b277d5
NC
176 # clean up
177 rmtree($name);
178}
3a9c887e 179
46b277d5 180ok (unlink ($header), 1, $!);