Commit | Line | Data |
---|---|---|
46b277d5 | 1 | #!./perl -w |
3a9c887e PK |
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 | |
3e6e4ea8 NC |
8 | # |
9 | # We are now checking that the correct use $version; is present in | |
10 | # Makefile.PL and $module.pm | |
fa1e5b33 | 11 | |
3a9c887e PK |
12 | BEGIN { |
13 | chdir 't' if -d 't'; | |
14 | @INC = '../lib'; | |
763a0d21 NC |
15 | # FIXME (or rather FIXh2xs) |
16 | require Config; | |
98641f60 | 17 | if (($Config::Config{'extensions'} !~ m!\bDevel/PPPort\b!) ){ |
763a0d21 NC |
18 | print "1..0 # Skip -- Perl configured without Devel::PPPort module\n"; |
19 | exit 0; | |
20 | } | |
3a9c887e PK |
21 | } |
22 | ||
45ea237c | 23 | # use strict; # we are not really testing this |
3a9c887e | 24 | use File::Path; # for cleaning up with rmtree() |
1cb0fb50 | 25 | use Test::More; |
31022a5a | 26 | use File::Spec; |
1cb0fb50 NC |
27 | use File::Find; |
28 | use ExtUtils::Manifest; | |
29 | # Don't want its diagnostics getting in the way of ours. | |
30 | $ExtUtils::Manifest::Quiet=1; | |
31 | my $up = File::Spec->updir(); | |
3a9c887e PK |
32 | |
33 | my $extracted_program = '../utils/h2xs'; # unix, nt, ... | |
ca48d8be JM |
34 | |
35 | my $Is_VMS_traildot = 0; | |
36 | if ($^O eq 'VMS') { | |
37 | $extracted_program = '[-.utils]h2xs.com'; | |
38 | ||
39 | # We have to know if VMS is in UNIX mode. In UNIX mode, trailing dots | |
40 | # should not be present. There are actually two settings that control this. | |
41 | ||
42 | $Is_VMS_traildot = 1; | |
43 | my $unix_rpt = 0; | |
44 | my $drop_dot = 0; | |
45 | if (eval 'require VMS::Feature') { | |
46 | $unix_rpt = VMS::Feature::current('filename_unix_report'); | |
47 | $drop_dot = VMS::Feature::current('readdir_dropdotnotype'); | |
48 | } else { | |
49 | my $unix_report = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; | |
50 | $unix_rpt = $unix_report =~ /^[ET1]/i; | |
51 | my $drop_dot_notype = $ENV{'DECC$READDIR_DROPDOTNOTYPE'} || ''; | |
52 | $drop_dot = $drop_dot_notype =~ /^[ET1]/i; | |
53 | } | |
54 | $Is_VMS_traildot = 0 if $drop_dot && unix_rpt; | |
55 | } | |
3a9c887e PK |
56 | if (!(-e $extracted_program)) { |
57 | print "1..0 # Skip: $extracted_program was not built\n"; | |
58 | exit 0; | |
59 | } | |
60 | # You might also wish to bail out if your perl platform does not | |
61 | # do `$^X -e 'warn "Writing h2xst"' 2>&1`; duplicity. | |
62 | ||
fa1e5b33 JH |
63 | # ok on unix, nt, VMS, ... |
64 | my $dupe = '2>&1'; | |
65 | # ok on unix, nt, The extra \" are for VMS | |
66 | my $lib = '"-I../lib" "-I../../lib"'; | |
3a9c887e PK |
67 | # $name should differ from system header file names and must |
68 | # not already be found in the t/ subdirectory for perl. | |
69 | my $name = 'h2xst'; | |
46b277d5 | 70 | my $header = "$name.h"; |
3e6e4ea8 | 71 | my $thisversion = sprintf "%vd", $^V; |
9137345a | 72 | $thisversion =~ s/^v//; |
3a9c887e | 73 | |
98d84473 | 74 | # If this test has failed previously a copy may be left. |
9d16830f | 75 | rmtree($name) if -e $name; |
98d84473 | 76 | |
46b277d5 | 77 | my @tests = ( |
3e6e4ea8 NC |
78 | "-f -n $name", $], <<"EOXSFILES", |
79 | Defaulting to backwards compatibility with perl $thisversion | |
80 | If you intend this module to be compatible with earlier perl versions, please | |
81 | specify a minimum perl version with the -b option. | |
82 | ||
0a7c7f4f | 83 | Writing $name/ppport.h |
4a660237 | 84 | Writing $name/lib/$name.pm |
3a9c887e | 85 | Writing $name/$name.xs |
1cb0fb50 NC |
86 | Writing $name/fallback/const-c.inc |
87 | Writing $name/fallback/const-xs.inc | |
3a9c887e PK |
88 | Writing $name/Makefile.PL |
89 | Writing $name/README | |
4a660237 | 90 | Writing $name/t/$name.t |
3a9c887e PK |
91 | Writing $name/Changes |
92 | Writing $name/MANIFEST | |
93 | EOXSFILES | |
94 | ||
3e6e4ea8 | 95 | "-f -n $name -b $thisversion", $], <<"EOXSFILES", |
0a7c7f4f | 96 | Writing $name/ppport.h |
4a660237 | 97 | Writing $name/lib/$name.pm |
3e6e4ea8 | 98 | Writing $name/$name.xs |
1cb0fb50 NC |
99 | Writing $name/fallback/const-c.inc |
100 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
101 | Writing $name/Makefile.PL |
102 | Writing $name/README | |
4a660237 | 103 | Writing $name/t/$name.t |
3e6e4ea8 NC |
104 | Writing $name/Changes |
105 | Writing $name/MANIFEST | |
106 | EOXSFILES | |
107 | ||
108 | "-f -n $name -b 5.6.1", "5.006001", <<"EOXSFILES", | |
0a7c7f4f | 109 | Writing $name/ppport.h |
4a660237 | 110 | Writing $name/lib/$name.pm |
3e6e4ea8 | 111 | Writing $name/$name.xs |
1cb0fb50 NC |
112 | Writing $name/fallback/const-c.inc |
113 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
114 | Writing $name/Makefile.PL |
115 | Writing $name/README | |
4a660237 | 116 | Writing $name/t/$name.t |
3e6e4ea8 NC |
117 | Writing $name/Changes |
118 | Writing $name/MANIFEST | |
119 | EOXSFILES | |
120 | ||
121 | "-f -n $name -b 5.5.3", "5.00503", <<"EOXSFILES", | |
0a7c7f4f | 122 | Writing $name/ppport.h |
4a660237 | 123 | Writing $name/lib/$name.pm |
3e6e4ea8 | 124 | Writing $name/$name.xs |
1cb0fb50 NC |
125 | Writing $name/fallback/const-c.inc |
126 | Writing $name/fallback/const-xs.inc | |
3e6e4ea8 NC |
127 | Writing $name/Makefile.PL |
128 | Writing $name/README | |
4a660237 | 129 | Writing $name/t/$name.t |
3e6e4ea8 NC |
130 | Writing $name/Changes |
131 | Writing $name/MANIFEST | |
132 | EOXSFILES | |
133 | ||
134 | "\"-X\" -f -n $name -b $thisversion", $], <<"EONOXSFILES", | |
4a660237 | 135 | Writing $name/lib/$name.pm |
3a9c887e PK |
136 | Writing $name/Makefile.PL |
137 | Writing $name/README | |
4a660237 | 138 | Writing $name/t/$name.t |
3a9c887e PK |
139 | Writing $name/Changes |
140 | Writing $name/MANIFEST | |
141 | EONOXSFILES | |
142 | ||
f1c8c936 | 143 | "-f -n $name -b $thisversion $header", $], <<"EOXSFILES", |
0a7c7f4f | 144 | Writing $name/ppport.h |
4a660237 | 145 | Writing $name/lib/$name.pm |
46b277d5 | 146 | Writing $name/$name.xs |
1cb0fb50 NC |
147 | Writing $name/fallback/const-c.inc |
148 | Writing $name/fallback/const-xs.inc | |
46b277d5 NC |
149 | Writing $name/Makefile.PL |
150 | Writing $name/README | |
4a660237 | 151 | Writing $name/t/$name.t |
46b277d5 NC |
152 | Writing $name/Changes |
153 | Writing $name/MANIFEST | |
154 | EOXSFILES | |
155 | ); | |
156 | ||
157 | my $total_tests = 3; # opening, closing and deleting the header file. | |
3e6e4ea8 | 158 | for (my $i = $#tests; $i > 0; $i-=3) { |
46b277d5 | 159 | # 1 test for running it, 1 test for the expected result, and 1 for each file |
4a660237 | 160 | # plus 1 to open and 1 to check for the use in lib/$name.pm and Makefile.PL |
1cb0fb50 | 161 | # And 1 more for our check for "bonus" files, 2 more for ExtUtil::Manifest. |
dd5f7cf2 | 162 | # And 1 more to examine const-c.inc contents in tests that use $header. |
46b277d5 | 163 | # use the () to force list context and hence count the number of matches. |
1cb0fb50 | 164 | $total_tests += 9 + (() = $tests[$i] =~ /(Writing)/sg); |
dd5f7cf2 | 165 | $total_tests++ if $tests[$i-2] =~ / \Q$header\E$/; |
46b277d5 NC |
166 | } |
167 | ||
168 | plan tests => $total_tests; | |
169 | ||
1ae6ead9 | 170 | ok (open (HEADER, '>', $header), "open '$header'"); |
46b277d5 NC |
171 | print HEADER <<HEADER or die $!; |
172 | #define Camel 2 | |
173 | #define Dromedary 1 | |
dd5f7cf2 AC |
174 | #define Bactrian /* empty */ |
175 | #define Bactrian2 | |
46b277d5 | 176 | HEADER |
1cb0fb50 | 177 | ok (close (HEADER), "close '$header'"); |
46b277d5 | 178 | |
3e6e4ea8 | 179 | while (my ($args, $version, $expectation) = splice @tests, 0, 3) { |
46b277d5 NC |
180 | # h2xs warns about what it is writing hence the (possibly unportable) |
181 | # 2>&1 dupe: | |
182 | # does it run? | |
183 | my $prog = "$^X $lib $extracted_program $args $dupe"; | |
184 | @result = `$prog`; | |
1cb0fb50 | 185 | cmp_ok ($?, "==", 0, "running $prog "); |
46b277d5 NC |
186 | $result = join("",@result); |
187 | ||
46b277d5 NC |
188 | #print "# expectation is >$expectation<\n"; |
189 | #print "# result is >$result<\n"; | |
190 | # Was the output the list of files that were expected? | |
1cb0fb50 NC |
191 | is ($result, $expectation, "running $prog"); |
192 | ||
193 | my (%got); | |
194 | find (sub {$got{$File::Find::name}++ unless -d $_}, $name); | |
46b277d5 | 195 | |
3e6e4ea8 | 196 | foreach ($expectation =~ /Writing\s+(\S+)/gm) { |
7ce7e561 | 197 | if ($^O eq 'VMS') { |
ca48d8be JM |
198 | if ($Is_VMS_traildot) { |
199 | $_ .= '.' unless $_ =~ m/\./; | |
200 | } | |
7ce7e561 CB |
201 | $_ = lc($_) unless exists $got{$_}; |
202 | } | |
1cb0fb50 NC |
203 | ok (-e $_, "check for $_") and delete $got{$_}; |
204 | } | |
205 | my @extra = keys %got; | |
206 | unless (ok (!@extra, "Are any extra files present?")) { | |
207 | print "# These files are unexpectedly present:\n"; | |
208 | print "# $_\n" foreach sort @extra; | |
46b277d5 | 209 | } |
3a9c887e | 210 | |
1cb0fb50 NC |
211 | chdir ($name) or die "chdir $name failed: $!"; |
212 | # Aargh. Something wants to load a bit of regexp. And we have to chdir | |
213 | # for ExtUtils::Manifest. Caught between a rock and a hard place, so this | |
214 | # seems the least evil thing to do: | |
215 | push @INC, "../../lib"; | |
216 | my ($missing, $extra) = ExtUtils::Manifest::fullcheck(); | |
217 | is_deeply ($missing, [], "No files in the MANIFEST should be missing"); | |
218 | is_deeply ($extra, [], "and all files present should be in the MANIFEST"); | |
219 | pop @INC; | |
220 | chdir ($up) or die "chdir $up failed: $!"; | |
221 | ||
dd5f7cf2 AC |
222 | if ($args =~ / \Q$header\E$/) { |
223 | my $const_c = File::Spec->catfile($name, 'fallback', 'const-c.inc'); | |
224 | my ($found, $diag); | |
225 | if (!open FILE, '<', $const_c) { | |
226 | $diag = "can't open $const_c: $!"; | |
227 | } | |
228 | else { | |
229 | while (<FILE>) { | |
230 | next unless /\b Bactrian 2? \b/x; | |
231 | $found = 1; | |
232 | last; | |
233 | } | |
234 | } | |
235 | ok (!$found, "generated $const_c has no Bactrian(2)"); | |
236 | diag ($diag) if defined $diag; | |
237 | } | |
238 | ||
4a660237 | 239 | foreach my $leaf (File::Spec->catfile('lib', "$name.pm"), 'Makefile.PL') { |
31022a5a | 240 | my $file = File::Spec->catfile($name, $leaf); |
1ae6ead9 | 241 | if (ok (open (FILE, '<', $file), "open $file")) { |
3e6e4ea8 NC |
242 | my $match = qr/use $version;/; |
243 | my $found; | |
244 | while (<FILE>) { | |
245 | last if $found = /$match/; | |
246 | } | |
1cb0fb50 | 247 | ok ($found, "looking for /$match/ in $file"); |
3e6e4ea8 NC |
248 | close FILE or die "close $file: $!"; |
249 | } | |
250 | } | |
46b277d5 NC |
251 | # clean up |
252 | rmtree($name); | |
253 | } | |
3a9c887e | 254 | |
1cb0fb50 | 255 | cmp_ok (unlink ($header), "==", 1, "unlink '$header'") or die "\$! is $!"; |