Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Add DocMeta.setdocmeta!(PkgName, :DocTestSetup, :(using PkgName); recursive=true) by default #232

Closed
terasakisatoshi opened this issue Sep 10, 2020 · 3 comments · Fixed by #244

Comments

@terasakisatoshi
Copy link
Contributor

As described in the documentation of Documenter.jl,
it is a good idea to add, by default, the expression DocMeta.setdocmeta!({{{PKG}}}, :DocTestSetup, :(using {{{PKG}}}); recursive=true) before doctest({{{PKG}}})
or inside of make.jl i.e.

using {{{PKG}}}
using Documenter

DocMeta.setdocmeta!({{{PKG}}}, :DocTestSetup, :(using {{{PKG}}}); recursive=true)

makedocs(;
    modules=[{{{PKG}}}],
...
...
...

This is required if one wants to run doctest of methods defined in one's Package (Say PkgName for example).

Assume PkgName.jl has a domath function (see the code below):

module PkgName

"""
    domath(x::Number)
Return `x + 5`.

```jldoctest
julia> domath(3)
8
```

"""
domath(x::Number) = x + 5

export domath

end

Both following commands will fail with a message ERROR: UndefVarError: domath not defined
if DocMeta.setdocmeta!(PkgName, :DocTestSetup, :(using PkgName); recursive=true) is missing.
`

$ julia --project=docs docs/make.jl
$ julia --project=docs -e '
  using Documenter: doctest
  using PkgName
  doctest(PkgName)'

Any ideas ?

@christopher-dG
Copy link
Member

I didn't know this existed, it looks really useful! A PR would be welcome. 🙂

@simeonschaub
Copy link
Collaborator

Both following commands will fail with a message ERROR: UndefVarError: domath not defined
if DocMeta.setdocmeta!(PkgName, :DocTestSetup, :(using PkgName); recursive=true) is missing.
`

$ julia --project=docs docs/make.jl
$ julia --project=docs -e '
  using Documenter: doctest
  using PkgName
  doctest(PkgName)'

Any ideas ?

Yes, the second example is not using docs/make.jl at all, so you either need to do DocMeta.setdocmeta! there as well, or figure out a way to pass an argument to make.jl, that will make it run only the doctest.

@terasakisatoshi
Copy link
Contributor Author

Thank you everyone.

I'll make a PR to add

DocMeta.setdocmeta!({{{PKG}}}, :DocTestSetup, :(using {{{PKG}}}); recursive=true) before doctest({{{PKG}}})

(and also modify test script to pass this PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants