Bug 16711 – unittest writefln

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-11-22T12:56:52Z
Last change time
2019-12-27T08:29:13Z
Assigned to
No Owner
Creator
liangwen

Comments

Comment #0 by liangwen — 2016-11-22T12:56:52Z
if unittest and use writefln("%s",123),get the wrong First-chance exception: std.format.FormatException Unterminated format specifier: "%" at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(829) win7 vs2015 visuald 0.3.34 dmd-2.072.0 import std.stdio; unittest { assert(1==1); } int main(string[] argv) { writefln("%s",123); return 0; }
Comment #1 by r.sagitario — 2017-01-14T09:05:47Z
By importing std.stdio and using writefln, you are also instantiating template struct FormatSpec(Char) from std.format. This contains a unittest that checks that an exception is thrown. Every time code generation for this struct kicks in, the unittest will also be generated. The unittest does not contain anything depending on the template parameters, so it should not be inside the struct declaration, but outside of it. Thus I'm reassigning this to component phobos.
Comment #2 by bugzilla — 2019-12-27T08:29:13Z
The behaviour of dmd regarding unittests changed in version 2.091. IMHO this isn't a problem anymore.