Thread overview
[Issue 18623] Documented unittest should not allow private symbol access
Mar 17, 2018
Alex
Mar 17, 2018
greenify
May 05, 2018
Nick Treleaven
May 06, 2018
greenify
Jul 02, 2018
greenify
Mar 08, 2022
Dlang Bot
Mar 10, 2022
RazvanN
Mar 10, 2022
Nick Treleaven
March 17, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

Alex <sascha.orlov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sascha.orlov@gmail.com

--
March 17, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

greenify <greeenify@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greeenify@gmail.com

--- Comment #1 from greenify <greeenify@gmail.com> ---
I agree though the compiler currently doesn't know whether the test is ddoc-ed when -D isn't passed. As it throws away all documentation text during parsing.

For Phobos we use a workaround which extracts all public tests and puts them in separate files and then executes them:

https://github.com/dlang/tools/blob/master/tests_extractor.d

--
March 18, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I would vote to close this as WONTFIX. You may want to test things inside your unit test that have nothing to do with the example, but use the same code for setup, and then you have to write that code twice. It's pretty easy to say // private data, for testing only.

--
May 05, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

--- Comment #3 from Nick Treleaven <nick@geany.org> ---
(In reply to Steven Schveighoffer from comment #2)
> You may want to test things inside
> your unit test that have nothing to do with the example, but use the same
> code for setup, and then you have to write that code twice.

If you really want your *documented* unittest not to be runnable by a user, you can wrap your private code in a free function with `protected` access as a workaround.

> It's pretty easy to say // private data, for testing only.

The whole point of this issue is for when the programmer is unaware that the documented example contains private symbols *unintentionally*. This is clearly a significant problem otherwise @greenify wouldn't have added a custom automated test for Phobos to check this. Copying and pasting from other tests is a classic trigger for this.

--
May 06, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I agree that can be a valid concern.

Let me restate that I would recommend if we do this, make it an opt-in switch.

--
May 06, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

--- Comment #5 from greenify <greeenify@gmail.com> ---
Andrei and Walter are not really keen on adding more and more cli switches. The unittest extraction pipeline is far from ideal, but it's probably the best we will get in this sector.

--
July 02, 2018
https://issues.dlang.org/show_bug.cgi?id=18623

--- Comment #6 from greenify <greeenify@gmail.com> ---
FWIW the tools extractor that is used by Phobos is now on dub:

https://code.dlang.org/packages/dtools

dub fetch dtools
dub run dtools:tests_extractor

--
March 08, 2022
https://issues.dlang.org/show_bug.cgi?id=18623

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #13783 "Fix Issue 18623 - Documented unittest should not allow private symbol access" fixing this issue:

- Fix Issue 18623 - Documented unittest should not allow private symbol access

https://github.com/dlang/dmd/pull/13783

--
March 10, 2022
https://issues.dlang.org/show_bug.cgi?id=18623

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WONTFIX

--- Comment #8 from RazvanN <razvan.nitu1305@gmail.com> ---
Closing as per comments in: https://github.com/dlang/dmd/pull/13783

--
March 10, 2022
https://issues.dlang.org/show_bug.cgi?id=18623

--- Comment #9 from Nick Treleaven <nick@geany.org> ---
>From the pull:

> If someone wants to document private symbols, why prevent it ? In the example, the documented unittest is attached to a private symbol, isn't it ?

If you want to support that unusual case, require private unittest to enable using private symbols in the documented test. (The documented unittest could even be inferred as private if the symbol it's documenting is private).

I would like to reopen this.

--