Commit | Line | Data |
---|---|---|
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 | ||
9 | BEGIN { | |
10 | chdir 't' if -d 't'; | |
11 | @INC = '../lib'; | |
12 | } | |
13 | ||
14 | use strict; | |
15 | use File::Path; # for cleaning up with rmtree() | |
16 | ||
17 | my $extracted_program = '../utils/h2xs'; # unix, nt, ... | |
18 | if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2xs.com'; } | |
19 | if ($^O eq 'MacOS') { $extracted_program = ':::utils:h2xs'; } | |
20 | if (!(-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 | ||
27 | my $dupe = '2>&1'; # ok on unix, nt, VMS, ... | |
28 | my $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). | |
31 | if ($^O eq 'MacOS') { | |
32 | $dupe = ''; | |
33 | $lib = '-I::lib:'; | |
34 | } | |
35 | # $name should differ from system header file names and must | |
36 | # not already be found in the t/ subdirectory for perl. | |
37 | my $name = 'h2xst'; | |
38 | ||
39 | print "1..17\n"; | |
40 | ||
41 | my @result = (); | |
42 | my $result = ''; | |
43 | my $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`; | |
49 | print(((!$?) ? "" : "not "), "ok 1\n"); | |
50 | $result = join("",@result); | |
51 | ||
52 | $expectation = <<"EOXSFILES"; | |
53 | Writing $name/$name.pm | |
54 | Writing $name/$name.xs | |
55 | Writing $name/Makefile.PL | |
56 | Writing $name/README | |
57 | Writing $name/t/1.t | |
58 | Writing $name/Changes | |
59 | Writing $name/MANIFEST | |
60 | EOXSFILES | |
61 | ||
62 | # accomodate MPW # comment character prependage | |
63 | if ($^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? | |
70 | print((($result eq $expectation) ? "" : "not "), "ok 2\n"); | |
71 | # Were the files created? | |
72 | my $t = 3; | |
73 | $expectation =~ s/Writing //; # remove leader | |
74 | foreach (split(/Writing /,$expectation)) { | |
75 | chomp; # remove \n | |
76 | if ($^O eq 'MacOS') { $_ = ':' . join(':',split(/\//,$_)); } | |
77 | print(((-e $_) ? "" : "not "), "ok $t\n"); | |
78 | $t++; | |
79 | } | |
80 | ||
81 | # clean up | |
82 | rmtree($name); | |
83 | ||
84 | # does it run with -X and omit the h2xst.xs file? | |
85 | @result = (); | |
86 | $result = ''; | |
87 | # The extra \" around -X are for VMS but do no harm on NT or Unix | |
88 | @result = `$^X $lib $extracted_program \"-X\" -f -n $name $dupe`; | |
89 | print(((!$?) ? "" : "not "), "ok $t\n"); | |
90 | $t++; | |
91 | $result = join("",@result); | |
92 | ||
93 | $expectation = <<"EONOXSFILES"; | |
94 | Writing $name/$name.pm | |
95 | Writing $name/Makefile.PL | |
96 | Writing $name/README | |
97 | Writing $name/t/1.t | |
98 | Writing $name/Changes | |
99 | Writing $name/MANIFEST | |
100 | EONOXSFILES | |
101 | ||
102 | if ($^O eq 'MacOS') { $result =~ s/#\s*//gs; } | |
103 | #print $expectation; | |
104 | #print $result; | |
105 | print((($result eq $expectation) ? "" : "not "), "ok $t\n"); | |
106 | $t++; | |
107 | $expectation =~ s/Writing //; # remove leader | |
108 | foreach (split(/Writing /,$expectation)) { | |
109 | chomp; # remove \n | |
110 | if ($^O eq 'MacOS') { $_ = ':' . join(':',split(/\//,$_)); } | |
111 | print(((-e $_) ? "" : "not "), "ok $t\n"); | |
112 | $t++; | |
113 | } | |
114 | ||
115 | # clean up | |
116 | rmtree($name); | |
117 |