Perl / perl5

šŸŖ The Perl programming language
https://dev.perl.org/perl5/
Other
1.99k stars 557 forks source link

t/op/arith.t: Convert to test.pl and add test descriptions #12589

Closed p5pRT closed 12 years ago

p5pRT commented 12 years ago

Migrated from rt.perl.org#115806 (status was 'resolved')

Searchable as RT115806$

p5pRT commented 12 years ago

From @jkeenan

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

140 of the 167 individual tests lacked descriptions. To a certain extent\, I composed descriptions from inline comments\, then removed those comments. I tried to make the test descriptions as unique as possible so that someone debugging a test failure could more easily locate the failure.

Since we presume that the tests were accurate to begin with\, in reviewing please first look for cases where the description is truly wrong\, and then look for cases where the description is capable of improvement.

I would like to be able to merge this into blead in 7 days. Thank you very much.

Jim Keenan

p5pRT commented 12 years ago

From @jkeenan

0013-Convert-t-op-arith.t-to-use-of-test.pl-functions.patch ```diff From c21641269f3af73ea6beb495b35c96f5a9e8a8fa Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Sun, 18 Nov 2012 10:44:10 -0600 Subject: [PATCH 13/13] Convert t/op/arith.t to use of test.pl functions. Add descriptions to all tests. --- t/op/arith.t | 537 ++++++++++++++++++++++++++++------------------------------ 1 files changed, 258 insertions(+), 279 deletions(-) diff --git a/t/op/arith.t b/t/op/arith.t index 8041276..8f14c92 100644 --- a/t/op/arith.t +++ b/t/op/arith.t @@ -3,51 +3,43 @@ 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"; - } -} -sub tryeq_sloppy ($$$) { - if ($_[1] == $_[2]) { - print "ok $_[0]\n"; - } else { - my $error = abs (($_[1] - $_[2]) / $_[1]); - if ($error < 1e-9) { - print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O\n"; - } else { - print "not ok $_[0] # $_[1] != $_[2]\n"; +sub sloppy_eq { + my ($got, $expected, $message) = @_; + my $result = 0; + if ($got == $expected) { + $result = 1; } - } + else { + my $error = abs (($got - $expected) / $got); + if ($error < 1e-9) { + $result = 1; + } + } + ok $result, $message; } -my $T = 1; -tryeq $T++, 13 % 4, 1; -tryeq $T++, -13 % 4, 3; -tryeq $T++, 13 % -4, -3; -tryeq $T++, -13 % -4, -1; +is 13 % 4, 1, 'modulo: positive positive'; +is -13 % 4, 3, 'modulo: negative positive'; +is 13 % -4, -3, 'modulo: positive negative'; +is -13 % -4, -1, 'modulo: negative negative'; # Give abs() a good work-out before using it in anger -tryeq $T++, abs(0), 0; -tryeq $T++, abs(1), 1; -tryeq $T++, abs(-1), 1; -tryeq $T++, abs(2147483647), 2147483647; -tryeq $T++, abs(-2147483647), 2147483647; -tryeq $T++, abs(4294967295), 4294967295; -tryeq $T++, abs(-4294967295), 4294967295; -tryeq $T++, abs(9223372036854775807), 9223372036854775807; -tryeq $T++, abs(-9223372036854775807), 9223372036854775807; -tryeq $T++, abs(1e50), 1e50; # Assume no change whatever; no slop needed -tryeq $T++, abs(-1e50), 1e50; # Assume only sign bit flipped +is abs(0), 0, 'abs(): 0 0'; +is abs(1), 1, 'abs(): 1 1'; +is abs(-1), 1, 'abs(): -1 1'; +is abs(2147483647), 2147483647, 'abs(): 2**31-1: pos pos'; +is abs(-2147483647), 2147483647, 'abs(): 2**31-1: neg pos'; +is abs(4294967295), 4294967295, 'abs(): 2**32-1: pos pos'; +is abs(-4294967295), 4294967295, 'abs(): 2**32-1: neg pos'; +is abs(9223372036854775807), 9223372036854775807, 'abs(): 2**63-1: pos pos'; +is abs(-9223372036854775807), 9223372036854775807, 'abs(): 2**63-1: neg pos'; +is abs(1e50), 1e50, 'abs(): 1e50: pos pos'; # Assume no change whatever; no slop needed +is abs(-1e50), 1e50, 'abs(): 1e50: neg pos'; # Assume only sign bit flipped my $limit = 1e6; @@ -55,220 +47,203 @@ my $limit = 1e6; # seem to be rather sloppy in Cray. $limit = 1e8 if $^O eq 'unicos'; -try $T++, abs( 13e21 % 4e21 - 1e21) < $limit; -try $T++, abs(-13e21 % 4e21 - 3e21) < $limit; -try $T++, abs( 13e21 % -4e21 - -3e21) < $limit; -try $T++, abs(-13e21 % -4e21 - -1e21) < $limit; - -# UVs should behave properly - -tryeq $T++, 4063328477 % 65535, 27407; -tryeq $T++, 4063328477 % 4063328476, 1; -tryeq $T++, 4063328477 % 2031664238, 1; -tryeq $T++, 2031664238 % 4063328477, 2031664238; - -# These should trigger wrapping on 32 bit IVs and UVs - -tryeq $T++, 2147483647 + 0, 2147483647; - -# IV + IV promote to UV -tryeq $T++, 2147483647 + 1, 2147483648; -tryeq $T++, 2147483640 + 10, 2147483650; -tryeq $T++, 2147483647 + 2147483647, 4294967294; -# IV + UV promote to NV -tryeq $T++, 2147483647 + 2147483649, 4294967296; -# UV + IV promote to NV -tryeq $T++, 4294967294 + 2, 4294967296; -# UV + UV promote to NV -tryeq $T++, 4294967295 + 4294967295, 8589934590; - -# UV + IV to IV -tryeq $T++, 2147483648 + -1, 2147483647; -tryeq $T++, 2147483650 + -10, 2147483640; -# IV + UV to IV -tryeq $T++, -1 + 2147483648, 2147483647; -tryeq $T++, -10 + 4294967294, 4294967284; -# IV + IV to NV -tryeq $T++, -2147483648 + -2147483648, -4294967296; -tryeq $T++, -2147483640 + -10, -2147483650; - -# Hmm. Don't forget the simple stuff -tryeq $T++, 1 + 1, 2; -tryeq $T++, 4 + -2, 2; -tryeq $T++, -10 + 100, 90; -tryeq $T++, -7 + -9, -16; -tryeq $T++, -63 + +2, -61; -tryeq $T++, 4 + -1, 3; -tryeq $T++, -1 + 1, 0; -tryeq $T++, +29 + -29, 0; -tryeq $T++, -1 + 4, 3; -tryeq $T++, +4 + -17, -13; +ok abs( 13e21 % 4e21 - 1e21) < $limit, 'abs() for floating point'; +ok abs(-13e21 % 4e21 - 3e21) < $limit, 'abs() for floating point'; +ok abs( 13e21 % -4e21 - -3e21) < $limit, 'abs() for floating point'; +ok abs(-13e21 % -4e21 - -1e21) < $limit, 'abs() for floating point'; + +is 4063328477 % 65535, 27407, 'UV behaves properly: modulo'; +is 4063328477 % 4063328476, 1, 'UV behaves properly: modulo'; +is 4063328477 % 2031664238, 1, 'UV behaves properly: modulo'; +is 2031664238 % 4063328477, 2031664238, 'UV behaves properly: modulo'; + +is 2147483647 + 0, 2147483647, 'trigger wrapping on 32 bit IVs and UVs'; + +is 2147483647 + 1, 2147483648, 'IV + IV promotes to UV'; +is 2147483640 + 10, 2147483650, 'IV + IV promotes to UV'; +is 2147483647 + 2147483647, 4294967294, 'IV + IV promotes to UV'; +is 2147483647 + 2147483649, 4294967296, 'IV + UV promotes to NV'; +is 4294967294 + 2, 4294967296, 'UV + IV promotes to NV'; +is 4294967295 + 4294967295, 8589934590, 'UV + UV promotes to NV'; + +is 2147483648 + -1, 2147483647, 'UV + IV promotes to IV'; +is 2147483650 + -10, 2147483640, 'UV + IV promotes to IV'; +is -1 + 2147483648, 2147483647, 'IV + UV promotes to IV'; +is -10 + 4294967294, 4294967284, 'IV + UV promotes to IV'; +is -2147483648 + -2147483648, -4294967296, 'IV + IV promotes to NV'; +is -2147483640 + -10, -2147483650, 'IV + IV promotes to NV'; + +# Hmm. Do not forget the simple stuff +is 1 + 1, 2, 'addition of 2 positive integers'; +is 4 + -2, 2, 'addition of positive and negative integer'; +is -10 + 100, 90, 'addition of negative and positive integer'; +is -7 + -9, -16, 'addition of 2 negative integers'; +is -63 + +2, -61, 'addition of signed negative and positive integers'; +is 4 + -1, 3, 'addition of positive and negative integer'; +is -1 + 1, 0, 'addition which sums to 0'; +is +29 + -29, 0, 'addition which sums to 0'; +is -1 + 4, 3, 'addition of signed negative and positive integers'; +is +4 + -17, -13, 'addition of signed positive and negative integers'; # subtraction -tryeq $T++, 3 - 1, 2; -tryeq $T++, 3 - 15, -12; -tryeq $T++, 3 - -7, 10; -tryeq $T++, -156 - 5, -161; -tryeq $T++, -156 - -5, -151; -tryeq $T++, -5 - -12, 7; -tryeq $T++, -3 - -3, 0; -tryeq $T++, 15 - 15, 0; - -tryeq $T++, 2147483647 - 0, 2147483647; -tryeq $T++, 2147483648 - 0, 2147483648; -tryeq $T++, -2147483648 - 0, -2147483648; - -tryeq $T++, 0 - -2147483647, 2147483647; -tryeq $T++, -1 - -2147483648, 2147483647; -tryeq $T++, 2 - -2147483648, 2147483650; - -tryeq $T++, 4294967294 - 3, 4294967291; -tryeq $T++, -2147483648 - -1, -2147483647; - -# IV - IV promote to UV -tryeq $T++, 2147483647 - -1, 2147483648; -tryeq $T++, 2147483647 - -2147483648, 4294967295; -# UV - IV promote to NV -tryeq $T++, 4294967294 - -3, 4294967297; -# IV - IV promote to NV -tryeq $T++, -2147483648 - +1, -2147483649; -# UV - UV promote to IV -tryeq $T++, 2147483648 - 2147483650, -2; -# IV - UV promote to IV -tryeq $T++, 2000000000 - 4000000000, -2000000000; +is 3 - 1, 2, 'subtraction of two positive integers'; +is 3 - 15, -12, 'subtraction of two positive integers: minuend smaller'; +is 3 - -7, 10, 'subtraction of positive and negative integer'; +is -156 - 5, -161, 'subtraction of negative and positive integer'; +is -156 - -5, -151, 'subtraction of two negative integers'; +is -5 - -12, 7, 'subtraction of two negative integers: minuend smaller'; +is -3 - -3, 0, 'subtraction of two negative integers with result of 0'; +is 15 - 15, 0, 'subtraction of two positive integers with result of 0'; + +is 2147483647 - 0, 2147483647, 'subtraction from large integer'; +is 2147483648 - 0, 2147483648, 'subtraction from large integer'; +is -2147483648 - 0, -2147483648, 'subtraction from large negative integer'; + +is 0 - -2147483647, 2147483647, 'subtraction of large negative integer from 0'; +is -1 - -2147483648, 2147483647, + 'subtraction of large negative integer from negative integer'; +is 2 - -2147483648, 2147483650, + 'subtraction of large negative integer from positive integer'; + +is 4294967294 - 3, 4294967291, 'subtraction from large integer'; +is -2147483648 - -1, -2147483647, 'subtraction from large negative integer'; + +is 2147483647 - -1, 2147483648, 'IV - IV promote to UV'; +is 2147483647 - -2147483648, 4294967295, 'IV - IV promote to UV'; +is 4294967294 - -3, 4294967297, 'UV - IV promote to NV'; +is -2147483648 - +1, -2147483649, 'IV - IV promote to NV'; +is 2147483648 - 2147483650, -2, 'UV - UV promote to IV'; +is 2000000000 - 4000000000, -2000000000, 'IV - UV promote to IV'; # No warnings should appear; -my $a; -$a += 1; -tryeq $T++, $a, 1; -undef $a; -$a += -1; -tryeq $T++, $a, -1; -undef $a; -$a += 4294967290; -tryeq $T++, $a, 4294967290; -undef $a; -$a += -4294967290; -tryeq $T++, $a, -4294967290; -undef $a; -$a += 4294967297; -tryeq $T++, $a, 4294967297; -undef $a; -$a += -4294967297; -tryeq $T++, $a, -4294967297; - -my $s; -$s -= 1; -tryeq $T++, $s, -1; -undef $s; -$s -= -1; -tryeq $T++, $s, +1; -undef $s; -$s -= -4294967290; -tryeq $T++, $s, +4294967290; -undef $s; -$s -= 4294967290; -tryeq $T++, $s, -4294967290; -undef $s; -$s -= 4294967297; -tryeq $T++, $s, -4294967297; -undef $s; -$s -= -4294967297; -tryeq $T++, $s, +4294967297; +{ my $a; $a += 1; is $a, 1, '+= with positive'; } +{ my $a; $a += -1; is $a, -1, '+= with negative'; } +{ my $a; $a += 4294967290; is $a, 4294967290, '+= with positive'; } +{ my $a; $a += -4294967290; is $a, -4294967290, '+= with negative'; } +{ my $a; $a += 4294967297; is $a, 4294967297, '+= with positive'; } +{ my $a; $a += -4294967297; is $a, -4294967297, '+= with negative'; } + +{ my $s; $s -= 1; is $s, -1, '-= with positive'; } +{ my $s; $s -= -1; is $s, +1, '-= with negative'; } +{ my $s; $s -= -4294967290; is $s, +4294967290, '-= with negative'; } +{ my $s; $s -= 4294967290; is $s, -4294967290, '-= with negative'; } +{ my $s; $s -= 4294967297; is $s, -4294967297, '-= with positive'; } +{ my $s; $s -= -4294967297; is $s, +4294967297, '-= with positive'; } # Multiplication -tryeq $T++, 1 * 3, 3; -tryeq $T++, -2 * 3, -6; -tryeq $T++, 3 * -3, -9; -tryeq $T++, -4 * -3, 12; +is 1 * 3, 3, 'multiplication of two positive integers'; +is -2 * 3, -6, 'multiplication of negative and positive integer'; +is 3 * -3, -9, 'multiplication of positive and negative integer';; +is -4 * -3, 12, 'multiplication of two negative integers'; # check with 0xFFFF and 0xFFFF -tryeq $T++, 65535 * 65535, 4294836225; -tryeq $T++, 65535 * -65535, -4294836225; -tryeq $T++, -65535 * 65535, -4294836225; -tryeq $T++, -65535 * -65535, 4294836225; +is 65535 * 65535, 4294836225, 'multiplication: 0xFFFF and 0xFFFF: pos pos'; +is 65535 * -65535, -4294836225, 'multiplication: 0xFFFF and 0xFFFF: pos neg'; +is -65535 * 65535, -4294836225, 'multiplication: 0xFFFF and 0xFFFF: pos neg'; +is -65535 * -65535, 4294836225, 'multiplication: 0xFFFF and 0xFFFF: neg neg'; # check with 0xFFFF and 0x10001 -tryeq $T++, 65535 * 65537, 4294967295; -tryeq $T++, 65535 * -65537, -4294967295; -tryeq $T++, -65535 * 65537, -4294967295; -tryeq $T++, -65535 * -65537, 4294967295; +is 65535 * 65537, 4294967295, 'multiplication: 0xFFFF and 0x10001: pos pos'; +is 65535 * -65537, -4294967295, 'multiplication: 0xFFFF and 0x10001: pos neg'; +is -65535 * 65537, -4294967295, 'multiplication: 0xFFFF and 0x10001: neg pos'; +is -65535 * -65537, 4294967295, 'multiplication: 0xFFFF and 0x10001: neg neg'; # check with 0x10001 and 0xFFFF -tryeq $T++, 65537 * 65535, 4294967295; -tryeq $T++, 65537 * -65535, -4294967295; -tryeq $T++, -65537 * 65535, -4294967295; -tryeq $T++, -65537 * -65535, 4294967295; +is 65537 * 65535, 4294967295, 'multiplication: 0x10001 and 0xFFFF: pos pos'; +is 65537 * -65535, -4294967295, 'multiplication: 0x10001 and 0xFFFF: pos neg'; +is -65537 * 65535, -4294967295, 'multiplication: 0x10001 and 0xFFFF: neg pos'; +is -65537 * -65535, 4294967295, 'multiplication: 0x10001 and 0xFFFF: neg neg'; # These should all be dones as NVs -tryeq $T++, 65537 * 65537, 4295098369; -tryeq $T++, 65537 * -65537, -4295098369; -tryeq $T++, -65537 * 65537, -4295098369; -tryeq $T++, -65537 * -65537, 4295098369; +is 65537 * 65537, 4295098369, 'multiplication: NV: pos pos'; +is 65537 * -65537, -4295098369, 'multiplication: NV: pos neg'; +is -65537 * 65537, -4295098369, 'multiplication: NV: neg pos'; +is -65537 * -65537, 4295098369, 'multiplication: NV: neg neg'; # will overflow an IV (in 32-bit) -tryeq $T++, 46340 * 46342, 0x80001218; -tryeq $T++, 46340 * -46342, -0x80001218; -tryeq $T++, -46340 * 46342, -0x80001218; -tryeq $T++, -46340 * -46342, 0x80001218; - -tryeq $T++, 46342 * 46340, 0x80001218; -tryeq $T++, 46342 * -46340, -0x80001218; -tryeq $T++, -46342 * 46340, -0x80001218; -tryeq $T++, -46342 * -46340, 0x80001218; +is 46340 * 46342, 0x80001218, + 'multiplication: overflow an IV in 32-bit: pos pos'; +is 46340 * -46342, -0x80001218, + 'multiplication: overflow an IV in 32-bit: pos neg'; +is -46340 * 46342, -0x80001218, + 'multiplication: overflow an IV in 32-bit: neg pos'; +is -46340 * -46342, 0x80001218, + 'multiplication: overflow an IV in 32-bit: neg neg'; + +is 46342 * 46340, 0x80001218, + 'multiplication: overflow an IV in 32-bit: pos pos'; +is 46342 * -46340, -0x80001218, + 'multiplication: overflow an IV in 32-bit: pos neg'; +is -46342 * 46340, -0x80001218, + 'multiplication: overflow an IV in 32-bit: neg pos'; +is -46342 * -46340, 0x80001218, + 'multiplication: overflow an IV in 32-bit: neg neg'; # will overflow a positive IV (in 32-bit) -tryeq $T++, 65536 * 32768, 0x80000000; -tryeq $T++, 65536 * -32768, -0x80000000; -tryeq $T++, -65536 * 32768, -0x80000000; -tryeq $T++, -65536 * -32768, 0x80000000; - -tryeq $T++, 32768 * 65536, 0x80000000; -tryeq $T++, 32768 * -65536, -0x80000000; -tryeq $T++, -32768 * 65536, -0x80000000; -tryeq $T++, -32768 * -65536, 0x80000000; +is 65536 * 32768, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos pos'; +is 65536 * -32768, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos neg'; +is -65536 * 32768, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg pos'; +is -65536 * -32768, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg neg'; + +is 32768 * 65536, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos pos'; +is 32768 * -65536, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos neg'; +is -32768 * 65536, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg pos'; +is -32768 * -65536, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg neg'; # 2147483647 is prime. bah. -tryeq $T++, 46339 * 46341, 0x7ffea80f; -tryeq $T++, 46339 * -46341, -0x7ffea80f; -tryeq $T++, -46339 * 46341, -0x7ffea80f; -tryeq $T++, -46339 * -46341, 0x7ffea80f; +is 46339 * 46341, 0x7ffea80f, 'multiplication: hex product: pos pos'; +is 46339 * -46341, -0x7ffea80f, 'multiplication: hex product: pos neg'; +is -46339 * 46341, -0x7ffea80f, 'multiplication: hex product: neg pos'; +is -46339 * -46341, 0x7ffea80f, 'multiplication: hex product: neg neg'; # leading space should be ignored -tryeq $T++, 1 + " 1", 2; -tryeq $T++, 3 + " -1", 2; -tryeq $T++, 1.2, " 1.2"; -tryeq $T++, -1.2, " -1.2"; +is 1 + " 1", 2, 'ignore leading space: addition'; +is 3 + " -1", 2, 'ignore leading space: subtraction'; +is 1.2, "1.2", 'floating point and string equivalent: positive'; +is -1.2, "-1.2", 'floating point and string equivalent: negative'; # divide -tryeq $T++, 28/14, 2; -tryeq $T++, 28/-7, -4; -tryeq $T++, -28/4, -7; -tryeq $T++, -28/-2, 14; +is 28/14, 2, 'division of two positive integers'; +is 28/-7, -4, 'division of positive integer by negative'; +is -28/4, -7, 'division of negative integer by positive'; +is -28/-2, 14, 'division of negative integer by negative'; -tryeq $T++, 0x80000000/1, 0x80000000; -tryeq $T++, 0x80000000/-1, -0x80000000; -tryeq $T++, -0x80000000/1, -0x80000000; -tryeq $T++, -0x80000000/-1, 0x80000000; +is 0x80000000/1, 0x80000000, 'division of positive hex by positive integer'; +is 0x80000000/-1, -0x80000000, 'division of positive hex by negative integer'; +is -0x80000000/1, -0x80000000, 'division of negative hex by negative integer'; +is -0x80000000/-1, 0x80000000, 'division of negative hex by positive integer'; # The example for sloppy divide, rigged to avoid the peephole optimiser. -tryeq_sloppy $T++, "20." / "5.", 4; +sloppy_eq "20." / "5.", 4, + 'division of floating point without fractional part'; -tryeq $T++, 2.5 / 2, 1.25; -tryeq $T++, 3.5 / -2, -1.75; -tryeq $T++, -4.5 / 2, -2.25; -tryeq $T++, -5.5 / -2, 2.75; +is 2.5 / 2, 1.25, 'division of positive floating point by positive integer'; +is 3.5 / -2, -1.75, 'division of positive floating point by negative integer'; +is -4.5 / 2, -2.25, 'division of negative floating point by positive integer'; +is -5.5 / -2, 2.75, 'division of negative floating point by negative integer'; -# Bluuurg if your floating point can't accurately cope with powers of 2 +# Bluuurg if your floating point can not accurately cope with powers of 2 # [I suspect this is parsing string->float problems, not actual arith] -tryeq_sloppy $T++, 18446744073709551616/1, 18446744073709551616; # Bluuurg -tryeq_sloppy $T++, 18446744073709551616/2, 9223372036854775808; -tryeq_sloppy $T++, 18446744073709551616/4294967296, 4294967296; -tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; +sloppy_eq 18446744073709551616/1, 18446744073709551616, + 'division of very large number by 1'; # Bluuurg +sloppy_eq 18446744073709551616/2, 9223372036854775808, + 'division of very large number by 2'; +sloppy_eq 18446744073709551616/4294967296, 4294967296, + 'division of two very large numbers'; +sloppy_eq 18446744073709551616/9223372036854775808, 2, + 'division of two very large numbers'; { # The peephole optimiser is wrong to think that it can substitute intops @@ -277,27 +252,27 @@ tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; my $n = 1127; my $float = ($n % 1000) * 167772160.0; - tryeq_sloppy $T++, $float, 21307064320; + sloppy_eq $float, 21307064320, 'integer times floating point'; # On a 32 bit machine, if the i_multiply op is used, you will probably get - # -167772160. It's actually undefined behaviour, so anything may happen. + # -167772160. It is actually undefined behaviour, so anything may happen. my $int = ($n % 1000) * 167772160; - tryeq $T++, $int, 21307064320; + is $int, 21307064320, 'integer times integer'; my $float2 = ($n % 1000 + 0.0) * 167772160; - tryeq $T++, $float2, 21307064320; + is $float2, 21307064320, 'floating point times integer'; my $int2 = ($n % 1000 + 0) * 167772160; - tryeq $T++, $int2, 21307064320; + is $int2, 21307064320, 'integer plus zero times integer'; # zero, but in a way that ought to be able to defeat any future optimizer: my $zero = $$ - $$; my $int3 = ($n % 1000 + $zero) * 167772160; - tryeq $T++, $int3, 21307064320; + is $int3, 21307064320, 'defeat any future optimizer'; my $t = time; my $t1000 = time() * 1000; - try $T++, abs($t1000 -1000 * $t) <= 2000; + ok abs($t1000 -1000 * $t) <= 2000, 'absolute value'; } { @@ -305,106 +280,110 @@ tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; my $n = 1127; my $float = ($n % 1000) * 720575940379279360.0; - tryeq_sloppy $T++, $float, 9.15131444281685e+19; + sloppy_eq $float, 9.15131444281685e+19, + '64 bit: integer times floating point'; my $int = ($n % 1000) * 720575940379279360; - tryeq_sloppy $T++, $int, 9.15131444281685e+19; + sloppy_eq $int, 9.15131444281685e+19, + '64 bit: integer times integer'; my $float2 = ($n % 1000 + 0.0) * 720575940379279360; - tryeq_sloppy $T++, $float2, 9.15131444281685e+19; + sloppy_eq $float2, 9.15131444281685e+19, + '64 bit: floating point times integer'; my $int2 = ($n % 1000 + 0) * 720575940379279360; - tryeq_sloppy $T++, $int2, 9.15131444281685e+19; + sloppy_eq $int2, 9.15131444281685e+19, + '64 bit: integer plus zero times integer'; # zero, but in a way that ought to be able to defeat any future optimizer: my $zero = $$ - $$; my $int3 = ($n % 1000 + $zero) * 720575940379279360; - tryeq_sloppy $T++, $int3, 9.15131444281685e+19; -} - -my $vms_no_ieee; -if ($^O eq 'VMS') { - use vars '%Config'; - eval {require Config; import Config}; - $vms_no_ieee = 1 unless defined($Config{useieee}); -} - -if ($^O eq 'vos') { - print "not ok ", $T++, " # TODO VOS raises SIGFPE instead of producing infinity.\n"; -} -elsif ($vms_no_ieee) { - print $T++, " # SKIP -- the IEEE infinity model is unavailable in this configuration.\n" -} -elsif ($^O eq 'ultrix') { - print "not ok ", $T++, " # TODO Ultrix enters deep nirvana instead of producing infinity.\n"; -} -else { - # The computation of $v should overflow and produce "infinity" - # on any system whose max exponent is less than 10**1506. - # The exact string used to represent infinity varies by OS, - # so we don't test for it; all we care is that we don't die. - # - # Perl considers it to be an error if SIGFPE is raised. - # Chances are the interpreter will die, since it doesn't set - # up a handler for SIGFPE. That's why this test is last; to - # minimize the number of test failures. --PG - - my $n = 5000; - my $v = 2; - while (--$n) - { - $v *= 2; - } - print "ok ", $T++, "\n"; + sloppy_eq $int3, 9.15131444281685e+19, + '64 bit: defeat any future optimizer'; } # [perl #109542] $1 and "$1" should be treated the same way "976562500000000" =~ /(\d+)/; $a = ($1 * 1024); $b = ("$1" * 1024); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" * something\n'; +is $a, $b, qq{\$1 vs "\$1" * something} . ': RT 109542'; $a = (1024 * $1); $b = (1024 * "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something * \$1 vs "\$1"\n'; +is $a, $b, qq{something * \$1 vs "\$1"} . ': RT 109542'; $a = ($1 + 102400000000000); $b = ("$1" + 102400000000000); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" + something\n'; +is $a, $b, qq{\$1 vs "\$1" + something} . ': RT 109542'; $a = (102400000000000 + $1); $b = (102400000000000 + "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something + \$1 vs "\$1"\n'; +is $a, $b, qq{something + \$1 vs "\$1"} . ': RT 109542'; $a = ($1 - 10240000000000000); $b = ("$1" - 10240000000000000); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" - something\n'; +is $a, $b, qq{\$1 vs "\$1" - something} . ': RT 109542'; $a = (10240000000000000 - $1); $b = (10240000000000000 - "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something - \$1 vs "\$1"\n'; +is $a, $b, qq{something - \$1 vs "\$1"} . ': RT 109542'; "976562500" =~ /(\d+)/; $a = ($1 ** 2); $b = ("$1" ** 2); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" ** something\n'; +is $a, $b, qq{\$1 vs "\$1" ** something} . ': RT 109542'; "32" =~ /(\d+)/; $a = (3 ** $1); $b = (3 ** "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something ** \$1 vs "\$1"\n'; +is $a, $b, qq{something ** \$1 vs "\$1"} . ': RT 109542'; "97656250000000000" =~ /(\d+)/; $a = ($1 / 10); $b = ("$1" / 10); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" / something\n'; +is $a, $b, qq{\$1 vs "\$1" / something} . ': RT 109542'; "10" =~ /(\d+)/; $a = (97656250000000000 / $1); $b = (97656250000000000 / "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something / \$1 vs "\$1"\n'; +is $a, $b, qq{something / \$1 vs "\$1"} . ': RT 109542'; "97656250000000000" =~ /(\d+)/; $a = ($1 <=> 97656250000000001); $b = ("$1" <=> 97656250000000001); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" <=> something\n'; +is $a, $b, qq{\$1 vs "\$1" <=> something} . ': RT 109542'; $a = (97656250000000001 <=> $1); $b = (97656250000000001 <=> "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something <=> \$1 vs "\$1"\n'; +is $a, $b, qq{something <=> \$1 vs "\$1"} . ': RT 109542'; "97656250000000001" =~ /(\d+)/; $a = ($1 % 97656250000000002); $b = ("$1" % 97656250000000002); -print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" % something\n'; +is $a, $b, qq{\$1 vs "\$1" % something} . ': RT 109542'; $a = (97656250000000000 % $1); $b = (97656250000000000 % "$1"); -print "not "x($a ne $b), "ok ", $T++, qq ' - something % \$1 vs "\$1"\n'; +is $a, $b, qq{something % \$1 vs "\$1"} . ': RT 109542'; + +my $vms_no_ieee; +if ($^O eq 'VMS') { + use vars '%Config'; + eval {require Config; import Config}; + $vms_no_ieee = 1 unless defined($Config{useieee}); +} + +TODO: { + todo_skip( 'VOS raises SIGFPE instead of producing infinity.' ) + if $^O eq 'vos'; + todo_skip( 'the IEEE infinity model is unavailable in this configuration.' ) + if $vms_no_ieee; + todo_skip( 'Ultrix enters deep nirvana instead of producing infinity.' ) + if $^O eq 'ultrix'; + + # The computation of $v should overflow and produce "infinity" + # on any system whose max exponent is less than 10**1506. + # The exact string used to represent infinity varies by OS, + # so we do not test for it; all we care is that we does not die. + # + # Perl considers it to be an error if SIGFPE is raised. + # Chances are the interpreter will die, since it does not set + # up a handler for SIGFPE. That is why this test is last; to + # minimize the number of test failures. --PG + + my $n = 5000; + my $v = 2; + while (--$n) + { + $v *= 2; + } + pass('infinity'); +} + -- 1.6.3.2 ```
p5pRT commented 12 years ago

From @b2gills

On Sun\, Nov 18\, 2012 at 11​:49 AM\, James E Keenan \perlbug\-followup@&#8203;perl\.org wrote​:

# New Ticket Created by James E Keenan # Please include the string​: [perl #115806] # in the subject line of all future correspondence about this issue. # \<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=115806 >

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

140 of the 167 individual tests lacked descriptions. To a certain extent\, I composed descriptions from inline comments\, then removed those comments. I tried to make the test descriptions as unique as possible so that someone debugging a test failure could more easily locate the failure.

Since we presume that the tests were accurate to begin with\, in reviewing please first look for cases where the description is truly wrong\, and then look for cases where the description is capable of improvement.

I would like to be able to merge this into blead in 7 days. Thank you very much.

Jim Keenan

If you (temporarily) increment $Level in sloppy_eq() then the line numbers in "not ok" messages will be more helpful.

sub sloppy_eq {   my ($got\, $expected\, $message) = @​_;   my $result = 0;   if ($got == $expected) {   $result = 1;   }   else {   my $error = abs (($got - $expected) / $got);   if ($error \< 1e-9) {   $result = 1;   }   } + local $Level = $Level + 1;   ok $result\, $message; }

p5pRT commented 12 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 12 years ago

From @cpansprout

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

--

