op/cmp.t: fix failing tests under -ffast-math
authorDavid Mitchell <davem@iabyn.com>
Sat, 26 Mar 2011 23:48:04 +0000 (23:48 +0000)
committerDavid Mitchell <davem@iabyn.com>
Sat, 26 Mar 2011 23:48:04 +0000 (23:48 +0000)
Apparently if you compile using gcc's -ffast-math option,
NaNs start matching other things. So skip the NaN tests.

t/op/cmp.t

index d811bae..0fbca5f 100644 (file)
@@ -52,10 +52,24 @@ foreach ("\x{1F4A9}", chr(163), 'N') {
 $expect = 7 * ($#FOO+2) * ($#FOO+1) + 6 * @raw + 6 * @utf8;
 print "1..$expect\n";
 
+my $bad_NaN = 0;
+
+{
+    # gcc's -ffast-math option may stop NaNs working correctly
+    use Config;
+    my $ccflags = $Config{ccflags} // '';
+    $bad_NaN = 1 if $ccflags =~ /-ffast-math\b/;
+}
+
 sub nok ($$$$$$$$) {
   my ($test, $left, $threeway, $right, $result, $i, $j, $boolean) = @_;
   $result = defined $result ? "'$result'" : 'undef';
-  print "not ok $test # ($left $threeway $right) gives: $result \$i=$i \$j=$j, $boolean disagrees\n";
+  if ($bad_NaN && ($left eq 'NaN' || $right eq 'NaN')) {
+    print "ok $test # skipping failed NaN test under -ffast-math\n";
+  }
+  else {
+    print "not ok $test # ($left $threeway $right) gives: $result \$i=$i \$j=$j, $boolean disagrees\n";
+  }
 }
 
 my $ok = 0;