perl5-dbi / DBD-MariaDB

Perl MariaDB driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2.1 is not a good testing value for -Duselongdouble

Tux opened this issue · comments

https://github.com/gooddata/DBD-MariaDB/blob/8d0799ce41eb06821ba3352f3ba336dfa5e262f4/t/40types.t#L70

t/40types.t ............................. 41/78
#   Failed test at t/40types.t line 78.
#     Structures begin differing at:
#          $got->[0][0] = '2.10000000000000009'
#     $expected->[0][0] = '2.1'
# Looks like you failed 1 test of 78.
t/40types.t ............................. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/78 subtests

with patch

diff --git a/t/40types.t b/t/40types.t
index b92e0aa..8fc272a 100644
--- a/t/40types.t
+++ b/t/40types.t
@@ -67,7 +67,7 @@ ok($dbh->do(qq{DROP TABLE t1}), "cleaning up");
 ok($dbh->do(qq{CREATE TABLE t1 (num DOUBLE)}), "creating table");

 $sth= $dbh->prepare("INSERT INTO t1 VALUES (?)");
-ok($sth->bind_param(1, 2.1, DBI::SQL_DOUBLE), "binding parameter");
+ok($sth->bind_param(1, 2.125, DBI::SQL_DOUBLE), "binding parameter");
 ok($sth->execute(), "inserting data");
 ok($sth->finish);
 ok($sth->bind_param(1, -1, DBI::SQL_DOUBLE), "binding parameter");
@@ -75,7 +75,7 @@ ok($sth->execute(), "inserting data");
 ok($sth->finish);

 my $ret = $dbh->selectall_arrayref("SELECT * FROM t1");
-is_deeply($ret, [ [2.1],  [-1] ]);
+is_deeply($ret, [ [2.125],  [-1] ]);

 $sv = svref_2object(\$ret->[0]->[0]);
 ok($sv->FLAGS & SVf_NOK, "scalar is double");

t/40types.t ............................. ok
commented

First of all, it is a bad idea to try comparing floating point on equality. The better way would be to use num test with tolerance: https://metacpan.org/pod/Test::Deep#num

True, but that will add a dependency, which I am not keen on

commented

Test::Deep is already used and needed for running DBD::mysql/DBD::MariaDB tests.