Father Chrysostomos

p5pRT commented 12 years ago

From @jkeenan

On Sun Nov 18 11​:02​:39 2012\, sprout wrote​:

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

We were following the guidance provided by this passage in pod/perlhack.pod​:

##### =item * F\<t/cmd>\, F\<t/run>\, F\<t/io> and F\<t/op> Now that basic require() and subroutines are tested\, you can use the F\<t/test.pl> library.

You can also use certain libraries like Config conditionally\, but be sure to skip the test gracefully if it's not there. #####

I infer from what you say that this guidance is wrong. If so\, can you please provide a patch ASAP that correctly describes when we can use 't/test.pl'? Otherwise\, people whom we are trying to introduce to the Perl 5 core distribution will have their patches rejected and be discouraged from making further contributions.

Thank you very much. Jim Keenan

p5pRT commented 12 years ago

From @cpansprout

On Sun Nov 18 18​:34​:04 2012\, jkeenan wrote​:

On Sun Nov 18 11​:02​:39 2012\, sprout wrote​:

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

We were following the guidance provided by this passage in pod/perlhack.pod​:

##### =item * F\<t/cmd>\, F\<t/run>\, F\<t/io> and F\<t/op> Now that basic require() and subroutines are tested\, you can use the F\<t/test.pl> library.

