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

Re: [perl #114532] Refactor t/op/arith.t to not make TAP by hand

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 29, 2012 12:38
Subject:
Re: [perl #114532] Refactor t/op/arith.t to not make TAP by hand
Message ID:
20120829193804.GH9583@plum.flirble.org
On Tue, Aug 21, 2012 at 08:56:25PM -0700, Colin Kuskie wrote:
> # New Ticket Created by  Colin Kuskie 
> # Please include the string:  [perl #114532]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=114532 >
> 
> 
> This transaction appears to have no content

> >From a60932634f1072209a5cd0aae601626eb2c35435 Mon Sep 17 00:00:00 2001
> From: Colin Kuskie <colink@perldreamer.com>
> Date: Tue, 21 Aug 2012 20:54:41 -0700
> Subject: [PATCH 11/11] Refactor t/op/arith.t to not make TAP by hand.
> 
> ---
>  t/op/arith.t |  435 +++++++++++++++++++++++++++-------------------------------
>  1 files changed, 204 insertions(+), 231 deletions(-)
> 
> diff --git a/t/op/arith.t b/t/op/arith.t
> index 8041276..76801be 100644
> --- a/t/op/arith.t
> +++ b/t/op/arith.t
> @@ -3,272 +3,246 @@
>  BEGIN {
>      chdir 't' if -d 't';
>      @INC = '../lib';
> +    require './test.pl';
>  }
>  
> -print "1..167\n";
> +plan tests => 167;
>  
> -sub try ($$) {
> -   print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
> -}
> -sub tryeq ($$$) {
> -  if ($_[1] == $_[2]) {
> -    print "ok $_[0]\n";
> -  } else {
> -    print "not ok $_[0] # $_[1] != $_[2]\n";
> -  }
> -}

> -my $T = 1;
> -tryeq $T++,  13 %  4, 1;
> -tryeq $T++, -13 %  4, 3;
> -tryeq $T++,  13 % -4, -3;
> -tryeq $T++, -13 % -4, -1;
> +within( 13 %  4, 1, 0, 'modulo, ++');
> +within(-13 %  4, 3, 0, '... -+');
> +within( 13 % -4, -3, 0, '... +-');
> +within(-13 % -4, -1, 0, '... --');

I had to look at this for a quite a while to be confident of what it's
actually testing. I think it would be better to use

  cmp_ok ( 13 %  4, '==', 1, 1);

etc for the exact tests, rather than within() with a tolerance of 0.

Whilst mathematically they are the same, cmp_ok() is far more common.

(Is that pretty much an editor macro to change?)

git also seemed to be warning that there was trailing whitespace added on
several lines. I would have squished that had I just been applying the patch.

Nicholas Clark

Thread Previous | Thread Next


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