Doctest error

Hi, I made my first steps with Documenter.jl and now wanted to set up some doctests but I’m failing on the first one and for a reason that makes no sense to me. The following test

jldoctest
julia> cpt = makecpt(range="-1/1/0.1");
#julia> (size(cpt.colormap,1) == 20) && (cpt.colormap[1,:] == [0.875, 0.0, 1.0])
#true

"""
# ---------------------------------------------------------------------------------------------------
function makecpt(cmd0::String="", arg1=[]; data=[], kwargs...)
...

fails with

> Subexpression:

    cpt = makecpt(range="-1/1/0.1");

> Output Diff:

ERROR: UndefVarError: makecpt not defined

which is obviously (?) wrong because the makecpt() function follows right bellow the mentioned test. And the test passes if I run it the REPL.

I’m guessing, but I think you are missing a using MyModule (which must be explicit in order for Documenter to use it). This can be put in a DocTestSetup block, see Doctests · Documenter.jl

Something like:

```@meta
DocTestSetup = quote
    using MyModule
end
```

at the top of the file you are including your docstrings should do the trick.

1 Like

Thanks, I see the point but it made no difference. Still errors.

Is makecpt exported? It is a bit hard to see whats wrong with no context…

I am following the recipe in the Documenter.jl. I run the make that loads the GMT module that exports makecpt and other functions. That is why the DocTestSetup above should not be needed.

When the make ends I can run the example in the REPL and it works fine.

Doctests are not evaluated in your REPL, they are evaluated in separate modules, so my first post is the solution. You didn’t even try it? …

Off course I tried. Said so two posts above. And I know the doctest is not run in the REPL, only mentioned it to emphasize that the testing command is OK.

Well, if you did what I said it, then it does indeed work:

1 Like

1- Thanks for solving this.

2- I had done it but in the makecpt.jl file and not in index.md

3- But there is more to it. If I keep it without an empty line in the jldoctest, as in

julia> cpt = makecpt(range="-1/1/0.1");
julia> (size(cpt.colormap,1) == 20) && (cpt.colormap[1,:] == [0.875, 0.0, 1.0])
true

than it still errors, but it’s complicated to see because running the make.jl fails one every other run (and it starts by failing). Next runs only show the ERROR: LoadError: stat: operation not permitted (EPERM) one yes one no but no more doctest error.

julia> cd(Pkg.dir("GMT") * "/docs")

julia> include("make.jl")
Documenter: setting up build directory.
ERROR: LoadError: stat: operation not permitted (EPERM)
Stacktrace:
 [1] stat(::String) at .\stat.jl:69
 [2] isdir at .\stat.jl:279 [inlined]
 [3] runner(::Type{Documenter.Builder.SetupBuildDirectory}, ::Documenter.Documents.Document) at c:\j\.julia\v0.6\Documenter\src\Builder.jl:90
 [4] dispatch(::Type{Documenter.Builder.DocumentPipeline}, ::Documenter.Documents.Document) at c:\j\.julia\v0.6\Documenter\src\Selectors.jl:164
 [5] cd(::Documenter.##2#3{Documenter.Documents.Document}, ::String) at .\file.jl:59
 [6] #makedocs#1(::Bool, ::Array{Any,1}, ::Function) at c:\j\.julia\v0.6\Documenter\src\Documenter.jl:198
 [7] (::Documenter.#kw##makedocs)(::Array{Any,1}, ::Documenter.#makedocs) at .\<missing>:0
 [8] include_from_node1(::String) at .\loading.jl:569
 [9] include(::String) at .\sysimg.jl:14
while loading c:\j\.julia\v0.6\GMT\docs\make.jl, in expression starting on line 3

julia> include("make.jl")
Documenter: setting up build directory.
Documenter: expanding markdown templates.
Documenter: building cross-references.
Documenter: running document checks.
 > checking for missing docstrings.
 !! 3 docstrings potentially missing:

    GMT.get_GMTversion :: Tuple{Ptr{Void}}
    GMT.gmt :: Tuple{String,Vararg{Any,N} where N}
    GMT.grid_type :: Union{Tuple{Any,Any}, Tuple{Any}}

 > running doctests.
=====[Test Error]==============================

> File: c:\j\.julia\v0.6\GMT\src\makecpt.jl

> Code block:

```jldoctest
julia> cpt = makecpt(range="-1/1/0.1");
julia> (size(cpt.colormap,1) == 20) && (cpt.colormap[1,:] == [0.875, 0.0, 1.0])
true

Subexpression:

(size(cpt.colormap,1) == 20) && (cpt.colormap[1,:] == [0.875, 0.0, 1.0])

Output Diff:

ERROR: UndefVarError: cpt = makecpt(range=“-1/1/0.1”);not defined

=====[End Error]===============================

checking footnote links.
Documenter: populating indices.
Documenter: rendering document.
Documenter: skipping docs deployment.
You can set DOCUMENTER_DEBUG to “true” in Travis to see more information.

julia>