Doctests all variables "variable not found"

I’m stuck trying to run doctests; it seems that the module isn’t being loaded, but I’ve included what I think is the appropriate meta DocTestSetup block. I’ve been banging my head against this on and off for months, so any suggestions would be greatly appreciated. edit: When I try, e.g. Simulation73.extent I also get Simulation73 is not defined.

# docs/make.jl
using Documenter, Simulation73
  
makedocs(
    sitename="Simulation73",
    modules=[Simulation73],
    pages = [
       "Home" => "index.md",
       "Manual" => Any[
           "man/simulation.md"
       ],
       "Library" => Any[
           "Public" => "lib/public.md",
           hide("Internals" => "lib/internals.md",
            Any[joinpath("lib/internals", f) for f in readdir("docs/src/lib/internals")]
           )
       ]
   ]
)

deploydocs(
    repo = "github.com/grahamas/Simulation73.git"
)
# docs/src/index.md
# Simulation73 Documentation
  
``@meta
DocTestSetup = quote
    using Simulation73
end
``

## Manual

``@contents
Pages = joinpath.("man", ["simulation.md"])
``

## Library Documentation

``@contents
Pages = joinpath.("lib", ["public.md", "internals.md"])
``
# test/runtests.jl
using Test, Documenter, Simulation73
doctest(Simulation73)

When run, the test returns all errored because no variables defined in Simulation73 exist. T̶h̶e̶ ̶p̶r̶o̶b̶l̶e̶m̶ ̶i̶s̶ ̶f̶i̶x̶e̶d̶ ̶b̶y̶ ̶q̶u̶a̶l̶i̶f̶y̶i̶n̶g̶ ̶a̶l̶l̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶s̶ ̶(̶e̶.̶g̶.̶ ̶̶S̶i̶m̶u̶l̶a̶t̶i̶o̶n̶7̶3̶.̶e̶x̶t̶e̶n̶t̶̶)̶,̶ ̶b̶u̶t̶ ̶I̶’̶d̶ ̶r̶e̶a̶l̶l̶y̶ ̶r̶a̶t̶h̶e̶r̶ ̶n̶o̶t̶.̶

It works just as in the REPL, if Simulation73 does not export the names you want, then you need to qualify.

2 Likes

Ah sorry I wasn’t clear (and I was wrong): I am exporting the names I want, and I have tested:

> activate ~/git/Simulation73/docs
> using Simulation73
> extent
extent (generic function with 1 method)

In fact, it doesn’t work with qualification. When I just tried to qualify, I get Simulation73 is not defined. (I think that was a previous iteration of this problem where I was able to qualify, and I assumed it was still true)

If you have your doctests in docstrings you might need to add the doctestmeta as described here: Doctests · Documenter.jl

2 Likes

That works! Thank you so much!

edit: If someone else runs into the problem that docs/make.jl works but ]test does not, don’t forget that you need the same setdocmeta! line in your test/runtests.jl as you had in your docs/make.jl.