mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Extract runnables that specify doccmd (#19275) [backport:1.6]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user