| 1 | # $Id: Helper.pm 1.7 Fri, 05 Sep 1997 16:08:15 -0400 jesse $ | ||
| 2 | |||
| 3 | package Test::Helper; | ||
| 4 | use Carp; | ||
| 5 | use IO::File; | ||
| 6 | use vars qw($VERSION @ISA @EXPORT $count $output); | ||
| 7 | use Exporter; | ||
| 8 | @ISA=qw(Exporter); | ||
| 9 | @EXPORT=qw(ok comm test runs heinous syntax_check); | ||
| 10 | # $Format: "$VERSION='$TestHelperRelease$';"$ | ||
| 11 | $VERSION='0.002'; | ||
| 12 | |||
| 13 | sub test(&) { | ||
| 14 | local($count)=0; | ||
| 15 | local($output)=''; | ||
| 16 | eval {&{+shift}}; | ||
| 17 | $count++ if $@; # Simulate something wrong. | ||
| 18 | print "1..$count\n$output"; | ||
| 19 | die $@ if $@; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub ok($;) { | ||
| 23 | my $isok=shift; | ||
| 24 | $output .= 'not ' unless $isok; | ||
| 25 | $count++; | ||
| 26 | $output .= "ok $count\n"; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub comm(@) { | ||
| 30 | my $comm=join '', @_; | ||
| 31 | $output .= "# $comm...\n"; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub runs(&) { | ||
| 35 | my $subr=shift; | ||
| 36 | eval {&$subr()}; | ||
| 37 | not $@; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub heinous(&) { | ||
| 41 | carp "`heinous {...}' is deprecated--use `ok not runs {...} instead'"; | ||
| 42 | my $subr=shift; | ||
| 43 | ok not &runs($subr); | ||
| 44 | } | ||
| 45 | |||
| 46 | sub syntax_check() { | ||
| 47 | my @mani=grep { | ||
| 48 | not /\.(t|PL)$/ and not m!^t/! and $_ ne 'test.pl' | ||
| 49 | } map { | ||
| 50 | chomp; | ||
| 51 | s!^lib/!!; | ||
| 52 | $_; | ||
| 53 | } IO::File->new('MANIFEST')->getlines; | ||
| 54 | print "To be checked: @mani\n"; | ||
| 55 | |||
| 56 | local($^W)=1; | ||
| 57 | my $file; foreach $file (@mani) { | ||
| 58 | if ($file =~ /\.pm$/) { | ||
| 59 | comm "Requiring $file"; | ||
| 60 | eval {require $file}; | ||
| 61 | print STDERR $@ if $@; | ||
| 62 | ok not $@; | ||
| 63 | } elsif ($file =~ /\.pl$/ or | ||
| 64 | (-r $file and -x $file and | ||
| 65 | IO::File->new($file)->getline =~ /^\#!\S*perl/)) { | ||
| 66 | comm "Syntax-checking $file"; | ||
| 67 | ok not system $^X, '-wc', $file; | ||
| 68 | } else { | ||
| 69 | comm "Skipping $file"; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; | ||
| 75 | __END__ |