You can also use certain libraries like Config conditionally\, but be sure to skip the test gracefully if it's not there. #####

I infer from what you say that this guidance is wrong. If so\, can you please provide a patch ASAP that correctly describes when we can use 't/test.pl'? Otherwise\, people whom we are trying to introduce to the Perl 5 core distribution will have their patches rejected and be discouraged from making further contributions.

I have patched it in commit b1b0854bd000.

--

Father Chrysostomos

p5pRT commented 12 years ago

From @jkeenan

On Sun Nov 18 20​:20​:29 2012\, sprout wrote​:

On Sun Nov 18 18​:34​:04 2012\, jkeenan wrote​:

On Sun Nov 18 11​:02​:39 2012\, sprout wrote​:

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

We were following the guidance provided by this passage in pod/perlhack.pod​:

##### =item * F\<t/cmd>\, F\<t/run>\, F\<t/io> and F\<t/op> Now that basic require() and subroutines are tested\, you can use the F\<t/test.pl> library.

You can also use certain libraries like Config conditionally\, but be sure to skip the test gracefully if it's not there. #####

I infer from what you say that this guidance is wrong. If so\, can you please provide a patch ASAP that correctly describes when we can use 't/test.pl'? Otherwise\, people whom we are trying to introduce to the Perl 5 core distribution will have their patches rejected and be discouraged from making further contributions.

I have patched it in commit b1b0854bd000.

Father C​:

While I thank you for your quick response\, I don't think the patch clarifies matters sufficiently​:

Inline Patch ```diff diff --git a/pod/perlhack.pod b/pod/perlhack.pod index 64329ed..9f2513f 100644 --- a/pod/perlhack.pod +++ b/pod/perlhack.pod @@ -713,6 +713,9 @@ tested. Now that basic require() and subroutines are tested, you can use the F library. +Note, however, that some test scripts still avoid F if they make +use of features that F relies on heavily. + ```

This means that the would-be test writer must first conduct a study of t/test.pl and list all the Perl features it uses\, then inspect the particular test file to see whether it avoids those features.

When I opened up t/op/arith.t this weekend\, there were no comments or POD in it to indicate that it could not be tested with t/test.pl. And its placement in t/op/ indicated that it could be so tested.

If there are files such as t/op/arith.t that currently sit in a directory listed as testable by t/test.pl which are not\, in fact\, so testable\, then let's move them into another directory or to one already listed as requiring hard-coded tests only. That way\, the would-be test description writer doesn't have to get bogged down in an analysis of the theoretical limits of t/test.pl.

Thank you very much. Jim Keenan

p5pRT commented 12 years ago

From @cpansprout

On Mon Nov 19 05​:08​:26 2012\, jkeenan wrote​:

Father C​:

While I thank you for your quick response\, I don't think the patch clarifies matters sufficiently​:

diff --git a/pod/perlhack.pod b/pod/perlhack.pod index 64329ed..9f2513f 100644 --- a/pod/perlhack.pod +++ b/pod/perlhack.pod @​@​ -713\,6 +713\,9 @​@​ tested. Now that basic require() and subroutines are tested\, you can use the F\<t/test.pl> library.

+Note\, however\, that some test scripts still avoid F\<t/test.pl> if they make +use of features that F\<t/test.pl> relies on heavily. +

This means that the would-be test writer must first conduct a study of t/test.pl and list all the Perl features it uses\, then inspect the particular test file to see whether it avoids those features.

When I opened up t/op/arith.t this weekend\, there were no comments or POD in it to indicate that it could not be tested with t/test.pl. And its placement in t/op/ indicated that it could be so tested.

If there are files such as t/op/arith.t that currently sit in a directory listed as testable by t/test.pl which are not\, in fact\, so testable\, then let's move them into another directory or to one already listed as requiring hard-coded tests only.

I would not be opposed to that. I hope you are not expected me to do it\, though. :-)

I do think you are reading too much into what perlhack says. test.pl may be OK to use in op/\, but that does not mean that everything in there must use it.

