# Doctest error

**URL:** <https://discourse.julialang.org/t/doctest-error/6366>\
**Category:** General Usage\
**Created:** [October 9, 2017, 10:04pm UTC](https://discourse.julialang.org/t/doctest-error/6366 "2017-10-09T22:04:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 9, 2017, 10:04pm UTC](https://discourse.julialang.org/t/doctest-error/6366/1 "2017-10-09T22:04:40Z")

</div>

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

```julia
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

```julia
> 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.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 10, 2017, 5:34am UTC](https://discourse.julialang.org/t/doctest-error/6366/2 "2017-10-10T05:34:49Z")

</div>

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](https://juliadocs.github.io/Documenter.jl/latest/man/doctests/#Setup-Code-1)

Something like:

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

````

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

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 10, 2017, 1:40pm UTC](https://discourse.julialang.org/t/doctest-error/6366/3 "2017-10-10T13:40:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 10, 2017, 2:15pm UTC](https://discourse.julialang.org/t/doctest-error/6366/4 "2017-10-10T14:15:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 10, 2017, 2:23pm UTC](https://discourse.julialang.org/t/doctest-error/6366/5 "2017-10-10T14:23:04Z")

</div>

I am following the recipe in the Documenter.jl. I run the [make](https://github.com/GenericMappingTools/GMT.jl/blob/master/docs/make.jl) that loads the [GMT](https://github.com/GenericMappingTools/GMT.jl/blob/master/src/GMT.jl) 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.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 10, 2017, 5:46pm UTC](https://discourse.julialang.org/t/doctest-error/6366/6 "2017-10-10T17:46:42Z")

</div>

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? …

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 10, 2017, 6:38pm UTC](https://discourse.julialang.org/t/doctest-error/6366/7 "2017-10-10T18:38:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 10, 2017, 7:23pm UTC](https://discourse.julialang.org/t/doctest-error/6366/8 "2017-10-10T19:23:15Z")

</div>

> [@joa-quim](#):
>
> Off course I tried. Said so two posts above.

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

> <https://github.com/GenericMappingTools/GMT.jl/pull/10>
>
> xref https://discourse.julialang.org/t/doctest-error/6366

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [October 10, 2017, 8:09pm UTC](https://discourse.julialang.org/t/doctest-error/6366/9 "2017-10-10T20:09:32Z")

</div>

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

```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

```

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
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\>

```julia

```
