October 05, 2015
On Sun, Sep 27, 2015 at 05:01:45AM +0000, Jonathan M Davis via Digitalmars-d wrote:
> This DIP provides a way to handle unittest blocks inside of templates which works with ddoc without compiling the unittest blocks into each instantiation.
> 
> http://wiki.dlang.org/DIP82

Thanks, Jonathan, for writing this up.  I have felt a need for this for a long time now, both in Phobos and in my own code.  Overall, I'm very much in favor of this proposal, particularly as it lets us make use of ddoc'd unittests within templated types without the associated template bloat.  This is quite important for Phobos as otherwise, we either risk code examples in the docs bit-rotting (user annoyance when examples don't compile, etc.), or user code compiled with -unittest unnecessarily paying the penalty of multiple identical unittests just because they use Phobos.

One minor issue with the DIP as currently written, though: it should be stipulated that inside a static unittest block, it is illegal to reference template arguments to the enclosing template block. Otherwise, you may run into pathological cases where it's not clear what the correct semantics should be:

	template MyTmpl(T) {
		///
		void method() { ... }

		///
		static unittest {
			// Unclear what should be the type of t in the
			// single instance of this unittest:
			T t;
		}
	}

	// (... since MyTmpl likely has multiple different
	// instantiations:)
	alias T1 = MyTmpl!int;
	alias T2 = MyTmpl!string;
	alias T3 = MyTmpl!float;


T

-- 
2+2=4. 2*2=4. 2^2=4. Therefore, +, *, and ^ are the same operation.
October 06, 2015
On Monday, 5 October 2015 at 19:32:00 UTC, H. S. Teoh wrote:
> One minor issue with the DIP as currently written, though: it should be stipulated that inside a static unittest block, it is illegal to reference template arguments to the enclosing template block. Otherwise, you may run into pathological cases where it's not clear what the correct semantics should be:

Given how the rest of the DIP is written, I don't see how it would even be possible for it to be legal to reference any template arguments. That's implied by the other semantics involved. But I should update the DIP to make that explicit.

- Jonathan M Davis
1 2
Next ›   Last »