Still\, separation into different directories does not sound like a bad idea.

That way\, the would-be test description writer doesn't have to get bogged down in an analysis of the theoretical limits of t/test.pl.

--

Father Chrysostomos

p5pRT commented 12 years ago

From @jkeenan

On Mon Nov 19 08​:47​:17 2012\, sprout wrote​:

I do think you are reading too much into what perlhack says. test.pl may be OK to use in op/\, but that does not mean that everything in there must use it.

Still\, separation into different directories does not sound like a bad idea.

I have created https://rt-archive.perl.org/perl5/Ticket/Display.html?id=115838 to address the general issue. Have you seen that yet?

Thank you very much. Jim Keenan

p5pRT commented 12 years ago

From @jkeenan

On Sun Nov 18 11​:02​:39 2012\, sprout wrote​:

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

I am attaching a patch which *substitutes* for the patch previously attached to this RT. Father C\, I believe it should satisfy your concerns.

Please review (anyone\, not just Father C)\, as we had to write descriptions for 140 out of 167 individual tests in this file.

Thank you very much. Jim Keenan

p5pRT commented 12 years ago

From @jkeenan

0003-Add-descriptions-to-tests-in-t-op-arith.t.patch ```diff From 6926ed9bf743623556ca0942b5e78637be9bcb1f Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Fri, 23 Nov 2012 14:20:56 -0500 Subject: [PATCH 3/3] Add descriptions to tests in t/op/arith.t. --- t/op/arith.t | 514 +++++++++++++++++++++++++++++++--------------------------- 1 files changed, 279 insertions(+), 235 deletions(-) diff --git a/t/op/arith.t b/t/op/arith.t index 8041276..3c91971 100644 --- a/t/op/arith.t +++ b/t/op/arith.t @@ -7,47 +7,53 @@ BEGIN { print "1..167\n"; -sub try ($$) { - print +($_[1] ? "ok" : "not ok"), " $_[0]\n"; +sub try ($$$) { + print +($_[1] ? "ok" : "not ok"), " $_[0] - $_[2]\n"; } -sub tryeq ($$$) { +sub tryeq ($$$$) { if ($_[1] == $_[2]) { - print "ok $_[0]\n"; + print "ok $_[0]"; } else { - print "not ok $_[0] # $_[1] != $_[2]\n"; + print "not ok $_[0] # $_[1] != $_[2]"; } + print " - $_[3]\n"; } -sub tryeq_sloppy ($$$) { +sub tryeq_sloppy ($$$$) { if ($_[1] == $_[2]) { - print "ok $_[0]\n"; + print "ok $_[0]"; } else { my $error = abs (($_[1] - $_[2]) / $_[1]); if ($error < 1e-9) { - print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O\n"; + print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O"; } else { - print "not ok $_[0] # $_[1] != $_[2]\n"; + print "not ok $_[0] # $_[1] != $_[2]"; } } + print " - $_[3]\n"; } my $T = 1; -tryeq $T++, 13 % 4, 1; -tryeq $T++, -13 % 4, 3; -tryeq $T++, 13 % -4, -3; -tryeq $T++, -13 % -4, -1; +tryeq $T++, 13 % 4, 1, 'modulo: positive positive'; +tryeq $T++, -13 % 4, 3, 'modulo: negative positive'; +tryeq $T++, 13 % -4, -3, 'modulo: positive negative'; +tryeq $T++, -13 % -4, -1, 'modulo: negative negative'; # Give abs() a good work-out before using it in anger -tryeq $T++, abs(0), 0; -tryeq $T++, abs(1), 1; -tryeq $T++, abs(-1), 1; -tryeq $T++, abs(2147483647), 2147483647; -tryeq $T++, abs(-2147483647), 2147483647; -tryeq $T++, abs(4294967295), 4294967295; -tryeq $T++, abs(-4294967295), 4294967295; -tryeq $T++, abs(9223372036854775807), 9223372036854775807; -tryeq $T++, abs(-9223372036854775807), 9223372036854775807; -tryeq $T++, abs(1e50), 1e50; # Assume no change whatever; no slop needed -tryeq $T++, abs(-1e50), 1e50; # Assume only sign bit flipped +tryeq $T++, abs(0), 0, 'abs(): 0 0'; +tryeq $T++, abs(1), 1, 'abs(): 1 1'; +tryeq $T++, abs(-1), 1, 'abs(): -1 1'; +tryeq $T++, abs(2147483647), 2147483647, 'abs(): 2**31-1: pos pos'; +tryeq $T++, abs(-2147483647), 2147483647, 'abs(): 2**31-1: neg pos'; +tryeq $T++, abs(4294967295), 4294967295, 'abs(): 2**32-1: pos pos'; +tryeq $T++, abs(-4294967295), 4294967295, 'abs(): 2**32-1: neg pos'; +tryeq $T++, abs(9223372036854775807), 9223372036854775807, + 'abs(): 2**63-1: pos pos'; +tryeq $T++, abs(-9223372036854775807), 9223372036854775807, + 'abs(): 2**63-1: neg pos'; +# Assume no change whatever; no slop needed +tryeq $T++, abs(1e50), 1e50, 'abs(): 1e50: pos pos'; +# Assume only sign bit flipped +tryeq $T++, abs(-1e50), 1e50, 'abs(): 1e50: neg pos'; my $limit = 1e6; @@ -55,220 +61,252 @@ my $limit = 1e6; # seem to be rather sloppy in Cray. $limit = 1e8 if $^O eq 'unicos'; -try $T++, abs( 13e21 % 4e21 - 1e21) < $limit; -try $T++, abs(-13e21 % 4e21 - 3e21) < $limit; -try $T++, abs( 13e21 % -4e21 - -3e21) < $limit; -try $T++, abs(-13e21 % -4e21 - -1e21) < $limit; - -# UVs should behave properly - -tryeq $T++, 4063328477 % 65535, 27407; -tryeq $T++, 4063328477 % 4063328476, 1; -tryeq $T++, 4063328477 % 2031664238, 1; -tryeq $T++, 2031664238 % 4063328477, 2031664238; - -# These should trigger wrapping on 32 bit IVs and UVs - -tryeq $T++, 2147483647 + 0, 2147483647; - -# IV + IV promote to UV -tryeq $T++, 2147483647 + 1, 2147483648; -tryeq $T++, 2147483640 + 10, 2147483650; -tryeq $T++, 2147483647 + 2147483647, 4294967294; -# IV + UV promote to NV -tryeq $T++, 2147483647 + 2147483649, 4294967296; -# UV + IV promote to NV -tryeq $T++, 4294967294 + 2, 4294967296; -# UV + UV promote to NV -tryeq $T++, 4294967295 + 4294967295, 8589934590; - -# UV + IV to IV -tryeq $T++, 2147483648 + -1, 2147483647; -tryeq $T++, 2147483650 + -10, 2147483640; -# IV + UV to IV -tryeq $T++, -1 + 2147483648, 2147483647; -tryeq $T++, -10 + 4294967294, 4294967284; -# IV + IV to NV -tryeq $T++, -2147483648 + -2147483648, -4294967296; -tryeq $T++, -2147483640 + -10, -2147483650; - -# Hmm. Don't forget the simple stuff -tryeq $T++, 1 + 1, 2; -tryeq $T++, 4 + -2, 2; -tryeq $T++, -10 + 100, 90; -tryeq $T++, -7 + -9, -16; -tryeq $T++, -63 + +2, -61; -tryeq $T++, 4 + -1, 3; -tryeq $T++, -1 + 1, 0; -tryeq $T++, +29 + -29, 0; -tryeq $T++, -1 + 4, 3; -tryeq $T++, +4 + -17, -13; +try $T++, abs( 13e21 % 4e21 - 1e21) < $limit, 'abs() for floating point'; +try $T++, abs(-13e21 % 4e21 - 3e21) < $limit, 'abs() for floating point'; +try $T++, abs( 13e21 % -4e21 - -3e21) < $limit, 'abs() for floating point'; +try $T++, abs(-13e21 % -4e21 - -1e21) < $limit, 'abs() for floating point'; + +tryeq $T++, 4063328477 % 65535, 27407, 'UV behaves properly: modulo'; +tryeq $T++, 4063328477 % 4063328476, 1, 'UV behaves properly: modulo'; +tryeq $T++, 4063328477 % 2031664238, 1, 'UV behaves properly: modulo'; +tryeq $T++, 2031664238 % 4063328477, 2031664238, + 'UV behaves properly: modulo'; + +tryeq $T++, 2147483647 + 0, 2147483647, + 'trigger wrapping on 32 bit IVs and UVs'; + +tryeq $T++, 2147483647 + 1, 2147483648, 'IV + IV promotes to UV'; +tryeq $T++, 2147483640 + 10, 2147483650, 'IV + IV promotes to UV'; +tryeq $T++, 2147483647 + 2147483647, 4294967294, 'IV + IV promotes to UV'; +tryeq $T++, 2147483647 + 2147483649, 4294967296, 'IV + UV promotes to NV'; +tryeq $T++, 4294967294 + 2, 4294967296, 'UV + IV promotes to NV'; +tryeq $T++, 4294967295 + 4294967295, 8589934590, 'UV + UV promotes to NV'; + +tryeq $T++, 2147483648 + -1, 2147483647, 'UV + IV promotes to IV'; +tryeq $T++, 2147483650 + -10, 2147483640, 'UV + IV promotes to IV'; +tryeq $T++, -1 + 2147483648, 2147483647, 'IV + UV promotes to IV'; +tryeq $T++, -10 + 4294967294, 4294967284, 'IV + UV promotes to IV'; +tryeq $T++, -2147483648 + -2147483648, -4294967296, 'IV + IV promotes to NV'; +tryeq $T++, -2147483640 + -10, -2147483650, 'IV + IV promotes to NV'; + +# Hmm. Do not forget the simple stuff +# addition +tryeq $T++, 1 + 1, 2, 'addition of 2 positive integers'; +tryeq $T++, 4 + -2, 2, 'addition of positive and negative integer'; +tryeq $T++, -10 + 100, 90, 'addition of negative and positive integer'; +tryeq $T++, -7 + -9, -16, 'addition of 2 negative integers'; +tryeq $T++, -63 + +2, -61, 'addition of signed negative and positive integers'; +tryeq $T++, 4 + -1, 3, 'addition of positive and negative integer'; +tryeq $T++, -1 + 1, 0, 'addition which sums to 0'; +tryeq $T++, +29 + -29, 0, 'addition which sums to 0'; +tryeq $T++, -1 + 4, 3, 'addition of signed negative and positive integers'; +tryeq $T++, +4 + -17, -13, 'addition of signed positive and negative integers'; # subtraction -tryeq $T++, 3 - 1, 2; -tryeq $T++, 3 - 15, -12; -tryeq $T++, 3 - -7, 10; -tryeq $T++, -156 - 5, -161; -tryeq $T++, -156 - -5, -151; -tryeq $T++, -5 - -12, 7; -tryeq $T++, -3 - -3, 0; -tryeq $T++, 15 - 15, 0; - -tryeq $T++, 2147483647 - 0, 2147483647; -tryeq $T++, 2147483648 - 0, 2147483648; -tryeq $T++, -2147483648 - 0, -2147483648; - -tryeq $T++, 0 - -2147483647, 2147483647; -tryeq $T++, -1 - -2147483648, 2147483647; -tryeq $T++, 2 - -2147483648, 2147483650; - -tryeq $T++, 4294967294 - 3, 4294967291; -tryeq $T++, -2147483648 - -1, -2147483647; - -# IV - IV promote to UV -tryeq $T++, 2147483647 - -1, 2147483648; -tryeq $T++, 2147483647 - -2147483648, 4294967295; -# UV - IV promote to NV -tryeq $T++, 4294967294 - -3, 4294967297; -# IV - IV promote to NV -tryeq $T++, -2147483648 - +1, -2147483649; -# UV - UV promote to IV -tryeq $T++, 2147483648 - 2147483650, -2; -# IV - UV promote to IV -tryeq $T++, 2000000000 - 4000000000, -2000000000; +tryeq $T++, 3 - 1, 2, 'subtraction of two positive integers'; +tryeq $T++, 3 - 15, -12, + 'subtraction of two positive integers: minuend smaller'; +tryeq $T++, 3 - -7, 10, 'subtraction of positive and negative integer'; +tryeq $T++, -156 - 5, -161, 'subtraction of negative and positive integer'; +tryeq $T++, -156 - -5, -151, 'subtraction of two negative integers'; +tryeq $T++, -5 - -12, 7, + 'subtraction of two negative integers: minuend smaller'; +tryeq $T++, -3 - -3, 0, 'subtraction of two negative integers with result of 0'; +tryeq $T++, 15 - 15, 0, 'subtraction of two positive integers with result of 0'; +tryeq $T++, 2147483647 - 0, 2147483647, 'subtraction from large integer'; +tryeq $T++, 2147483648 - 0, 2147483648, 'subtraction from large integer'; +tryeq $T++, -2147483648 - 0, -2147483648, + 'subtraction from large negative integer'; +tryeq $T++, 0 - -2147483647, 2147483647, + 'subtraction of large negative integer from 0'; +tryeq $T++, -1 - -2147483648, 2147483647, + 'subtraction of large negative integer from negative integer'; +tryeq $T++, 2 - -2147483648, 2147483650, + 'subtraction of large negative integer from positive integer'; +tryeq $T++, 4294967294 - 3, 4294967291, 'subtraction from large integer'; +tryeq $T++, -2147483648 - -1, -2147483647, + 'subtraction from large negative integer'; +tryeq $T++, 2147483647 - -1, 2147483648, 'IV - IV promote to UV'; +tryeq $T++, 2147483647 - -2147483648, 4294967295, 'IV - IV promote to UV'; +tryeq $T++, 4294967294 - -3, 4294967297, 'UV - IV promote to NV'; +tryeq $T++, -2147483648 - +1, -2147483649, 'IV - IV promote to NV'; +tryeq $T++, 2147483648 - 2147483650, -2, 'UV - UV promote to IV'; +tryeq $T++, 2000000000 - 4000000000, -2000000000, 'IV - UV promote to IV'; # No warnings should appear; my $a; $a += 1; -tryeq $T++, $a, 1; +tryeq $T++, $a, 1, '+= with positive'; undef $a; $a += -1; -tryeq $T++, $a, -1; +tryeq $T++, $a, -1, '+= with negative'; undef $a; $a += 4294967290; -tryeq $T++, $a, 4294967290; +tryeq $T++, $a, 4294967290, '+= with positive'; undef $a; $a += -4294967290; -tryeq $T++, $a, -4294967290; +tryeq $T++, $a, -4294967290, '+= with negative'; undef $a; $a += 4294967297; -tryeq $T++, $a, 4294967297; +tryeq $T++, $a, 4294967297, '+= with positive'; undef $a; $a += -4294967297; -tryeq $T++, $a, -4294967297; +tryeq $T++, $a, -4294967297, '+= with negative'; my $s; $s -= 1; -tryeq $T++, $s, -1; +tryeq $T++, $s, -1, '-= with positive'; undef $s; $s -= -1; -tryeq $T++, $s, +1; +tryeq $T++, $s, +1, '-= with negative'; undef $s; $s -= -4294967290; -tryeq $T++, $s, +4294967290; +tryeq $T++, $s, +4294967290, '-= with negative'; undef $s; $s -= 4294967290; -tryeq $T++, $s, -4294967290; +tryeq $T++, $s, -4294967290, '-= with negative'; undef $s; $s -= 4294967297; -tryeq $T++, $s, -4294967297; +tryeq $T++, $s, -4294967297, '-= with positive'; undef $s; $s -= -4294967297; -tryeq $T++, $s, +4294967297; +tryeq $T++, $s, +4294967297, '-= with positive'; -# Multiplication - -tryeq $T++, 1 * 3, 3; -tryeq $T++, -2 * 3, -6; -tryeq $T++, 3 * -3, -9; -tryeq $T++, -4 * -3, 12; +# multiplication +tryeq $T++, 1 * 3, 3, 'multiplication of two positive integers'; +tryeq $T++, -2 * 3, -6, 'multiplication of negative and positive integer'; +tryeq $T++, 3 * -3, -9, 'multiplication of positive and negative integer'; +tryeq $T++, -4 * -3, 12, 'multiplication of two negative integers'; # check with 0xFFFF and 0xFFFF -tryeq $T++, 65535 * 65535, 4294836225; -tryeq $T++, 65535 * -65535, -4294836225; -tryeq $T++, -65535 * 65535, -4294836225; -tryeq $T++, -65535 * -65535, 4294836225; +tryeq $T++, 65535 * 65535, 4294836225, + 'multiplication: 0xFFFF and 0xFFFF: pos pos'; +tryeq $T++, 65535 * -65535, -4294836225, + 'multiplication: 0xFFFF and 0xFFFF: pos neg'; +tryeq $T++, -65535 * 65535, -4294836225, + 'multiplication: 0xFFFF and 0xFFFF: pos neg'; +tryeq $T++, -65535 * -65535, 4294836225, + 'multiplication: 0xFFFF and 0xFFFF: neg neg'; # check with 0xFFFF and 0x10001 -tryeq $T++, 65535 * 65537, 4294967295; -tryeq $T++, 65535 * -65537, -4294967295; -tryeq $T++, -65535 * 65537, -4294967295; -tryeq $T++, -65535 * -65537, 4294967295; +tryeq $T++, 65535 * 65537, 4294967295, + 'multiplication: 0xFFFF and 0x10001: pos pos'; +tryeq $T++, 65535 * -65537, -4294967295, + 'multiplication: 0xFFFF and 0x10001: pos neg'; +tryeq $T++, -65535 * 65537, -4294967295, + 'multiplication: 0xFFFF and 0x10001: neg pos'; +tryeq $T++, -65535 * -65537, 4294967295, + 'multiplication: 0xFFFF and 0x10001: neg neg'; # check with 0x10001 and 0xFFFF -tryeq $T++, 65537 * 65535, 4294967295; -tryeq $T++, 65537 * -65535, -4294967295; -tryeq $T++, -65537 * 65535, -4294967295; -tryeq $T++, -65537 * -65535, 4294967295; +tryeq $T++, 65537 * 65535, 4294967295, + 'multiplication: 0x10001 and 0xFFFF: pos pos'; +tryeq $T++, 65537 * -65535, -4294967295, + 'multiplication: 0x10001 and 0xFFFF: pos neg'; +tryeq $T++, -65537 * 65535, -4294967295, + 'multiplication: 0x10001 and 0xFFFF: neg pos'; +tryeq $T++, -65537 * -65535, 4294967295, + 'multiplication: 0x10001 and 0xFFFF: neg neg'; # These should all be dones as NVs -tryeq $T++, 65537 * 65537, 4295098369; -tryeq $T++, 65537 * -65537, -4295098369; -tryeq $T++, -65537 * 65537, -4295098369; -tryeq $T++, -65537 * -65537, 4295098369; +tryeq $T++, 65537 * 65537, 4295098369, 'multiplication: NV: pos pos'; +tryeq $T++, 65537 * -65537, -4295098369, 'multiplication: NV: pos neg'; +tryeq $T++, -65537 * 65537, -4295098369, 'multiplication: NV: neg pos'; +tryeq $T++, -65537 * -65537, 4295098369, 'multiplication: NV: neg neg'; # will overflow an IV (in 32-bit) -tryeq $T++, 46340 * 46342, 0x80001218; -tryeq $T++, 46340 * -46342, -0x80001218; -tryeq $T++, -46340 * 46342, -0x80001218; -tryeq $T++, -46340 * -46342, 0x80001218; - -tryeq $T++, 46342 * 46340, 0x80001218; -tryeq $T++, 46342 * -46340, -0x80001218; -tryeq $T++, -46342 * 46340, -0x80001218; -tryeq $T++, -46342 * -46340, 0x80001218; +tryeq $T++, 46340 * 46342, 0x80001218, + 'multiplication: overflow an IV in 32-bit: pos pos'; +tryeq $T++, 46340 * -46342, -0x80001218, + 'multiplication: overflow an IV in 32-bit: pos neg'; +tryeq $T++, -46340 * 46342, -0x80001218, + 'multiplication: overflow an IV in 32-bit: neg pos'; +tryeq $T++, -46340 * -46342, 0x80001218, + 'multiplication: overflow an IV in 32-bit: neg neg'; + +tryeq $T++, 46342 * 46340, 0x80001218, + 'multiplication: overflow an IV in 32-bit: pos pos'; +tryeq $T++, 46342 * -46340, -0x80001218, + 'multiplication: overflow an IV in 32-bit: pos neg'; +tryeq $T++, -46342 * 46340, -0x80001218, + 'multiplication: overflow an IV in 32-bit: neg pos'; +tryeq $T++, -46342 * -46340, 0x80001218, + 'multiplication: overflow an IV in 32-bit: neg neg'; # will overflow a positive IV (in 32-bit) -tryeq $T++, 65536 * 32768, 0x80000000; -tryeq $T++, 65536 * -32768, -0x80000000; -tryeq $T++, -65536 * 32768, -0x80000000; -tryeq $T++, -65536 * -32768, 0x80000000; - -tryeq $T++, 32768 * 65536, 0x80000000; -tryeq $T++, 32768 * -65536, -0x80000000; -tryeq $T++, -32768 * 65536, -0x80000000; -tryeq $T++, -32768 * -65536, 0x80000000; +tryeq $T++, 65536 * 32768, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos pos'; +tryeq $T++, 65536 * -32768, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos neg'; +tryeq $T++, -65536 * 32768, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg pos'; +tryeq $T++, -65536 * -32768, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg neg'; + +tryeq $T++, 32768 * 65536, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos pos'; +tryeq $T++, 32768 * -65536, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: pos neg'; +tryeq $T++, -32768 * 65536, -0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg pos'; +tryeq $T++, -32768 * -65536, 0x80000000, + 'multiplication: overflow a positive IV in 32-bit: neg neg'; # 2147483647 is prime. bah. -tryeq $T++, 46339 * 46341, 0x7ffea80f; -tryeq $T++, 46339 * -46341, -0x7ffea80f; -tryeq $T++, -46339 * 46341, -0x7ffea80f; -tryeq $T++, -46339 * -46341, 0x7ffea80f; +tryeq $T++, 46339 * 46341, 0x7ffea80f, + 'multiplication: hex product: pos pos'; +tryeq $T++, 46339 * -46341, -0x7ffea80f, + 'multiplication: hex product: pos neg'; +tryeq $T++, -46339 * 46341, -0x7ffea80f, + 'multiplication: hex product: neg pos'; +tryeq $T++, -46339 * -46341, 0x7ffea80f, + 'multiplication: hex product: neg neg'; # leading space should be ignored -tryeq $T++, 1 + " 1", 2; -tryeq $T++, 3 + " -1", 2; -tryeq $T++, 1.2, " 1.2"; -tryeq $T++, -1.2, " -1.2"; - -# divide - -tryeq $T++, 28/14, 2; -tryeq $T++, 28/-7, -4; -tryeq $T++, -28/4, -7; -tryeq $T++, -28/-2, 14; - -tryeq $T++, 0x80000000/1, 0x80000000; -tryeq $T++, 0x80000000/-1, -0x80000000; -tryeq $T++, -0x80000000/1, -0x80000000; -tryeq $T++, -0x80000000/-1, 0x80000000; +tryeq $T++, 1 + " 1", 2, 'ignore leading space: addition'; +tryeq $T++, 3 + " -1", 2, 'ignore leading space: subtraction'; +tryeq $T++, 1.2, " 1.2", 'floating point and string equivalent: positive'; +tryeq $T++, -1.2, " -1.2", 'floating point and string equivalent: negative'; + +# division +tryeq $T++, 28/14, 2, 'division of two positive integers'; +tryeq $T++, 28/-7, -4, 'division of positive integer by negative'; +tryeq $T++, -28/4, -7, 'division of negative integer by positive'; +tryeq $T++, -28/-2, 14, 'division of negative integer by negative'; + +tryeq $T++, 0x80000000/1, 0x80000000, + 'division of positive hex by positive integer'; +tryeq $T++, 0x80000000/-1, -0x80000000, + 'division of positive hex by negative integer'; +tryeq $T++, -0x80000000/1, -0x80000000, + 'division of negative hex by negative integer'; +tryeq $T++, -0x80000000/-1, 0x80000000, + 'division of negative hex by positive integer'; # The example for sloppy divide, rigged to avoid the peephole optimiser. -tryeq_sloppy $T++, "20." / "5.", 4; - -tryeq $T++, 2.5 / 2, 1.25; -tryeq $T++, 3.5 / -2, -1.75; -tryeq $T++, -4.5 / 2, -2.25; -tryeq $T++, -5.5 / -2, 2.75; - -# Bluuurg if your floating point can't accurately cope with powers of 2 +tryeq_sloppy $T++, "20." / "5.", 4, 'division of floating point without fractional part'; + +tryeq $T++, 2.5 / 2, 1.25, + 'division of positive floating point by positive integer'; +tryeq $T++, 3.5 / -2, -1.75, + 'division of positive floating point by negative integer'; +tryeq $T++, -4.5 / 2, -2.25, + 'division of negative floating point by positive integer'; +tryeq $T++, -5.5 / -2, 2.75, + 'division of negative floating point by negative integer'; + +# Bluuurg if your floating point can not accurately cope with powers of 2 # [I suspect this is parsing string->float problems, not actual arith] -tryeq_sloppy $T++, 18446744073709551616/1, 18446744073709551616; # Bluuurg -tryeq_sloppy $T++, 18446744073709551616/2, 9223372036854775808; -tryeq_sloppy $T++, 18446744073709551616/4294967296, 4294967296; -tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; +tryeq_sloppy $T++, 18446744073709551616/1, 18446744073709551616, + 'division of very large number by 1'; # Bluuurg +tryeq_sloppy $T++, 18446744073709551616/2, 9223372036854775808, + 'division of very large number by 2'; +tryeq_sloppy $T++, 18446744073709551616/4294967296, 4294967296, + 'division of two very large numbers'; +tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2, + 'division of two very large numbers'; { # The peephole optimiser is wrong to think that it can substitute intops @@ -277,27 +315,27 @@ tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; my $n = 1127; my $float = ($n % 1000) * 167772160.0; - tryeq_sloppy $T++, $float, 21307064320; + tryeq_sloppy $T++, $float, 21307064320, 'integer times floating point'; # On a 32 bit machine, if the i_multiply op is used, you will probably get - # -167772160. It's actually undefined behaviour, so anything may happen. + # -167772160. It is actually undefined behaviour, so anything may happen. my $int = ($n % 1000) * 167772160; - tryeq $T++, $int, 21307064320; + tryeq $T++, $int, 21307064320, 'integer times integer'; my $float2 = ($n % 1000 + 0.0) * 167772160; - tryeq $T++, $float2, 21307064320; + tryeq $T++, $float2, 21307064320, 'floating point times integer'; my $int2 = ($n % 1000 + 0) * 167772160; - tryeq $T++, $int2, 21307064320; + tryeq $T++, $int2, 21307064320, 'integer plus zero times integer'; # zero, but in a way that ought to be able to defeat any future optimizer: my $zero = $$ - $$; my $int3 = ($n % 1000 + $zero) * 167772160; - tryeq $T++, $int3, 21307064320; + tryeq $T++, $int3, 21307064320, 'defeat any future optimizer'; my $t = time; my $t1000 = time() * 1000; - try $T++, abs($t1000 -1000 * $t) <= 2000; + try $T++, abs($t1000 -1000 * $t) <= 2000, 'absolute value'; } { @@ -305,57 +343,26 @@ tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2; my $n = 1127; my $float = ($n % 1000) * 720575940379279360.0; - tryeq_sloppy $T++, $float, 9.15131444281685e+19; + tryeq_sloppy $T++, $float, 9.15131444281685e+19, + '64 bit: integer times floating point'; my $int = ($n % 1000) * 720575940379279360; - tryeq_sloppy $T++, $int, 9.15131444281685e+19; + tryeq_sloppy $T++, $int, 9.15131444281685e+19, + '64 bit: integer times integer'; my $float2 = ($n % 1000 + 0.0) * 720575940379279360; - tryeq_sloppy $T++, $float2, 9.15131444281685e+19; + tryeq_sloppy $T++, $float2, 9.15131444281685e+19, + '64 bit: floating point times integer'; my $int2 = ($n % 1000 + 0) * 720575940379279360; - tryeq_sloppy $T++, $int2, 9.15131444281685e+19; + tryeq_sloppy $T++, $int2, 9.15131444281685e+19, + '64 bit: integer plus zero times integer'; # zero, but in a way that ought to be able to defeat any future optimizer: my $zero = $$ - $$; my $int3 = ($n % 1000 + $zero) * 720575940379279360; - tryeq_sloppy $T++, $int3, 9.15131444281685e+19; -} - -my $vms_no_ieee; -if ($^O eq 'VMS') { - use vars '%Config'; - eval {require Config; import Config}; - $vms_no_ieee = 1 unless defined($Config{useieee}); -} - -if ($^O eq 'vos') { - print "not ok ", $T++, " # TODO VOS raises SIGFPE instead of producing infinity.\n"; -} -elsif ($vms_no_ieee) { - print $T++, " # SKIP -- the IEEE infinity model is unavailable in this configuration.\n" -} -elsif ($^O eq 'ultrix') { - print "not ok ", $T++, " # TODO Ultrix enters deep nirvana instead of producing infinity.\n"; -} -else { - # The computation of $v should overflow and produce "infinity" - # on any system whose max exponent is less than 10**1506. - # The exact string used to represent infinity varies by OS, - # so we don't test for it; all we care is that we don't die. - # - # Perl considers it to be an error if SIGFPE is raised. - # Chances are the interpreter will die, since it doesn't set - # up a handler for SIGFPE. That's why this test is last; to - # minimize the number of test failures. --PG - - my $n = 5000; - my $v = 2; - while (--$n) - { - $v *= 2; - } - print "ok ", $T++, "\n"; + tryeq_sloppy $T++, $int3, 9.15131444281685e+19, + '64 bit: defeat any future optimizer'; } # [perl #109542] $1 and "$1" should be treated the same way @@ -408,3 +415,40 @@ print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" % something\n'; $a = (97656250000000000 % $1); $b = (97656250000000000 % "$1"); print "not "x($a ne $b), "ok ", $T++, qq ' - something % \$1 vs "\$1"\n'; + +my $vms_no_ieee; +if ($^O eq 'VMS') { + use vars '%Config'; + eval {require Config; import Config}; + $vms_no_ieee = 1 unless defined($Config{useieee}); +} + +if ($^O eq 'vos') { + print "not ok ", $T++, " # TODO VOS raises SIGFPE instead of producing infinity.\n"; +} +elsif ($vms_no_ieee) { + print $T++, " # SKIP -- the IEEE infinity model is unavailable in this configuration.\n" +} +elsif ($^O eq 'ultrix') { + print "not ok ", $T++, " # TODO Ultrix enters deep nirvana instead of producing infinity.\n"; +} +else { + # The computation of $v should overflow and produce "infinity" + # on any system whose max exponent is less than 10**1506. + # The exact string used to represent infinity varies by OS, + # so we don't test for it; all we care is that we don't die. + # + # Perl considers it to be an error if SIGFPE is raised. + # Chances are the interpreter will die, since it doesn't set + # up a handler for SIGFPE. That's why this test is last; to + # minimize the number of test failures. --PG + + my $n = 5000; + my $v = 2; + while (--$n) + { + $v *= 2; + } + print "ok ", $T++, " - infinity\n"; +} + -- 1.6.3.2 ```
p5pRT commented 12 years ago

