Explain in more detail why -pipe and -fno-common are good.
[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
8
9BEGIN {
10 chdir 't' if -d 't';
11 @INC = '../lib';
12}
13
45ea237c 14# use strict; # we are not really testing this
3a9c887e 15use File::Path; # for cleaning up with rmtree()
46b277d5 16use Test;
17
3a9c887e 18
19my $extracted_program = '../utils/h2xs'; # unix, nt, ...
20if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
45ea237c 21if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
3a9c887e 22if (!(-e $extracted_program)) {
23 print "1..0 # Skip: $extracted_program was not built\n";
24 exit 0;
25}
26# You might also wish to bail out if your perl platform does not
27# do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
28
29my $dupe = '2>&1'; # ok on unix, nt, VMS, ...
30my $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
32# already merged).
33if ($^O eq 'MacOS') {
34 $dupe = '';
45ea237c 35 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
3a9c887e 36}
37# $name should differ from system header file names and must
38# not already be found in the t/ subdirectory for perl.
39my $name = 'h2xst';
46b277d5 40my $header = "$name.h";
3a9c887e 41
46b277d5 42my @tests = (
43"-f -n $name", <<"EOXSFILES",
3a9c887e 44Writing $name/$name.pm
45Writing $name/$name.xs
46Writing $name/Makefile.PL
47Writing $name/README
48Writing $name/t/1.t
49Writing $name/Changes
50Writing $name/MANIFEST
51EOXSFILES
52
46b277d5 53"\"-X\" -f -n $name", <<"EONOXSFILES",
3a9c887e 54Writing $name/$name.pm
55Writing $name/Makefile.PL
56Writing $name/README
57Writing $name/t/1.t
58Writing $name/Changes
59Writing $name/MANIFEST
60EONOXSFILES
61
46b277d5 62"-f -n $name $header", <<"EOXSFILES",
63Writing $name/$name.pm
64Writing $name/$name.xs
65Writing $name/Makefile.PL
66Writing $name/README
67Writing $name/t/1.t
68Writing $name/Changes
69Writing $name/MANIFEST
70EOXSFILES
71);
72
73my $total_tests = 3; # opening, closing and deleting the header file.
74for (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);
78}
79
80plan tests => $total_tests;
81
82ok (open (HEADER, ">$header"));
83print HEADER <<HEADER or die $!;
84#define Camel 2
85#define Dromedary 1
86HEADER
87ok (close (HEADER));
88
89while (my ($args, $expectation) = splice @tests, 0, 2) {
90 # h2xs warns about what it is writing hence the (possibly unportable)
91 # 2>&1 dupe:
92 # does it run?
93 my $prog = "$^X $lib $extracted_program $args $dupe";
94 @result = `$prog`;
95 ok ($?, 0, "running $prog");
96 $result = join("",@result);
97
98 # accomodate MPW # comment character prependage
99 if ($^O eq 'MacOS') {
100 $result =~ s/#\s*//gs;
101 }
102
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");
107
108 $expectation =~ s/Writing //; # remove leader
109 foreach (split(/Writing /,$expectation)) {
3a9c887e 110 chomp; # remove \n
45ea237c 111 if ($^O eq 'MacOS') {
46b277d5 112 $_ = ':' . join(':',split(/\//,$_));
113 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
45ea237c 114 }
46b277d5 115 ok (-e $_, 1, "$_ missing");
116 }
3a9c887e 117
46b277d5 118 # clean up
119 rmtree($name);
120}
3a9c887e 121
46b277d5 122ok (unlink ($header), 1, $!);