www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5092] New: pure nothrow should be ignored for unit tests

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5092

           Summary: pure nothrow should be ignored for unit tests
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2010-10-21 06:50:18 PDT ---
import std.stdio;

pure nothrow:

int foo(int z) { return z*2; }

unittest {    
    writeln("testing foo");
    assert(foo(4) == 8);
}

---
This won't compile, because the unit test calls writeln which is impure and may
throw. 

It makes no sense for a unittest to be nothrow. And it's really a nuisance.

And if a unittest isn't conceptually pure, you have a big problem anyway -- the
program behaviour will change depending on whether unittests are run, or not.

PATCH: func.c, around line 3460

void UnitTestDeclaration::semantic(Scope *sc)
{
    if (global.params.useUnitTests)
    {
        if (!type)
            type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
        Scope *sc2 = sc->push();
+        // It makes no sense for unit tests to be pure or nothrow.
+        sc2->stc &= ~(STCnothrow | STCpure);
        sc2->linkage = LINKd;
        FuncDeclaration::semantic(sc2);
        sc2->pop();
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 21 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5092


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-11-03 06:36:38 PDT ---
Fixed svn 736.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 03 2010