From @cpansprout

On Fri Nov 23 13​:24​:27 2012\, jkeenan wrote​:

On Mon Nov 19 08​:47​:17 2012\, sprout wrote​:

I do think you are reading too much into what perlhack says. test.pl may be OK to use in op/\, but that does not mean that everything in there must use it.

Still\, separation into different directories does not sound like a bad idea.

I have created https://rt-archive.perl.org/perl5/Ticket/Display.html?id=115838 to address the general issue. Have you seen that yet?

I did. I have no comment on that in particular. Let me explain why.

I have seen test suite refactorings that basically sabotaged the tests\, so they were no longer testing what they were supposed to be testing. That actually happened in 5.10. A feature was added\, with tests. The tests were refactored. Later the feature was broken and 5.10 shipped with a broken feature\, but the tests still passed. So Iā€™m paranoid.

I donā€™t fully understand or appreciate the reasons why certain things are done certain ways\, but I can appreciate that there may be reasons. So I donā€™t assume that all changes are safe to make.

I have seen comments scattered throughout the test suite suggesting that things are done oddly for a reason\, so I try to be careful when it comes to modifying tests.

I just wanted to share my paranoia with others by raising awareness of the issues. I donā€™t know whether it is absolutely necessary for arith.t to avoid test.pl. But I do know that anyone refactoring tests needs to be careful and not assume that nothing is written in an odd way without a reason.

