diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-08-12 10:33:09 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-08-12 10:33:09 +0100 |
commit | 44885db356d43ce046830669852738437e8ad2db (patch) | |
tree | 432517bc69441e09108a9d19efa51341a40688f8 /t | |
parent | 9e27fd7083290e0886c26e7c6c5e4a1e2cbceae3 (diff) | |
download | perl-44885db356d43ce046830669852738437e8ad2db.tar.gz |
Convert int.t to test.pl (and hence produce better failure diagnostics).
Diffstat (limited to 't')
-rw-r--r-- | t/op/int.t | 71 |
1 files changed, 21 insertions, 50 deletions
diff --git a/t/op/int.t b/t/op/int.t index e9596a39a0..6d3b5b496c 100644 --- a/t/op/int.t +++ b/t/op/int.t @@ -3,96 +3,67 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require './test.pl'; } -print "1..14\n"; +plan 15; # compile time evaluation -if (int(1.234) == 1) {print "ok 1\n";} else {print "not ok 1\n";} +if (int(1.234) == 1) {pass()} else {fail()} -if (int(-1.234) == -1) {print "ok 2\n";} else {print "not ok 2\n";} +if (int(-1.234) == -1) {pass()} else {fail()} # run time evaluation $x = 1.234; -if (int($x) == 1) {print "ok 3\n";} else {print "not ok 3\n";} -if (int(-$x) == -1) {print "ok 4\n";} else {print "not ok 4\n";} +cmp_ok(int($x), '==', 1); +cmp_ok(int(-$x), '==', -1); $x = length("abc") % -10; -print $x == -7 ? "ok 5\n" : "# expected -7, got $x\nnot ok 5\n"; +cmp_ok($x, '==', -7); { + my $fail; use integer; $x = length("abc") % -10; $y = (3/-10)*-10; - print $x+$y == 3 && abs($x) < 10 ? "ok 6\n" : "not ok 6\n"; + ok($x+$y == 3) or ++$fail; + ok(abs($x) < 10) or ++$fail; + if ($fail) { + diag("\$x == $x", "\$y == $y"); + } } -# check bad strings still get converted - @x = ( 6, 8, 10); -print "not " if $x["1foo"] != 8; -print "ok 7\n"; - -# check values > 32 bits work. +cmp_ok($x["1foo"], '==', 8, 'check bad strings still get converted'); $x = 4294967303.15; $y = int ($x); - -if ($y eq "4294967303") { - print "ok 8\n" -} else { - print "not ok 8 # int($x) is $y, not 4294967303\n" -} +is($y, "4294967303", 'check values > 32 bits work'); $y = int (-$x); -if ($y eq "-4294967303") { - print "ok 9\n" -} else { - print "not ok 9 # int($x) is $y, not -4294967303\n" -} +is($y, "-4294967303"); $x = 4294967294.2; $y = int ($x); -if ($y eq "4294967294") { - print "ok 10\n" -} else { - print "not ok 10 # int($x) is $y, not 4294967294\n" -} +is($y, "4294967294"); $x = 4294967295.7; $y = int ($x); -if ($y eq "4294967295") { - print "ok 11\n" -} else { - print "not ok 11 # int($x) is $y, not 4294967295\n" -} +is($y, "4294967295"); $x = 4294967296.11312; $y = int ($x); -if ($y eq "4294967296") { - print "ok 12\n" -} else { - print "not ok 12 # int($x) is $y, not 4294967296\n" -} +is($y, "4294967296"); $y = int(279964589018079/59); -if ($y == 4745162525730) { - print "ok 13\n" -} else { - print "not ok 13 # int(279964589018079/59) is $y, not 4745162525730\n" -} +cmp_ok($y, '==', 4745162525730); $y = 279964589018079; $y = int($y/59); -if ($y == 4745162525730) { - print "ok 14\n" -} else { - print "not ok 14 # int(279964589018079/59) is $y, not 4745162525730\n" -} - +cmp_ok($y, '==', 4745162525730); |