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
16 # use strict; # we are not really testing this
17 use File::Path; # for cleaning up with rmtree()
21 my $extracted_program = '../utils/h2xs'; # unix, nt, ...
22 if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
23 if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
24 if (!(-e $extracted_program)) {
25 print "1..0 # Skip: $extracted_program was not built\n";
28 # You might also wish to bail out if your perl platform does not
29 # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
31 my $dupe = '2>&1'; # ok on unix, nt, VMS, ...
32 my $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
37 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
39 # $name should differ from system header file names and must
40 # not already be found in the t/ subdirectory for perl.
42 my $header = "$name.h";
43 my $thisversion = sprintf "%vd", $^V;
46 "-f -n $name", $], <<"EOXSFILES",
47 Defaulting to backwards compatibility with perl $thisversion
48 If you intend this module to be compatible with earlier perl versions, please
49 specify a minimum perl version with the -b option.
51 Writing $name/ppport.h
52 Writing $name/$name.pm
53 Writing $name/$name.xs
54 Writing $name/fallback.c
55 Writing $name/fallback.xs
56 Writing $name/Makefile.PL
60 Writing $name/MANIFEST
63 "-f -n $name -b $thisversion", $], <<"EOXSFILES",
64 Writing $name/ppport.h
65 Writing $name/$name.pm
66 Writing $name/$name.xs
67 Writing $name/fallback.c
68 Writing $name/fallback.xs
69 Writing $name/Makefile.PL
73 Writing $name/MANIFEST
76 "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES",
77 Writing $name/ppport.h
78 Writing $name/$name.pm
79 Writing $name/$name.xs
80 Writing $name/fallback.c
81 Writing $name/fallback.xs
82 Writing $name/Makefile.PL
86 Writing $name/MANIFEST
89 "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES",
90 Writing $name/ppport.h
91 Writing $name/$name.pm
92 Writing $name/$name.xs
93 Writing $name/fallback.c
94 Writing $name/fallback.xs
95 Writing $name/Makefile.PL
99 Writing $name/MANIFEST
102 "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES",
103 Writing $name/$name.pm
104 Writing $name/Makefile.PL
107 Writing $name/Changes
108 Writing $name/MANIFEST
111 "-f -n $name $header -b $thisversion", $], <<"EOXSFILES",
112 Writing $name/ppport.h
113 Writing $name/$name.pm
114 Writing $name/$name.xs
115 Writing $name/fallback.c
116 Writing $name/fallback.xs
117 Writing $name/Makefile.PL
120 Writing $name/Changes
121 Writing $name/MANIFEST
125 my $total_tests = 3; # opening, closing and deleting the header file.
126 for (my $i = $#tests; $i > 0; $i-=3) {
127 # 1 test for running it, 1 test for the expected result, and 1 for each file
128 # plus 1 to open and 1 to check for the use in $name.pm and Makefile.PL
129 # use the () to force list context and hence count the number of matches.
130 $total_tests += 6 + (() = $tests[$i] =~ /(Writing)/sg);
133 plan tests => $total_tests;
135 ok (open (HEADER, ">$header"));
136 print HEADER <<HEADER or die $!;
142 while (my ($args, $version, $expectation) = splice @tests, 0, 3) {
143 # h2xs warns about what it is writing hence the (possibly unportable)
146 my $prog = "$^X $lib $extracted_program $args $dupe";
148 ok ($?, 0, "running $prog");
149 $result = join("",@result);
151 # accomodate MPW # comment character prependage
152 if ($^O eq 'MacOS') {
153 $result =~ s/#\s*//gs;
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");
161 foreach ($expectation =~ /Writing\s+(\S+)/gm) {
162 if ($^O eq 'MacOS') {
163 $_ = ':' . join(':',split(/\//,$_));
164 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
166 ok (-e $_, 1, "$_ missing");
169 foreach my $leaf ("$name.pm", 'Makefile.PL') {
170 my $file = File::Spec->catfile($name, $leaf);
171 if (ok (open (FILE, $file), 1, "open $file")) {
172 my $match = qr/use $version;/;
175 last if $found = /$match/;
177 ok ($found, 1, "looking for /$match/ in $file");
178 close FILE or die "close $file: $!";
185 ok (unlink ($header), 1, $!);