I would actually prefer that tests not be refactored at all\, but I am not in charge and am willing to live with it.

So Iā€™m basically saying that I donā€™t want to be involved in refactoring tests\, but I want others to be aware of the danger.

(I know thatā€™s not well written. I wrote it quickly. I probably repeated myself a few times.)

--

Father Chrysostomos

p5pRT commented 12 years ago

From @demerphq

On 24 November 2012 03​:12\, Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org wrote​:

On Fri Nov 23 13​:24​:27 2012\, jkeenan wrote​:

On Mon Nov 19 08​:47​:17 2012\, sprout wrote​:

I do think you are reading too much into what perlhack says. test.pl may be OK to use in op/\, but that does not mean that everything in there must use it.

Still\, separation into different directories does not sound like a bad idea.

I have created https://rt-archive.perl.org/perl5/Ticket/Display.html?id=115838 to address the general issue. Have you seen that yet?

I did. I have no comment on that in particular. Let me explain why.

I have seen test suite refactorings that basically sabotaged the tests\, so they were no longer testing what they were supposed to be testing. That actually happened in 5.10. A feature was added\, with tests. The tests were refactored. Later the feature was broken and 5.10 shipped with a broken feature\, but the tests still passed. So Iā€™m paranoid.

I donā€™t fully understand or appreciate the reasons why certain things are done certain ways\, but I can appreciate that there may be reasons. So I donā€™t assume that all changes are safe to make.

