diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 968a955f6b..c38b9b87ce 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -31,7 +31,7 @@ type
isPureRst: bool
conf*: ConfigRef
cache*: IdentCache
- runnableExamples*: PNode
+ exampleCounter: int
PDoc* = ref TDocumentor ## Alias to type less.
@@ -285,29 +285,26 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
dispA(d.conf, result, "$1", "\\spanOther{$1}",
[rope(esc(d.target, literal))])
-proc testExamples*(d: PDoc) =
- if d.runnableExamples == nil or d.conf.errorCounter > 0: return
+proc testExample(d: PDoc; ex: PNode) =
+ if d.conf.errorCounter > 0: return
let outputDir = d.conf.getNimcacheDir / "runnableExamples"
createDir(outputDir)
- let inp = toFullPath(d.conf, d.runnableExamples.info)
- let outp = outputDir / extractFilename(inp.changeFileExt"" & "_examples.nim")
- let nimcache = outp.changeFileExt"" & "_nimcache"
- renderModule(d.runnableExamples, inp, outp, conf = d.conf)
+ inc d.exampleCounter
+ let outp = outputDir / extractFilename(d.filename.changeFileExt"" &
+ "_examples" & $d.exampleCounter & ".nim")
+ #let nimcache = outp.changeFileExt"" & "_nimcache"
+ renderModule(ex, d.filename, outp, conf = d.conf)
let backend = if isDefined(d.conf, "js"): "js"
elif isDefined(d.conf, "cpp"): "cpp"
elif isDefined(d.conf, "objc"): "objc"
else: "c"
if os.execShellCmd(os.getAppFilename() & " " & backend &
- " --nimcache:" & nimcache & " -r " & outp) != 0:
+ " --nimcache:" & outputDir & " -r " & outp) != 0:
quit "[Examples] failed: see " & outp
else:
# keep generated source file `outp` to allow inspection.
rawMessage(d.conf, hintSuccess, ["runnableExamples: " & outp])
removeFile(outp.changeFileExt(ExeExt))
- try:
- removeDir(nimcache)
- except OSError:
- discard
proc extractImports(n: PNode; result: PNode) =
if n.kind in {nkImportStmt, nkImportExceptStmt, nkFromStmt}:
@@ -317,16 +314,15 @@ proc extractImports(n: PNode; result: PNode) =
for i in 0..