Problem with public example in Phobos

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Dec 18 20:20:54 UTC 2019


On Wed, Dec 18, 2019 at 07:16:15PM +0000, berni44 via Digitalmars-d-learn wrote:
> On Wednesday, 18 December 2019 at 17:57:15 UTC, Steven Schveighoffer wrote:
[...]
> > Note, putting unittests inside templates duplicates the unit test
> > for every instantiation. Using an instantiation other than the
> > template itself is going to result in a lot of duplicated tests.
> > Unfortunately, there is no mechanism to have a documented unittest
> > that isn't part of the instantiation.
> 
> I know about that problem. Would be good, to have some such mechanism.
> Until we have, I'll resort to moving them after the template and
> adding a link to the docs, see below.
[...]

Hackish workaround:

	struct TemplateStruct(T) {
		auto foo(...) { ... }

		static if (is(T == int))
			/// Look, ma! I'm documented!
			unittest {
			}
	}

	// Make sure the test actually runs
	version(unittest) alias dummy = TemplateStruct!int;


T

-- 
Why can't you just be a nonconformist like everyone else? -- YHL


More information about the Digitalmars-d-learn mailing list