I have the following case where I want to split implementations and documentation. The following unittest should also be used as example in the docs but that doesn't work.
version (D_Ddoc)
{
/// Library docs
struct Library
{
/// foo
void foo();
}
// unittests docs only work here, but here they don't run
}
else version (Windows)
{
// Library impls
struct Library
{
void foo() {}
}
}
else version (Posix)
{
// Library impls
struct Library
{
void foo() {}
}
}
///
unittest
{
// shared unittest used as example and for testing
Library lib;
}
Comment #1 by code — 2013-09-27T20:00:32Z
Ah I forgot to mention. The following case works. It seems like it's the else branch that break the unittest docs.
version (D_Ddoc)
{
///
struct Library {}
}
///
version (all) unittest
{
}
Comment #2 by issues.dlang — 2017-12-14T01:22:30Z
Similarly, the unit tests don't end up in the docs in this code, and version(D_Ddoc) isn't even involved:
==============
///
struct S
{
/// Something about foo.
version(Posix)
alias Foo = int;
else version(Windows)
alias Foo = int;
///
unittest
{
Foo foo;
}
}
==============
Or at least, the unit test doesn't show up in the docs if you compile on a POSIX system. I assume that it will show up if you compile on Windows, since if I flip the versions, the unit test does show up. So, I guess that it considers the unit test to go with the symbol in the else block and will only put the test in the docs if it's the last version that's taken.
I have a similar problem in my code with static ifs, so I think that this problem applies to them too.
Comment #3 by issues.dlang — 2017-12-14T01:29:01Z
Here's an example that has the problem with static if:
///
struct S(R)
{
/// Some docs
static if(is(R == string))
alias S = R;
else
alias S = int;
///
unittest
{
S s;
}
}