Skip to content

Commit

Permalink
fixes nim-lang#11953; jsondoc creates no files unless the htmldocs di…
Browse files Browse the repository at this point in the history
…r is created (nim-lang#20198)

* fixes nim-lang#11953; jsondoc creates no files unless the htmldocs dir is created

* target

* fixes runner
  • Loading branch information
ringabout authored and capocasa committed Mar 31, 2023
1 parent b829ed9 commit 5c9133e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ proc writeOutputJson*(d: PDoc, useWarning = false) =
if optStdout in d.conf.globalOptions:
write(stdout, $content)
else:
let dir = d.destFile.splitFile.dir
createDir(dir)
var f: File
if open(f, d.destFile, fmWrite):
write(f, $content)
Expand Down
16 changes: 16 additions & 0 deletions tests/misc/trunner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ sub/mmain.idx""", context
doAssert doSomething["col"].getInt == 0
doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}"

block: # nim jsondoc # bug #11953
let file = testsDir / "misc/mjsondoc.nim"
let destDir = testsDir / "misc/htmldocs"
removeDir(destDir)
defer: removeDir(destDir)
let (msg, exitCode) = execCmdEx(fmt"{nim} jsondoc {file}")
doAssert exitCode == 0, msg

let data = parseJson(readFile(destDir / "mjsondoc.json"))["entries"]
doAssert data.len == 4
let doSomething = data[0]
doAssert doSomething["name"].getStr == "doSomething"
doAssert doSomething["type"].getStr == "skProc"
doAssert doSomething["line"].getInt == 1
doAssert doSomething["col"].getInt == 0
doAssert doSomething["code"].getStr == "proc doSomething(x, y: int): int {.raises: [], tags: [], forbids: [].}"

block: # further issues with `--backend`
let file = testsDir / "misc/mbackend.nim"
Expand Down

0 comments on commit 5c9133e

Please sign in to comment.