Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

Version doctests

Open bramtayl opened this issue 5 years ago • 8 comments

Is there a mechanism to make doctests conditional on Julia version? Printing seems pretty unstable version to version

bramtayl avatar Jun 30 '19 15:06 bramtayl

Just set the doctest kwarg to be conditional?

makedocs(
    doctest = VERSION == v"1.0.0"
   ...
)

or w/e.

fredrikekre avatar Jun 30 '19 15:06 fredrikekre

I was hoping for something like:

doctest VERSION == this_version this printing

doctest VERSION == another_version another printing

bramtayl avatar Jun 30 '19 18:06 bramtayl

So you mean an argument to an jldoctest block? Technically it would be doable, but I am a bit sceptical whether this is a good idea. E.g. in docstrings, you'd then end up with multiple sets of doctests that all show up in the REPL.

I do think that it would be better to just target a single Julia version with the doctests, as Fredrik suggested. It's not even a problem to target the latest Julia -- updating all the doctests with the :fix option every few months is relatively painless.

mortenpi avatar Jun 30 '19 23:06 mortenpi

I'm mostly interested in this because I want to maintain support for both 1.0 and 1.1, and I run doctests as part of CI. Preferable the jldoctest block would only run and render on its matching julia version

bramtayl avatar Jul 01 '19 00:07 bramtayl

I'm mostly interested in this because I want to maintain support for both 1.0 and 1.1, and I run doctests as part of CI.

I would version guard that, so that you doctest only when the Julia version matches. I don't think you really gain much from testing the doctests with multiple Julia versions. If they work for one Julia version, everything is probably fine for all versions (I assume you still have normal tests that verify the APIs on all versions). Do you have a particular example where it would be likely that this assumption does not hold?

mortenpi avatar Jul 02 '19 06:07 mortenpi

I assume you still have normal tests that verify the APIs on all versions

Not usually. Or to put it another way, it's rare for me to write a test and then decide it wouldn't be useful for the user to see it. E.g. LightQuery.jl has an extensive tutorial which doubles as a doctest, as well as regular doc-string doctests, but no regular tests.

bramtayl avatar Jul 02 '19 12:07 bramtayl

Maybe a bit more generally, adding a condition under which doctests will run and display:

doctest condition = x -> VERSION == v"1.0"

bramtayl avatar Jul 07 '19 18:07 bramtayl

Eh, in newer packages, I've decided to only run doctests on latest julia, and replicate them all as regular tests. It's a little bit less elegant but more robust since printing changes so much between version. Maybe it would be nice to have a note in the docs about doctests being fragile.

bramtayl avatar Dec 05 '21 18:12 bramtayl