<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-09-27 14:01 GMT+09:00 Jonathan M Davis via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">This DIP provides a way to handle unittest blocks inside of templates which works with ddoc without compiling the unittest blocks into each instantiation.<br>
<br>
<a href="http://wiki.dlang.org/DIP82" rel="noreferrer" target="_blank">http://wiki.dlang.org/DIP82</a><br>
<br>
<br>
At present, we really can't put unittest blocks - including ddoc-ed unittest blocks - inside of templated types, which has been a problem for Phobos and came up again just the other day when someone was helpful and went and tried to turn the examples in std.datetime's *Interval types in ddoc-ed unit tests, but we had to reject the changes, because it would have resulted in those tests being compiled into every instantiation of those templated types, polluting the code of anyone who uses them as well as making the Phobos unit tests take longer to run for no extra benefit whatsoever.<br>
<br>
So, I wrote up this DIP in the hopes of solving the problem in a clean and simple manner which fits in well with the existing language features.</blockquote><div><br></div><div>Interesting proposal. </div><div><br></div>Quick questions:<div><br></div><div>1. I think the token `static` should be placed at the immediate front of `unittest`</div><div><br></div><div><div> static unittest { ... }</div><div></div></div><div><div class="gmail_extra"><div> static nothrow unittest { ... } // NG</div><div></div><div class="gmail_quote"><br></div><div class="gmail_quote">It's consistent with the behavior of `static this()` family.</div><div class="gmail_quote"><br></div><div class="gmail_quote">2. Currently the members of template won't be semantically analyzed until it's instantiated. So, when the `static unittest` is enclosed in other blocks, how it works?</div><div class="gmail_quote"><br></div><div class="gmail_quote"> template Foo(T) {<br></div><div class="gmail_quote"><div class="gmail_quote"> // inside conditional compilation blocks:</div><div class="gmail_quote"></div><div class="gmail_quote"> static if (is(T == int)) {</div><div class="gmail_quote"> static unittest { ... }</div><div class="gmail_quote"> }</div><div class="gmail_quote"> version (UserDefinedVersion) {</div><div class="gmail_quote"> static unittest { ... }</div><div class="gmail_quote"> }</div><div class="gmail_quote"> debug (UserDefinedDebugId) {</div><div class="gmail_quote"> static unittest { ... }</div><div class="gmail_quote"> }</div><div class="gmail_quote"><br></div><div class="gmail_quote"> // inside block/labeled attributes</div><div class="gmail_quote"> nothrow {</div><div class="gmail_quote"> static unittest { ... }</div><div class="gmail_quote"> }</div><div class="gmail_quote"> @safe:</div><div class="gmail_quote"> static unittest { ... }</div><div class="gmail_quote"><br></div><div class="gmail_quote"> mixin("static unittest { ... }");</div><div class="gmail_quote"> mixin(makeStaticUnittest());</div><div class="gmail_quote"> }<br></div><div><br></div><div> string makeStaticUnittest() { return "static unittest { ... }"; }</div><div><br></div><div>Kenji Hara<br></div><div><br></div></div></div></div><div> </div></div></div></div>