Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jul 15, 2019
1 parent 690a1d2 commit 52adcde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ proc defined*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.}
## # Put here the normal code

when defined(nimHasRunnableExamples):
proc runnableExamples*(body: untyped) {.magic: "RunnableExamples".}
proc runnableExamples*(topLevel: bool, body: untyped) {.magic: "RunnableExamples".}
proc runnableExamples*(topLevel = true, body: untyped) {.magic: "RunnableExamples".}
## A section you should use to mark `runnable example`:idx: code with.
##
## - In normal debug and release builds code within
Expand Down
19 changes: 10 additions & 9 deletions tests/magics/trunnableexamples.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,38 @@ foo5
foo6
foo7
foo8
foo9
'''
joinable: false
"""

proc fun*() =
runnableExamples(topLevel=false):
# `defer` only allowed inside a block
defer: echo "foo2"
defer: echo "foo1"

runnableExamples(topLevel=true):
# `fun*` only allowed at top level
proc fun*()=echo "foo3"
proc fun*()=echo "foo2"
fun()
block:
defer: echo "foo4"
defer: echo "foo3"

runnableExamples:
# implicitly uses topLevel=true
proc fun*()=echo "foo3"
proc fun*()=echo "foo4"
fun()

runnableExamples():
# ditto
proc fun*()=echo "foo3"
proc fun*()=echo "foo5"
fun()

runnableExamples:
# `codeReordering` only allowed at top level
{.experimental: "codeReordering".}
proc fun1() = fun2()
proc fun2() = echo "foo5"
proc fun2() = echo "foo6"
fun1()

runnableExamples:
Expand All @@ -50,14 +51,14 @@ proc fun*() =
newTree(nnkImportStmt, [newLit a])
myImport "str" & "utils"
doAssert declared(isAlphaAscii)
echo "foo6"
echo "foo7"

# also check for runnableExamples at module scope
runnableExamples(topLevel=false):
defer: echo "foo7"
defer: echo "foo8"

runnableExamples:
proc fun*()=echo "foo8"
proc fun*()=echo "foo9"
fun()

# note: there are yet other examples where `topLevel=true` is needed,
Expand Down

0 comments on commit 52adcde

Please sign in to comment.