Skip to content

Commit

Permalink
Extract runnables that specify doccmd (nim-lang#19275) [backport:1.6]
Browse files Browse the repository at this point in the history
  • Loading branch information
ire4ever1190 authored and PMunch committed Mar 28, 2022
1 parent 54c505e commit 8fc36e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1715,8 +1715,8 @@ proc extractDocCommentsAndRunnables*(n: NimNode): NimNode =
case ni.kind
of nnkCommentStmt:
result.add ni
of nnkCall:
if ni[0].kind == nnkIdent and ni[0].strVal == "runnableExamples":
of nnkCall, nnkCommand:
if ni[0].kind == nnkIdent and ni[0].eqIdent "runnableExamples":
result.add ni
else: break
else: break
20 changes: 20 additions & 0 deletions tests/stdlib/tmacros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,23 @@ block: # SameType
assert not testTensorInt(x1)
assert testTensorInt(x2)
assert not testTensorInt(x3)

block: # extractDocCommentsAndRunnables
macro checkRunnables(prc: untyped) =
let runnables = prc.body.extractDocCommentsAndRunnables()
doAssert runnables[0][0].eqIdent("runnableExamples")

macro checkComments(comment: static[string], prc: untyped) =
let comments = prc.body.extractDocCommentsAndRunnables()
doAssert comments[0].strVal == comment

proc a() {.checkRunnables.} =
runnableExamples: discard
discard

proc b() {.checkRunnables.} =
runnableExamples "-d:ssl": discard
discard

proc c() {.checkComments("Hello world").} =
## Hello world

0 comments on commit 8fc36e7

Please sign in to comment.