Skip to content

Commit 6d3e337

Browse files
authored
Added documentation for doctests (#17825)
The manual entry for doctests was way out of date! Updated with an example of what to do.
1 parent 1280a1d commit 6d3e337

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

doc/manual/documentation.rst

+20-5
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,29 @@ documentation:
9999
...
100100
"""
101101

102-
5. Group examples under an ``# Examples`` section and use ````julia`` blocks instead of
102+
5. Group examples under an ``# Examples`` section and use `````julia`` blocks instead of
103103
standard text.
104104

105105
Examples should consist of verbatim copies of the Julia REPL, including the ``julia>``
106-
prompt (see example above). This will be used in the future to allow running examples
107-
automatically and checking that their actual output is consistent with that presented
108-
in the documentation (a feature called *doctests*). This way, the code will be tested and
109-
examples won't get out of date without notice.
106+
prompt (see example above). This is used to allow running examples automatically and
107+
checking that their actual output is consistent with that presented in the
108+
documentation (a feature called *doctests*). This way, the code will be tested and
109+
examples won't get out of date without notice. An example::
110+
111+
"""
112+
Some nice documentation here.
113+
114+
```jldoctest
115+
julia> a = [1 2; 3 4]
116+
2×2 Array{Int64,2}:
117+
1 2
118+
3 4
119+
```
120+
"""
121+
122+
You can then run ``make -C doc doctest`` to run all the doctests, which will ensure
123+
that your example works. Note that whitespace in your doctest is significant! The
124+
doctest will fail if you misalign the output of pretty-printing an array, for example.
110125

111126
6. Use backticks to identify code and equations.
112127

0 commit comments

Comments
 (0)