* fixes #20132; fixes the broken jsondoc comand * add testcase
This commit is contained in:
parent
7af484da94
commit
2aeb0d516b
3 changed files with 30 additions and 1 deletions
|
|
@ -1360,9 +1360,10 @@ proc finishGenerateDoc*(d: var PDoc) =
|
||||||
var str: string
|
var str: string
|
||||||
renderRstToOut(d[], resolved, str)
|
renderRstToOut(d[], resolved, str)
|
||||||
entry.json[entry.rstField] = %str
|
entry.json[entry.rstField] = %str
|
||||||
d.jEntriesFinal.add entry.json
|
|
||||||
d.jEntriesPre[i].rst = nil
|
d.jEntriesPre[i].rst = nil
|
||||||
|
|
||||||
|
d.jEntriesFinal.add entry.json # generates docs
|
||||||
|
|
||||||
proc add(d: PDoc; j: JsonItem) =
|
proc add(d: PDoc; j: JsonItem) =
|
||||||
if j.json != nil or j.rst != nil: d.jEntriesPre.add j
|
if j.json != nil or j.rst != nil: d.jEntriesPre.add j
|
||||||
|
|
||||||
|
|
|
||||||
11
tests/misc/mjsondoc.nim
Normal file
11
tests/misc/mjsondoc.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
proc doSomething*(x, y: int): int =
|
||||||
|
## do something
|
||||||
|
x + y
|
||||||
|
|
||||||
|
const
|
||||||
|
a* = 1 ## echo 1234
|
||||||
|
b* = "test"
|
||||||
|
|
||||||
|
type
|
||||||
|
MyEnum* = enum
|
||||||
|
foo, bar
|
||||||
|
|
@ -216,6 +216,23 @@ sub/mmain.idx""", context
|
||||||
let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}"
|
let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}"
|
||||||
check execCmdEx(cmd) == ("ok3\n", 0)
|
check execCmdEx(cmd) == ("ok3\n", 0)
|
||||||
|
|
||||||
|
block: # nim jsondoc # bug #20132
|
||||||
|
let file = testsDir / "misc/mjsondoc.nim"
|
||||||
|
let output = "nimcache_tjsondoc.json"
|
||||||
|
defer: removeFile(output)
|
||||||
|
let (msg, exitCode) = execCmdEx(fmt"{nim} jsondoc -o:{output} {file}")
|
||||||
|
doAssert exitCode == 0, msg
|
||||||
|
|
||||||
|
let data = parseJson(readFile(output))["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`
|
block: # further issues with `--backend`
|
||||||
let file = testsDir / "misc/mbackend.nim"
|
let file = testsDir / "misc/mbackend.nim"
|
||||||
var cmd = fmt"{nim} doc -b:cpp --hints:off --nimcache:{nimcache} {file}"
|
var cmd = fmt"{nim} doc -b:cpp --hints:off --nimcache:{nimcache} {file}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue