朱莉娅:我可以在没有“makedocs”的情况下运行doctests吗?

时间:2018-06-08 15:02:38

标签: testing julia

我正在启动Julia模块,并且更喜欢仅使用doctests并在此阶段跳过文档。 Julia doctest documentationmakedocs可以运行doctests:

  

可以通过设置makedocs关键字doctest = false.

来停用文档测试

它没有提到运行doctests的其他方法。 Julia是否提供任何其他方式来运行类似于Python import doctestdoctest.testmod()的doctests?

注意:以下是一个示例函数:

"""
month_to_quarter(date::Date)

Returns the date corresponding to the first day of the quarter enclosing date

#Examples
```jldoctest
julia> Date(1990, 1, 1) == month_to_quarter(Date(1990, 2, 1))
true
julia> Date(1990, 1, 1) == month_to_quarter(Date(1990, 1, 1))
true
julia> Date(1990, 1, 1) == month_to_quarter(Date(1990, 2, 25))
true
```
"""
function month_to_quarter(date::Date)
    new_month = 1 + 3 * floor((Dates.month(date) - 1) / 3)
    return Date(Dates.year(date), new_month, 1)
end

2 个答案:

答案 0 :(得分:1)

发表我的评论作为答案:

否,目前尚无法实现,但是对于Documenter.jl的未来版本,我们有类似的想法。不过,我想指出的是,即使您不打算部署生成的文档,设置一个简单的文档环境并使用makedocs运行doctest还是很容易的。有关简单的设置,请参见此评论:Julia Documenter: missing docstring

答案 1 :(得分:1)

为了记录,this is now supported。只需将此添加到 runtests.jl

using Test, Documenter, MyPackage
doctest(MyPackage)

请注意,如果您的 Project.toml 目录中有单独的 test,则需要 add Documenter。此外,如果您的 docs/make.jl 文件中有设置代码,则需要将其复制并放在调用 doctest 之前。