[Issue 22596] The "publictests" target runs unittests at the top-level namespace so they don't have access to
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 14 04:39:51 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22596
Andrei Alexandrescu <andrei at erdani.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |---
--- Comment #3 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to moonlightsentinel from comment #2)
> A documented unittest as defined above would contribute the following to the
> documentation:
>
> Example:
> -------------------
> writeln(v);
> ------------------
>
> Note that the symbol `v` is entirely undefined - so the test is failing as
> expected. A user should be able to execute code shown in a documented
> unittest by simply adding the appropriate import.
>
> Any unittest that relies on internal details of a module / it's members
> (which are not accessible when importing said module) should be private.
> This also applies to the template parameter `v`.
The symbol is not undefined because the documentation is nested inside the
`canon` template, which is parameterized on v.
Maybe I simplified the code too much. Expanding it a bit:
/// Module.
import std.stdio;
/// This is a template parameterized on value `v`.
template canon(string v) {
/// This is a function that does something.
void fun(string);
/// This is a unittest that shows how to use the function
unittest {
fun(v ~ "!");
}
}
void main() {
canon!"hello".fun("");
}
Looking at the generated html documentation, the declaration of canon is shown
first. Nested within is the example. Does this work properly with `make
publictests`?
--
More information about the Digitalmars-d-bugs
mailing list