diff --git a/src/debug.c b/src/debug.c index ccaf93758..114b1bd92 100644 --- a/src/debug.c +++ b/src/debug.c @@ -723,7 +723,7 @@ NULL } else if (!strcasecmp(name,"integer")) { addReplyLongLong(c,12345); } else if (!strcasecmp(name,"double")) { - addReplyDouble(c,3.14159265359); + addReplyDouble(c,3.141); } else if (!strcasecmp(name,"bignum")) { addReplyBigNum(c,"1234567999999999999999999999999999999",37); } else if (!strcasecmp(name,"null")) { diff --git a/tests/modules/basics.c b/tests/modules/basics.c index e1d2c2115..7f4383759 100644 --- a/tests/modules/basics.c +++ b/tests/modules/basics.c @@ -285,7 +285,7 @@ int TestCallResp3Double(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) /* we compare strings, since comparing doubles directly can fail in various architectures, e.g. 32bit */ char got[30], expected[30]; sprintf(got, "%.17g", d); - sprintf(expected, "%.17g", 3.14159265359); + sprintf(expected, "%.17g", 3.141); if (strcmp(got, expected) != 0) goto fail; RedisModule_ReplyWithSimpleString(ctx,"OK"); return REDISMODULE_OK; diff --git a/tests/unit/moduleapi/reply.tcl b/tests/unit/moduleapi/reply.tcl index c1f572c4b..43d44707c 100644 --- a/tests/unit/moduleapi/reply.tcl +++ b/tests/unit/moduleapi/reply.tcl @@ -7,7 +7,7 @@ start_server {tags {"modules"}} { for {set proto 2} {$proto <= 3} {incr proto} { r hello $proto - test {RM_ReplyWithString: an string reply} { + test "RESP$proto: RM_ReplyWithString: an string reply" { # RedisString set string [r rw.string "Redis"] assert_equal "Redis" $string @@ -16,31 +16,41 @@ start_server {tags {"modules"}} { assert_equal "A simple string" $string } - test {RM_ReplyWithBigNumber: an string reply} { + test "RESP$proto: RM_ReplyWithBigNumber: an string reply" { assert_equal "123456778901234567890" [r rw.bignumber "123456778901234567890"] } - test {RM_ReplyWithInt: an integer reply} { + test "RESP$proto: RM_ReplyWithInt: an integer reply" { assert_equal 42 [r rw.int 42] } - test {RM_ReplyWithDouble: a float reply} { + test "RESP$proto: RM_ReplyWithDouble: a float reply" { assert_equal 3.141 [r rw.double 3.141] } - test {RM_ReplyWithLongDouble: a float reply} { - assert_equal 3.141 [r rw.longdouble 3.141] + set ld 0.00000000000000001 + test "RESP$proto: RM_ReplyWithLongDouble: a float reply" { + if {$proto == 2} { + # here the response gets to TCL as a string + assert_equal $ld [r rw.longdouble $ld] + } else { + # TCL doesn't support long double and the test infra converts it to a + # normal double which causes precision loss. so we use readraw instead + r readraw 1 + assert_equal ",$ld" [r rw.longdouble $ld] + r readraw 0 + } } - test {RM_ReplyWithVerbatimString: a string reply} { + test "RESP$proto: RM_ReplyWithVerbatimString: a string reply" { assert_equal "bla\nbla\nbla" [r rw.verbatim "bla\nbla\nbla"] } - test {RM_ReplyWithArray: an array reply} { + test "RESP$proto: RM_ReplyWithArray: an array reply" { assert_equal {0 1 2 3 4} [r rw.array 5] } - test {RM_ReplyWithMap: an map reply} { + test "RESP$proto: RM_ReplyWithMap: an map reply" { set res [r rw.map 3] if {$proto == 2} { assert_equal {0 0 1 1.5 2 3} $res @@ -49,11 +59,11 @@ start_server {tags {"modules"}} { } } - test {RM_ReplyWithSet: an set reply} { + test "RESP$proto: RM_ReplyWithSet: an set reply" { assert_equal {0 1 2} [r rw.set 3] } - test {RM_ReplyWithAttribute: an set reply} { + test "RESP$proto: RM_ReplyWithAttribute: an set reply" { if {$proto == 2} { catch {[r rw.attribute 3]} e assert_match "Attributes aren't supported by RESP 2" $e @@ -71,15 +81,15 @@ start_server {tags {"modules"}} { } } - test {RM_ReplyWithBool: a boolean reply} { + test "RESP$proto: RM_ReplyWithBool: a boolean reply" { assert_equal {0 1} [r rw.bool] } - test {RM_ReplyWithNull: a NULL reply} { + test "RESP$proto: RM_ReplyWithNull: a NULL reply" { assert_equal {} [r rw.null] } - test {RM_ReplyWithError: an error reply} { + test "RESP$proto: RM_ReplyWithError: an error reply" { catch {r rw.error} e assert_match "An error" $e } diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 5b7024669..893f9f994 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -1028,10 +1028,10 @@ start_server {tags {"scripting resp3 needs:debug"}} { set ret [r eval "redis.setresp($i);return redis.call('debug', 'protocol', 'double')" 0] if {$client_proto == 2 || $i == 2} { # if either Lua or the clien is RESP2 the reply will be RESP2 - assert_equal $ret {$18} - assert_equal [r read] {3.1415926535900001} + assert_equal $ret {$5} + assert_equal [r read] {3.141} } else { - assert_equal $ret {,3.1415926535900001} + assert_equal $ret {,3.141} } }