www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14774] New: core.time.numToString(double) fails its unit


          Issue ID: 14774
           Summary: core.time.numToString(double) fails its unit tests in
                    non-release mode
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: issues.dlang jmdavisProg.com

As I pointed out in issue# 14773, the druntime unit tests are unfortunately
only run in non-release mode right now, so stuff like range violations in the
tests typically aren't caught. In particular, the tests for numToString(double)
in core.time fail due to range violations (it's resulting in "0.3" and not
"0.33")) when built without -release, but by some quirk of the implementation,
the resulting slice matches the string that it's being tested against even
though they aren't actually equal. It's the tests which are currently at line#

    auto a = 1.337;
    auto aStr = numToString(a);
    assert(aStr[0 .. 4] == "1.33", aStr);

    a = 0.337;
    aStr = numToString(a);
    assert(aStr[0 .. 4] == "0.33", aStr);

    a = -0.337;
    aStr = numToString(a);
    assert(aStr[0 .. 5] == "-0.33", aStr);

You can also just mark the unittest block with  safe rather than editing the
makefile to build druntime without -release. And if you do, the second and
third tests fail.

Jul 06 2015