run runnableExamples in the module scope (#11732) [feature]

This commit is contained in:
Timothee Cour 2019-07-22 07:22:57 -07:00 • committed by Andreas Rumpf
commit 8c93c692b9
4 changed files with 81 additions and 17 deletions

View file

@ -128,7 +128,7 @@ when defined(nimHasRunnableExamples):
## a ``runnableExamples`` section is ignored.
## - The documentation generator is aware of these examples and considers them
## part of the ``##`` doc comment. As the last step of documentation
## generation the examples are put into an ``$file_example.nim`` file,
## generation each runnableExample is put in its own file ``$file_examples$i.nim``,
## compiled and tested. The collected examples are
## put into their own module to ensure the examples do not refer to
## non-exported symbols.
@ -136,12 +136,14 @@ when defined(nimHasRunnableExamples):
## Usage:
##
## .. code-block:: Nim
## proc double(x: int): int =
## proc double*(x: int): int =
## ## This proc doubles a number.
## runnableExamples:
## ## at module scope
## assert double(5) == 10
## assert double(21) == 42
##
## block: ## at block scope
## defer: echo "done"
##
## result = 2 * x
else:
template runnableExamples*(body: untyped) =