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.
14 # use strict; # we are not really testing this
15 use File::Path; # for cleaning up with rmtree()
19 my $extracted_program = '../utils/h2xs'; # unix, nt, ...
20 if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
21 if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
22 if (!(-e $extracted_program)) {
23 print "1..0 # Skip: $extracted_program was not built\n";
26 # You might also wish to bail out if your perl platform does not
27 # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
29 my $dupe = '2>&1'; # ok on unix, nt, VMS, ...
30 my $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS
31 # The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
35 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
37 # $name should differ from system header file names and must
38 # not already be found in the t/ subdirectory for perl.
40 my $header = "$name.h";
43 "-f -n $name", <<"EOXSFILES",
44 Writing $name/$name.pm
45 Writing $name/$name.xs
46 Writing $name/fallback.c
47 Writing $name/fallback.xs
48 Writing $name/Makefile.PL
52 Writing $name/MANIFEST
55 "\"-X\" -f -n $name", <<"EONOXSFILES",
56 Writing $name/$name.pm
57 Writing $name/Makefile.PL
61 Writing $name/MANIFEST
64 "-f -n $name $header", <<"EOXSFILES",
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
77 my $total_tests = 3; # opening, closing and deleting the header file.
78 for (my $i = $#tests; $i > 0; $i-=2) {
79 # 1 test for running it, 1 test for the expected result, and 1 for each file
80 # use the () to force list context and hence count the number of matches.
81 $total_tests += 2 + (() = $tests[$i] =~ /(Writing)/sg);
84 plan tests => $total_tests;
86 ok (open (HEADER, ">$header"));
87 print HEADER <<HEADER or die $!;
93 while (my ($args, $expectation) = splice @tests, 0, 2) {
94 # h2xs warns about what it is writing hence the (possibly unportable)
97 my $prog = "$^X $lib $extracted_program $args $dupe";
99 ok ($?, 0, "running $prog");
100 $result = join("",@result);
102 # accomodate MPW # comment character prependage
103 if ($^O eq 'MacOS') {
104 $result =~ s/#\s*//gs;
107 #print "# expectation is >$expectation<\n";
108 #print "# result is >$result<\n";
109 # Was the output the list of files that were expected?
110 ok ($result, $expectation, "running $prog");
112 $expectation =~ s/Writing //; # remove leader
113 foreach (split(/Writing /,$expectation)) {
115 if ($^O eq 'MacOS') {
116 $_ = ':' . join(':',split(/\//,$_));
117 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
119 ok (-e $_, 1, "$_ missing");
126 ok (unlink ($header), 1, $!);