X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTest.pm;h=60e9f7eee1021ac9a7267fd92a548a2c5f549807;hb=92dffb52e8549d6a194db47a2e5b989b8338a19a;hp=22f947acf1ef0364b60e30353a2af38cf6df4f55;hpb=f2ac83ee9b0351aafadde538d84d97d64ef7e570;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Test.pm b/lib/Test.pm index 22f947a..60e9f7e 100644 --- a/lib/Test.pm +++ b/lib/Test.pm @@ -2,9 +2,9 @@ use strict; package Test; use Test::Harness 1.1601 (); use Carp; -use vars (qw($VERSION @ISA @EXPORT @EXPORT_OK $ntest $TestLevel), #public-ish - qw($TESTOUT $ONFAIL %todo %history $planned @FAILDETAIL)); #private-ish -$VERSION = '1.121'; +our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $ntest, $TestLevel); #public-ish +our($TESTOUT, $ONFAIL, %todo, %history, $planned, @FAILDETAIL); #private-ish +$VERSION = '1.14'; require Exporter; @ISA=('Exporter'); @EXPORT=qw(&plan &ok &skip); @@ -63,7 +63,11 @@ sub ok ($;$$) { } else { $expected = to_value(shift); my ($regex,$ignore); - if ((ref($expected)||'') eq 're') { + if (!defined $expected) { + $ok = !defined $result; + } elsif (!defined $result) { + $ok = 0; + } elsif ((ref($expected)||'') eq 'Regexp') { $ok = $result =~ /$expected/; } elsif (($regex) = ($expected =~ m,^ / (.+) / $,sx) or ($ignore, $regex) = ($expected =~ m,^ m([^\w\s]) (.+) \1 $,sx)) { @@ -94,9 +98,10 @@ sub ok ($;$$) { } } else { my $prefix = "Test $ntest"; - print $TESTOUT "# $prefix got: '$result' ($context)\n"; + print $TESTOUT "# $prefix got: ". + (defined $result? "'$result'":'')." ($context)\n"; $prefix = ' ' x (length($prefix) - 5); - if ((ref($expected)||'') eq 're') { + if ((ref($expected)||'') eq 'Regexp') { $expected = 'qr/'.$expected.'/' } else { $expected = "'$expected'"; @@ -162,7 +167,7 @@ __END__ ok(sub { 1+1 }, 2); # success: '2' eq '2' ok(sub { 1+1 }, 3); # failure: '2' ne '3' - ok(0, int(rand(2)); # (just kidding! :-) + ok(0, int(rand(2)); # (just kidding :-) my @list = (0,0); ok @list, 3, "\@list=".join(',',@list); #extra diagnostics @@ -172,9 +177,9 @@ __END__ =head1 DESCRIPTION -L expects to see particular output when it executes -tests. This module aims to make writing proper test scripts just a -little bit easier (and less error prone :-). +L expects to see particular output when it +executes tests. This module aims to make writing proper test scripts just +a little bit easier (and less error prone :-). =head1 TEST TYPES @@ -220,7 +225,7 @@ triggered at the end of a test run. C is passed an array ref of hash refs that describe each test failure. Each hash will contain at least the following fields: C, C, and C. (The file, line, and test number are not included because -their correspondance to a particular test is tenuous.) If the test +their correspondence to a particular test is tenuous.) If the test had an expected value or a diagnostic string, these will also be included. @@ -239,7 +244,7 @@ L and, perhaps, test coverage analysis tools. =head1 AUTHOR -Copyright (C) 1998 Joshua Nathaniel Pritikin. All rights reserved. +Copyright (c) 1998-1999 Joshua Nathaniel Pritikin. All rights reserved. This package is free software and is provided "as is" without express or implied warranty. It may be used, redistributed and/or modified