develooper Front page | perl.perl5.porters | Postings from August 2001

[PATCH pod/perlhack.pod] Yet another improvement to the patching example

From:
Michael G Schwern
Date:
August 30, 2001 14:02
Subject:
[PATCH pod/perlhack.pod] Yet another improvement to the patching example
Message ID:
20010830170208.M2318@blackrider
This gives a simpler implementation of ok() that also includes
descriptive names.


--- pod/perlhack.pod	2001/08/28 13:54:34	1.1
+++ pod/perlhack.pod	2001/08/30 21:00:31
@@ -1481,13 +1481,12 @@
 
     my $test = 1;
     sub ok {
-        my($ok) = @_;
+        my($ok, $name) = @_;
 
         # You have to do it this way or VMS will get confused.
-        my $out = '';
-        $out =  "not " unless $ok;
-        $out .= "ok $test\n";
-        print $out;
+        print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";
+
+        printf "# Failed test at line %d\n", (caller)[2] unless $ok;
 
         $test++;
         return $ok;
@@ -1500,16 +1499,19 @@
 
 we can write the (somewhat) more sensible:
 
- ok( "1.20.300.4000" eq sprintf "%vd", pack("U*",1,20,300,4000) );
+ ok( "1.20.300.4000" eq sprintf "%vd", pack("U*",1,20,300,4000), 
+                                       "U* produces unicode" );
 
 Now we'll test that we got that space-at-the-beginning business right:
 
- ok( "1.20.300.4000" eq sprintf "%vd", pack("  U*",1,20,300,4000) );
+ ok( "1.20.300.4000" eq sprintf "%vd", pack("  U*",1,20,300,4000),
+                                       "  with spaces at the beginning" );
 
 And finally we'll test that we don't make Unicode strings if C<U> is B<not>
 the first active format:
 
- ok( v1.20.300.4000 ne  sprintf "%vd", pack("C0U*",1,20,300,4000) );
+ ok( v1.20.300.4000 ne  sprintf "%vd", pack("C0U*",1,20,300,4000),
+                                       "U* not first isn't unicode" );
 
 Mustn't forget to change the number of tests which appears at the top, or
 else the automated tester will get confused:


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
Well, my work here is done.  If you need me again, just admit that you're
screwed and die.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About