From: Nicholas Clark Date: Thu, 14 Apr 2011 17:23:23 +0000 (+0100) Subject: Use cmp_ok() in place of ok() with a < comparison, for better diagnostics. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c566e6ab8500795b29fd593e67aa8d6f1aa9b0b;p=p5sagit%2FDevel-Size.git Use cmp_ok() in place of ok() with a < comparison, for better diagnostics. Eliminate an unused lexical $tests. --- diff --git a/t/basic.t b/t/basic.t index f299f10..cc99c3a 100644 --- a/t/basic.t +++ b/t/basic.t @@ -3,8 +3,6 @@ use Test::More; use strict; -my $tests; - BEGIN { chdir 't' if -d 't'; @@ -35,8 +33,8 @@ $foo = "12"; my $x = "A string"; my $y = "A much much longer string"; # need to be at least 7 bytes longer for 64 bit -ok (size($x) < size($y), 'size() of strings'); -ok (total_size($x) < total_size($y), 'total_size() of strings'); +cmp_ok(size($x), '<', size($y), 'size() of strings'); +cmp_ok(total_size($x), '<', total_size($y), 'total_size() of strings'); my @x = (1..4); my @y = (1..200); @@ -44,7 +42,7 @@ my @y = (1..200); my $size_1 = total_size(\@x); my $size_2 = total_size(\@y); -ok ( $size_1 < $size_2, 'size() of array refs'); +cmp_ok($size_1, '<', $size_2, 'size() of array refs'); # the arrays alone shouldn't be the same size $size_1 = size(\@x); @@ -61,7 +59,7 @@ $y = 12; $y .= ''; $size_1 = size($x); $size_2 = size($y); -ok ($size_1 < $size_2, ' ."" makes string longer'); +cmp_ok($size_1, '<', $size_2, ' ."" makes string longer'); ############################################################################# # check that the tracking_hash is working diff --git a/t/recurse.t b/t/recurse.t index 845e825..00233b8 100644 --- a/t/recurse.t +++ b/t/recurse.t @@ -9,8 +9,6 @@ use Test::More; use strict; -my $tests; - BEGIN { chdir 't' if -d 't'; @@ -112,8 +110,8 @@ for my $size (2, 3, 7, 100) # Get the size of the PVNV and the contained array my $element_size = total_size(\$hash->{a}); - ok ($element_size < total_size($hash), "element < hash with one element"); - ok ($element_size > total_size(\[]), "PVNV + [] > [] alone"); + cmp_ok($element_size, '<', total_size($hash), "element < hash with one element"); + cmp_ok($element_size, '>', total_size(\[]), "PVNV + [] > [] alone"); # Dereferencing the PVNV (the argument to total_size) leaves us with # just the array, and this should be equal to a dereferenced array: @@ -138,7 +136,7 @@ for my $size (2, 3, 7, 100) # is a PVNV, so they shouldn't be the same: isnt (total_size(\[0..$size]), total_size( \$hash->{a} ), "[0..size] vs PVNV"); # and the plain ref should be smaller - ok (total_size(\[0..$size]) < total_size( \$hash->{a} ), "[0..size] vs. PVNV"); + cmp_ok(total_size(\[0..$size]), '<', total_size( \$hash->{a} ), "[0..size] vs. PVNV"); $full_hash = total_size($hash); $element_size = total_size(\$hash->{a});