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
17 # use strict; # we are not really testing this
18 use File::Path; # for cleaning up with rmtree()
22 my $extracted_program = '../utils/h2xs'; # unix, nt, ...
23 if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
24 if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
25 if (!(-e $extracted_program)) {
26 print "1..0 # Skip: $extracted_program was not built\n";
29 # You might also wish to bail out if your perl platform does not
30 # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
32 # ok on unix, nt, VMS, ...
34 # ok on unix, nt, The extra \" are for VMS
35 my $lib = '"-I../lib" "-I../../lib"';
36 # The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
40 # -x overcomes MPW $Config{startperl} anomaly
41 $lib = '-x -I::lib: -I:::lib:';
43 # $name should differ from system header file names and must
44 # not already be found in the t/ subdirectory for perl.
46 my $header = "$name.h";
47 my $thisversion = sprintf "%vd", $^V;
50 "-f -n $name", $], <<"EOXSFILES",
51 Defaulting to backwards compatibility with perl $thisversion
52 If you intend this module to be compatible with earlier perl versions, please
53 specify a minimum perl version with the -b option.
55 Writing $name/ppport.h
56 Writing $name/$name.pm
57 Writing $name/$name.xs
58 Writing $name/fallback.c
59 Writing $name/fallback.xs
60 Writing $name/Makefile.PL
64 Writing $name/MANIFEST
67 "-f -n $name -b $thisversion", $], <<"EOXSFILES",
68 Writing $name/ppport.h
69 Writing $name/$name.pm
70 Writing $name/$name.xs
71 Writing $name/fallback.c
72 Writing $name/fallback.xs
73 Writing $name/Makefile.PL
77 Writing $name/MANIFEST
80 "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
81 Writing $name/ppport.h
82 Writing $name/$name.pm
83 Writing $name/$name.xs
84 Writing $name/fallback.c
85 Writing $name/fallback.xs
86 Writing $name/Makefile.PL
90 Writing $name/MANIFEST
93 "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
94 Writing $name/ppport.h
95 Writing $name/$name.pm
96 Writing $name/$name.xs
97 Writing $name/fallback.c
98 Writing $name/fallback.xs
99 Writing $name/Makefile.PL
102 Writing $name/Changes
103 Writing $name/MANIFEST
106 "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
107 Writing $name/$name.pm
108 Writing $name/Makefile.PL
111 Writing $name/Changes
112 Writing $name/MANIFEST
115 "-f -n $name $header -b $thisversion", $], <<"EOXSFILES",
116 Writing $name/ppport.h
117 Writing $name/$name.pm
118 Writing $name/$name.xs
119 Writing $name/fallback.c
120 Writing $name/fallback.xs
121 Writing $name/Makefile.PL
124 Writing $name/Changes
125 Writing $name/MANIFEST
129 my $total_tests = 3; # opening, closing and deleting the header file.
130 for (my $i = $#tests; $i > 0; $i-=3) {
131 # 1 test for running it, 1 test for the expected result, and 1 for each file
132 # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL
133 # use the () to force list context and hence count the number of matches.
134 $total_tests += 6 + (() = $tests[$i] =~ /(Writing)/sg);
137 plan tests => $total_tests;
139 ok (open (HEADER, ">$header"));
140 print HEADER <<HEADER or die $!;
146 while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
147 # h2xs warns about what it is writing hence the (possibly unportable)
150 my $prog = "$^X $lib $extracted_program $args $dupe";
152 ok ($?, 0, "running $prog ");
153 $result = join("",@result);
155 # accomodate MPW # comment character prependage
156 if ($^O eq 'MacOS') {
157 $result =~ s/#\s*//gs;
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");
165 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
166 if ($^O eq 'MacOS') {
167 $_ = ':' . join(':',split(/\//,$_));
168 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
170 ok (-e $_, 1, "$_ missing");
173 foreach my $leaf ("$name.pm", 'Makefile.PL') {
174 my $file = File::Spec->catfile($name, $leaf);
175 if (ok (open (FILE, $file), 1, "open $file")) {
176 my $match = qr/use $version;/;
179 last if $found = /$match/;
181 ok ($found, 1, "looking for /$match/ in $file");
182 close FILE or die "close $file: $!";
189 ok (unlink ($header), 1, $!);