-
Notifications
You must be signed in to change notification settings - Fork 10
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
jldoctest support #15
Comments
Yes, some form of doctest-like feature does need to be added, thanks for opening this. It's worth taking some time to decide exactly how it should behave once actually implemented. I've never been 100% happy with how I've been playing around with the idea of turning the whole doctest feature on it's head a bit, i.e: write out the examples as module MyPackage
"""
# Examples
```jldoctest
a = 1
b = 2; # semi-colon would suppress output as usual
c = a + b
@test c == 3 # test lines wouldn't appear in the final output
```
"""
function foo end
#
doctest!(@__MODULE__) # or maybe just @doctest! would search docstrings in the module and
# expand and test them when precompiling the package.
end
# Examples
```julia-repl
julia> a = 1
1
julia> b = 2; # semi-colon would suppress output as usual
julia> c = a + b
3
``` Kind of a rough idea that's just in my head at the moment, so I've not really thought about the downsides of it yet. |
Nice, thanks for the response. That design looks great for examples in docstrings where we do some kind of check to indicate to the reader that "yes, this function returns the thing you think it returns." I would characterize that as about 40% of the I'm not entirely sure if there is value beyond testing custom |
Yeah, @test sprint(show, a) == "1" but with as much of that repetition abstracted away so that it doesn't actually get in the way of writing these things: """
```jldoctest
a = 1
@test_show a "1"
```
""" the nice thing about making it explicit is you aren't forced to test every value's |
I like how doctests currently work; I think copy-pasting can be avoided by Some annoyance can be avoided by running doctests only on one version of Julia (eg as part of building docs, with To me, something like |
Does Publish plan to support
jldoctest
blocks in docstrings? This is useful for making sure any examples can always run.The text was updated successfully, but these errors were encountered: