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/Makefile.PL
50 Writing $name/MANIFEST
53 "\"-X\" -f -n $name", <<"EONOXSFILES",
54 Writing $name/$name.pm
55 Writing $name/Makefile.PL
59 Writing $name/MANIFEST
62 "-f -n $name $header", <<"EOXSFILES",
63 Writing $name/$name.pm
64 Writing $name/$name.xs
65 Writing $name/Makefile.PL
69 Writing $name/MANIFEST
73 my $total_tests = 3; # opening, closing and deleting the header file.
74 for (my $i = $#tests; $i > 0; $i-=2) {
75 # 1 test for running it, 1 test for the expected result, and 1 for each file
76 # use the () to force list context and hence count the number of matches.
77 $total_tests += 2 + (() = $tests[$i] =~ /(Writing)/sg);
80 plan tests => $total_tests;
82 ok (open (HEADER, ">$header"));
83 print HEADER <<HEADER or die $!;
89 while (my ($args, $expectation) = splice @tests, 0, 2) {
90 # h2xs warns about what it is writing hence the (possibly unportable)
93 my $prog = "$^X $lib $extracted_program $args $dupe";
95 ok ($?, 0, "running $prog");
96 $result = join("",@result);
98 # accomodate MPW # comment character prependage
100 $result =~ s/#\s*//gs;
103 #print "# expectation is >$expectation<\n";
104 #print "# result is >$result<\n";
105 # Was the output the list of files that were expected?
106 ok ($result, $expectation, "running $prog");
108 $expectation =~ s/Writing //; # remove leader
109 foreach (split(/Writing /,$expectation)) {
111 if ($^O eq 'MacOS') {
112 $_ = ':' . join(':',split(/\//,$_));
113 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
115 ok (-e $_, 1, "$_ missing");
122 ok (unlink ($header), 1, $!);