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