Updated to Git v1.8.4
[msysgit.git] / bin / perlivp
blob1217d71b30de1674eb95f3e3a7e0b3d2c51edeca
1 #!/usr/bin/perl
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
5 # perlivp V 0.02
8 sub usage {
9 warn "@_\n" if @_;
10 print << " EOUSAGE";
11 Usage:
13 $0 [-a] [-p] [-v] | [-h]
15 -a Run all tests (default is to skip .ph tests)
16 -p Print a preface before each test telling what it will test.
17 -v Verbose mode in which extra information about test results
18 is printed. Test failures always print out some extra information
19 regardless of whether or not this switch is set.
20 -h Prints this help message.
21 EOUSAGE
22 exit;
25 use vars qw(%opt); # allow testing with older versions (do not use our)
27 @opt{ qw/? H h P p V v/ } = qw(0 0 0 0 0 0 0);
29 while ($ARGV[0] =~ /^-/) {
30 $ARGV[0] =~ s/^-//;
31 for my $flag (split(//,$ARGV[0])) {
32 usage() if '?' =~ /\Q$flag/;
33 usage() if 'h' =~ /\Q$flag/;
34 usage() if 'H' =~ /\Q$flag/;
35 usage("unknown flag: `$flag'") unless 'HhPpVva' =~ /\Q$flag/;
36 warn "$0: `$flag' flag already set\n" if $opt{$flag}++;
38 shift;
41 $opt{p}++ if $opt{P};
42 $opt{v}++ if $opt{V};
44 my $pass__total = 0;
45 my $error_total = 0;
46 my $tests_total = 0;
48 my $perlpath = '/usr/bin/perl';
49 my $useithreads = '';
51 print "## Checking Perl binary via variable `\$perlpath' = $perlpath.\n" if $opt{'p'};
53 if (-x $perlpath) {
54 print "## Perl binary `$perlpath' appears executable.\n" if $opt{'v'};
55 print "ok 1\n";
56 $pass__total++;
58 else {
59 print "# Perl binary `$perlpath' does not appear executable.\n";
60 print "not ok 1\n";
61 $error_total++;
63 $tests_total++;
66 print "## Checking Perl version via variable `\$]'.\n" if $opt{'p'};
68 my $ivp_VERSION = 5.008008;
70 if ($ivp_VERSION eq $]) {
71 print "## Perl version `$]' appears installed as expected.\n" if $opt{'v'};
72 print "ok 2\n";
73 $pass__total++;
75 else {
76 print "# Perl version `$]' installed, expected $ivp_VERSION.\n";
77 print "not ok 2\n";
78 $error_total++;
80 $tests_total++;
83 print "## Checking roots of the Perl library directory tree via variable `\@INC'.\n" if $opt{'p'};
85 my $INC_total = 0;
86 my $INC_there = 0;
87 foreach (@INC) {
88 next if $_ eq '.'; # skip -d test here
89 if ($^O eq 'MacOS') {
90 next if $_ eq ':'; # skip -d test here
91 next if $_ eq 'Dev:Pseudo:'; # why is this in @INC?
93 if (-d $_) {
94 print "## Perl \@INC directory `$_' exists.\n" if $opt{'v'};
95 $INC_there++;
97 else {
98 print "# Perl \@INC directory `$_' does not appear to exist.\n";
100 $INC_total++;
102 if ($INC_total == $INC_there) {
103 print "ok 3\n";
104 $pass__total++;
106 else {
107 print "not ok 3\n";
108 $error_total++;
110 $tests_total++;
113 print "## Checking installations of modules necessary for ivp.\n" if $opt{'p'};
115 my $needed_total = 0;
116 my $needed_there = 0;
117 foreach (qw(Config.pm ExtUtils/Installed.pm)) {
118 $@ = undef;
119 $needed_total++;
120 eval "require \"$_\";";
121 if (!$@) {
122 print "## Module `$_' appears to be installed.\n" if $opt{'v'};
123 $needed_there++;
125 else {
126 print "# Needed module `$_' does not appear to be properly installed.\n";
128 $@ = undef;
130 if ($needed_total == $needed_there) {
131 print "ok 4\n";
132 $pass__total++;
134 else {
135 print "not ok 4\n";
136 $error_total++;
138 $tests_total++;
141 print "## Checking installations of extensions built with perl.\n" if $opt{'p'};
143 use Config;
145 my $extensions_total = 0;
146 my $extensions_there = 0;
147 if (defined($Config{'extensions'})) {
148 my @extensions = split(/\s+/,$Config{'extensions'});
149 foreach (@extensions) {
150 next if ($_ eq '');
151 if ( $useithreads !~ /define/i ) {
152 next if ($_ eq 'threads');
153 next if ($_ eq 'threads/shared');
155 next if ($_ eq 'Devel/DProf');
156 # VMS$ perl -e "eval ""require \""Devel/DProf.pm\"";"" print $@"
157 # \NT> perl -e "eval \"require 'Devel/DProf.pm'\"; print $@"
158 # DProf: run perl with -d to use DProf.
159 # Compilation failed in require at (eval 1) line 1.
160 eval " require \"$_.pm\"; ";
161 if (!$@) {
162 print "## Module `$_' appears to be installed.\n" if $opt{'v'};
163 $extensions_there++;
165 else {
166 print "# Required module `$_' does not appear to be properly installed.\n";
167 $@ = undef;
169 $extensions_total++;
172 # A silly name for a module (that hopefully won't ever exist).
173 # Note that this test serves more as a check of the validity of the
174 # actuall required module tests above.
175 my $unnecessary = 'bLuRfle';
177 if (!grep(/$unnecessary/, @extensions)) {
178 $@ = undef;
179 eval " require \"$unnecessary.pm\"; ";
180 if ($@) {
181 print "## Unnecessary module `$unnecessary' does not appear to be installed.\n" if $opt{'v'};
183 else {
184 print "# Unnecessary module `$unnecessary' appears to be installed.\n";
185 $extensions_there++;
188 $@ = undef;
190 if ($extensions_total == $extensions_there) {
191 print "ok 5\n";
192 $pass__total++;
194 else {
195 print "not ok 5\n";
196 $error_total++;
198 $tests_total++;
201 print "## Checking installations of later additional extensions.\n" if $opt{'p'};
203 use ExtUtils::Installed;
205 my $installed_total = 0;
206 my $installed_there = 0;
207 my $version_check = 0;
208 my $installed = ExtUtils::Installed -> new();
209 my @modules = $installed -> modules();
210 my @missing = ();
211 my $version = undef;
212 for (@modules) {
213 $installed_total++;
214 # Consider it there if it contains one or more files,
215 # and has zero missing files,
216 # and has a defined version
217 $version = undef;
218 $version = $installed -> version($_);
219 if ($version) {
220 print "## $_; $version\n" if $opt{'v'};
221 $version_check++;
223 else {
224 print "# $_; NO VERSION\n" if $opt{'v'};
226 $version = undef;
227 @missing = ();
228 @missing = $installed -> validate($_);
229 if ($#missing >= 0) {
230 print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n";
231 print '# ',join(' ',@missing),"\n";
233 elsif ($#missing == -1) {
234 $installed_there++;
236 @missing = ();
238 if (($installed_total == $installed_there) &&
239 ($installed_total == $version_check)) {
240 print "ok 6\n";
241 $pass__total++;
243 else {
244 print "not ok 6\n";
245 $error_total++;
247 $tests_total++;
250 if ($opt{'a'}) {
251 print "## Checking installations of *.h -> *.ph header files.\n" if $opt{'p'};
252 my $ph_there = 0;
253 my $var = undef;
254 my $val = undef;
255 my $h_file = undef;
256 # Just about "any" C implementation ought to have a stdio.h (even if
257 # Config.pm may not list a i_stdio var).
258 my @ph_files = qw(stdio.ph);
259 # Add the ones that we know that perl thinks are there:
260 while (($var, $val) = each %Config) {
261 if ($var =~ m/i_(.+)/ && $val eq 'define') {
262 $h_file = $1;
263 # Some header and symbol names don't match for hysterical raisins.
264 $h_file = 'arpa/inet' if $h_file eq 'arpainet';
265 $h_file = 'netinet/in' if $h_file eq 'niin';
266 $h_file = 'netinet/tcp' if $h_file eq 'netinettcp';
267 $h_file = 'sys/resource' if $h_file eq 'sysresrc';
268 $h_file = 'sys/select' if $h_file eq 'sysselct';
269 $h_file = 'sys/security' if $h_file eq 'syssecrt';
270 $h_file = 'rpcsvc/dbm' if $h_file eq 'rpcsvcdbm';
271 # This ought to distinguish syslog from sys/syslog.
272 # (NB syslog.ph is heavily used for the DBI pre-requisites).
273 $h_file =~ s{^sys(\w.+)}{sys/$1} unless $h_file eq 'syslog';
274 push(@ph_files, "$h_file.ph");
277 #foreach (qw(stdio.ph syslog.ph)) {
278 foreach (@ph_files) {
279 $@ = undef;
280 eval "require \"$_\";";
281 if (!$@) {
282 print "## Perl header `$_' appears to be installed.\n" if $opt{'v'};
283 $ph_there++;
285 else {
286 print "# Perl header `$_' does not appear to be properly installed.\n";
288 $@ = undef;
291 if (scalar(@ph_files) == $ph_there) {
292 print "ok 7\n";
293 $pass__total++;
295 else {
296 print "not ok 7\n";
297 $error_total++;
299 $tests_total++;
301 else {
302 print "## Skip checking of *.ph header files.\n" if $opt{'p'};
305 # Final report (rather than feed ousrselves to Test::Harness::runtests()
306 # we simply format some output on our own to keep things simple and
307 # easier to "fix" - at least for now.
309 if ($error_total == 0 && $tests_total) {
310 print "All tests successful.\n";
311 } elsif ($tests_total==0){
312 die "FAILED--no tests were run for some reason.\n";
313 } else {
314 my $rate = 0.0;
315 if ($tests_total > 0) { $rate = sprintf "%.2f", 100.0 * ($pass__total / $tests_total); }
316 printf " %d/%d subtests failed, %.2f%% okay.\n",
317 $error_total, $tests_total, $rate;
320 =head1 NAME
322 perlivp - Perl Installation Verification Procedure
324 =head1 SYNOPSIS
326 B<perlivp> [B<-a>] [B<-p>] [B<-v>] [B<-h>]
328 =head1 DESCRIPTION
330 The B<perlivp> program is set up at Perl source code build time to test the
331 Perl version it was built under. It can be used after running:
333 make install
335 (or your platform's equivalent procedure) to verify that B<perl> and its
336 libraries have been installed correctly. A correct installation is verified
337 by output that looks like:
339 ok 1
340 ok 2
342 etc.
344 =head1 OPTIONS
346 =over 5
348 =item B<-h> help
350 Prints out a brief help message.
352 =item B<-a> run all tests
354 Normally tests for optional features are skipped. With -a all tests
355 are executed.
357 =item B<-p> print preface
359 Gives a description of each test prior to performing it.
361 =item B<-v> verbose
363 Gives more detailed information about each test, after it has been performed.
364 Note that any failed tests ought to print out some extra information whether
365 or not -v is thrown.
367 =back
369 =head1 DIAGNOSTICS
371 =over 4
373 =item * print "# Perl binary `$perlpath' does not appear executable.\n";
375 Likely to occur for a perl binary that was not properly installed.
376 Correct by conducting a proper installation.
378 =item * print "# Perl version `$]' installed, expected $ivp_VERSION.\n";
380 Likely to occur for a perl that was not properly installed.
381 Correct by conducting a proper installation.
383 =item * print "# Perl \@INC directory `$_' does not appear to exist.\n";
385 Likely to occur for a perl library tree that was not properly installed.
386 Correct by conducting a proper installation.
388 =item * print "# Needed module `$_' does not appear to be properly installed.\n";
390 One of the two modules that is used by perlivp was not present in the
391 installation. This is a serious error since it adversely affects perlivp's
392 ability to function. You may be able to correct this by performing a
393 proper perl installation.
395 =item * print "# Required module `$_' does not appear to be properly installed.\n";
397 An attempt to C<eval "require $module"> failed, even though the list of
398 extensions indicated that it should succeed. Correct by conducting a proper
399 installation.
401 =item * print "# Unnecessary module `bLuRfle' appears to be installed.\n";
403 This test not coming out ok could indicate that you have in fact installed
404 a bLuRfle.pm module or that the C<eval " require \"$module_name.pm\"; ">
405 test may give misleading results with your installation of perl. If yours
406 is the latter case then please let the author know.
408 =item * print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n";
410 One or more files turned up missing according to a run of
411 C<ExtUtils::Installed -E<gt> validate()> over your installation.
412 Correct by conducting a proper installation.
414 =item * print "# Perl header `$_' does not appear to be properly installed.\n";
416 Correct by running B<h2ph> over your system's C header files. If necessary,
417 edit the resulting *.ph files to eliminate perl syntax errors.
419 =back
421 For further information on how to conduct a proper installation consult the
422 INSTALL file that comes with the perl source and the README file for your
423 platform.
425 =head1 AUTHOR
427 Peter Prymmer
429 =cut