I have seen similar with regex tests.

Yves

-- perl -Mre=debug -e "/just|another|perl|hacker/"

p5pRT commented 12 years ago

From @ap

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2012-11-24 03​:15]​:

I have seen test suite refactorings that basically sabotaged the tests\, so they were no longer testing what they were supposed to be testing. That actually happened in 5.10. A feature was added\, with tests. The tests were refactored. Later the feature was broken and 5.10 shipped with a broken feature\, but the tests still passed. So Iā€™m paranoid.

And anyone who has their epistemology down will now ask​: but was the ineffectiveness of those tests a function of their refactoredness? You know that the tests tested failed to test for the right thing *after* being refactored\, but do you *also* know that they tested for the right thing *before* getting refactored? Put another way\, which came first​: the refactoring or the brokenness? Just because evidence of brokenness followed evidence of refactoring doesnā€™t also mean brokenness followed refactoring. You cannot necessarily deduce causality from temporal sequence of observation\, even though our brains are strongly wired to work that way.

Itā€™s so hard not to fool oneself\, to quote Feynman.

For making sure that refactorings donā€™t *introduce* brokenness if it was not previously present\, there is an easy if costly approach to reaching some level of confidence​: just keep the old tests around and compare the shiny new testsā€™ results with theirs\, for the duration of a couple of releases. At some point you can decide that youā€™ve watched them spit out the same output for long enough to attain some X% confidence\, and can therefore delete the old crufty version.

But tests can never *prove* anything. Letā€™s not forget that. In practice this is rarely relevant but it matters a great deal when for some reason you find yourself reasoning epistemologically about test suites.

(So for making sure brokenness doesnā€™t exist *in the first place*\, well\, good luck with thatā€¦)

Regards\, -- Aristotle Pagaltzis // \<http​://plasmasturm.org/>

p5pRT commented 12 years ago

From @cpansprout

On Sat Nov 24 04​:43​:32 2012\, aristotle wrote​:

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2012-11-24 03​:15]​:

I have seen test suite refactorings that basically sabotaged the tests\, so they were no longer testing what they were supposed to be testing. That actually happened in 5.10. A feature was added\, with tests. The tests were refactored. Later the feature was broken and 5.10 shipped with a broken feature\, but the tests still passed. So Iā€™m paranoid.

And anyone who has their epistemology down will now ask​: but was the ineffectiveness of those tests a function of their refactoredness?

Yes\, it was.

--

Father Chrysostomos

p5pRT commented 12 years ago

From @jkeenan

On Fri Nov 23 13​:26​:49 2012\, jkeenan wrote​:

On Sun Nov 18 11​:02​:39 2012\, sprout wrote​:

On Sun Nov 18 09​:49​:09 2012\, jkeen@​verizon.net wrote​:

The patch attached is the last of those begun at yesterday's St Louis Perl Hackathon. Thanks to all participants in that event.

The patch converts the file from using all hard-coded tests (or subroutines wrapping around hard-coded tests) to using functions pulled in by require-ing test.pl.

But test.pl uses infix + for its machinery\, and we are trying to test that here.

I am attaching a patch which *substitutes* for the patch previously attached to this RT. Father C\, I believe it should satisfy your concerns.

Please review (anyone\, not just Father C)\, as we had to write descriptions for 140 out of 167 individual tests in this file.

Thank you very much. Jim Keenan

Pushed to blead in commit 84721e9. Closing ticket.

Thank you very much. Jim Keenan

p5pRT commented 12 years ago

@jkeenan - Status changed from 'open' to 'resolved'