This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update the libnet tests as per #11138.
[perl5.git] / lib / h2xs.t
CommitLineData
3a9c887e
PK
1#!./perl
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
PK
15use File::Path; # for cleaning up with rmtree()
16
17my $extracted_program = '../utils/h2xs'; # unix, nt, ...
18if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; }
45ea237c 19if ($^O eq 'MacOS') { $extracted_program = '::utils:h2xs'; }
3a9c887e
PK
20if (!(-e $extracted_program)) {
21 print "1..0 # Skip: $extracted_program was not built\n";
22 exit 0;
23}
24# You might also wish to bail out if your perl platform does not
25# do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity.
26
27my $dupe = '2>&1'; # ok on unix, nt, VMS, ...
28my $lib = '"-I../lib"'; # ok on unix, nt, The extra \" are for VMS
29# The >&1 would create a file named &1 on MPW (STDERR && STDOUT are
30# already merged).
31if ($^O eq 'MacOS') {
32 $dupe = '';
45ea237c 33 $lib = '-x -I::lib:'; # -x overcomes MPW $Config{startperl} anomaly
3a9c887e
PK
34}
35# $name should differ from system header file names and must
36# not already be found in the t/ subdirectory for perl.
37my $name = 'h2xst';
38
39print "1..17\n";
40
41my @result = ();
42my $result = '';
43my $expectation = '';
44
45# h2xs warns about what it is writing hence the (possibly unportable)
46# 2>&1 dupe:
47# does it run?
48@result = `$^X $lib $extracted_program -f -n $name $dupe`;
49print(((!$?) ? "" : "not "), "ok 1\n");
50$result = join("",@result);
51
52$expectation = <<"EOXSFILES";
53Writing $name/$name.pm
54Writing $name/$name.xs
55Writing $name/Makefile.PL
56Writing $name/README
57Writing $name/t/1.t
58Writing $name/Changes
59Writing $name/MANIFEST
60EOXSFILES
61
62# accomodate MPW # comment character prependage
63if ($^O eq 'MacOS') {
64 $result =~ s/#\s*//gs;
65}
66
67#print "# expectation is >$expectation<\n";
68#print "# result is >$result<\n";
69# Was the output the list of files that were expected?
70print((($result eq $expectation) ? "" : "not "), "ok 2\n");
71# Were the files created?
72my $t = 3;
73$expectation =~ s/Writing //; # remove leader
74foreach (split(/Writing /,$expectation)) {
75 chomp; # remove \n
45ea237c
PK
76 if ($^O eq 'MacOS') {
77 $_ = ':' . join(':',split(/\//,$_));
78 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
79 }
3a9c887e
PK
80 print(((-e $_) ? "" : "not "), "ok $t\n");
81 $t++;
82}
83
84# clean up
85rmtree($name);
86
87# does it run with -X and omit the h2xst.xs file?
88@result = ();
89$result = '';
90# The extra \" around -X are for VMS but do no harm on NT or Unix
91@result = `$^X $lib $extracted_program \"-X\" -f -n $name $dupe`;
92print(((!$?) ? "" : "not "), "ok $t\n");
93$t++;
94$result = join("",@result);
95
96$expectation = <<"EONOXSFILES";
97Writing $name/$name.pm
98Writing $name/Makefile.PL
99Writing $name/README
100Writing $name/t/1.t
101Writing $name/Changes
102Writing $name/MANIFEST
103EONOXSFILES
104
105if ($^O eq 'MacOS') { $result =~ s/#\s*//gs; }
106#print $expectation;
107#print $result;
108print((($result eq $expectation) ? "" : "not "), "ok $t\n");
109$t++;
110$expectation =~ s/Writing //; # remove leader
111foreach (split(/Writing /,$expectation)) {
112 chomp; # remove \n
45ea237c
PK
113 if ($^O eq 'MacOS') {
114 $_ = ':' . join(':',split(/\//,$_));
115 $_ =~ s/$name:t:1.t/$name:t\/1.t/; # is this an h2xs bug?
116 }
3a9c887e
PK
117 print(((-e $_) ? "" : "not "), "ok $t\n");
118 $t++;
119}
120
121# clean up
122rmtree($name);
123