Message-ID: <f1gj4usu5m76bv88a3ldptnmo6ld7d44ri@4ax.com>
[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
3a9c887e 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 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 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 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 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
0a7c7f4f 51Writing $name/ppport.h
3a9c887e 52Writing $name/$name.pm
53Writing $name/$name.xs
9a7df4f2 54Writing $name/fallback.c
55Writing $name/fallback.xs
3a9c887e 56Writing $name/Makefile.PL
57Writing $name/README
58Writing $name/t/1.t
59Writing $name/Changes
60Writing $name/MANIFEST
61EOXSFILES
62
3e6e4ea8 63"-f -n $name -b $thisversion", $], <<"EOXSFILES",
0a7c7f4f 64Writing $name/ppport.h
3e6e4ea8 65Writing $name/$name.pm
66Writing $name/$name.xs
67Writing $name/fallback.c
68Writing $name/fallback.xs
69Writing $name/Makefile.PL
70Writing $name/README
71Writing $name/t/1.t
72Writing $name/Changes
73Writing $name/MANIFEST
74EOXSFILES
75
76"-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
0a7c7f4f 77Writing $name/ppport.h
3e6e4ea8 78Writing $name/$name.pm
79Writing $name/$name.xs
80Writing $name/fallback.c
81Writing $name/fallback.xs
82Writing $name/Makefile.PL
83Writing $name/README
84Writing $name/t/1.t
85Writing $name/Changes
86Writing $name/MANIFEST
87EOXSFILES
88
89"-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
0a7c7f4f 90Writing $name/ppport.h
3e6e4ea8 91Writing $name/$name.pm
92Writing $name/$name.xs
93Writing $name/fallback.c
94Writing $name/fallback.xs
95Writing $name/Makefile.PL
96Writing $name/README
97Writing $name/t/1.t
98Writing $name/Changes
99Writing $name/MANIFEST
100EOXSFILES
101
102"\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
3a9c887e 103Writing $name/$name.pm
104Writing $name/Makefile.PL
105Writing $name/README
106Writing $name/t/1.t
107Writing $name/Changes
108Writing $name/MANIFEST
109EONOXSFILES
110
3e6e4ea8 111"-f -n $name $header -b $thisversion", $], <<"EOXSFILES",
0a7c7f4f 112Writing $name/ppport.h
46b277d5 113Writing $name/$name.pm
114Writing $name/$name.xs
9a7df4f2 115Writing $name/fallback.c
116Writing $name/fallback.xs
46b277d5 117Writing $name/Makefile.PL
118Writing $name/README
119Writing $name/t/1.t
120Writing $name/Changes
121Writing $name/MANIFEST
122EOXSFILES
123);
124
125my $total_tests = 3; # opening, closing and deleting the header file.
3e6e4ea8 126for (my $i = $#tests; $i > 0; $i-=3) {
46b277d5 127 # 1 test for running it, 1 test for the expected result, and 1 for each file
3e6e4ea8 128 # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL
46b277d5 129 # use the () to force list context and hence count the number of matches.
3e6e4ea8 130 $total_tests += 6 + (() = $tests[$i] =~ /(Writing)/sg);
46b277d5 131}
132
133plan tests => $total_tests;
134
135ok (open (HEADER, ">$header"));
136print HEADER <<HEADER or die $!;
137#define Camel 2
138#define Dromedary 1
139HEADER
140ok (close (HEADER));
141
3e6e4ea8 142while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
46b277d5 143 # h2xs warns about what it is writing hence the (possibly unportable)
144 # 2>&1 dupe:
145 # does it run?
146 my $prog = "$^X $lib $extracted_program $args $dupe";
147 @result = `$prog`;
148 ok ($?, 0, "running $prog");
149 $result = join("",@result);
150
151 # accomodate MPW # comment character prependage
152 if ($^O eq 'MacOS') {
153 $result =~ s/#\s*//gs;
154 }
155
156 #print "# expectation is >$expectation<\n";
157 #print "# result is >$result<\n";
158 # Was the output the list of files that were expected?
159 ok ($result, $expectation, "running $prog");
160
3e6e4ea8 161 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
45ea237c 162 if ($^O eq 'MacOS') {
46b277d5 163 $_ = ':' . join(':',split(/\//,$_));
164 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
45ea237c 165 }
46b277d5 166 ok (-e $_, 1, "$_ missing");
167 }
3a9c887e 168
3e6e4ea8 169 foreach my $leaf ("$name.pm", 'Makefile.PL') {
31022a5a 170 my $file = File::Spec->catfile($name, $leaf);
3e6e4ea8 171 if (ok (open (FILE, $file), 1, "open $file")) {
172 my $match = qr/use $version;/;
173 my $found;
174 while (<FILE>) {
175 last if $found = /$match/;
176 }
177 ok ($found, 1, "looking for /$match/ in $file");
178 close FILE or die "close $file: $!";
179 }
180 }
46b277d5 181 # clean up
182 rmtree($name);
183}
3a9c887e 184
46b277d5 185ok (unlink ($header), 1, $!);