digitalmars.D.bugs - [Issue 5092] New: pure nothrow should be ignored for unit tests
- d-bugmail puremagic.com (44/44) Oct 21 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5092
- d-bugmail puremagic.com (11/11) Nov 03 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5092
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 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
http://d.puremagic.com/issues/show_bug.cgi?id=5092 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed svn 736. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 03 2010