Extract runnables that specify doccmd (#19275) [backport:1.6]

(cherry picked from commit 4da7dbffc5)
This commit is contained in:
Jake Leahy
2021-12-21 03:29:03 +11:00
committed by narimiran
parent f2e7e5d899
commit ce6fa79858
2 changed files with 22 additions and 2 deletions

View File

@@ -1718,8 +1718,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

View File

@@ -66,3 +66,23 @@ block: # unpackVarargs
doAssert call1(toString) == ""
doAssert call1(toString, 10) == "10"
doAssert call1(toString, 10, 11) == "1011"
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