nim doc --backend:js, nim doc --doccmd:-d:foo, nim r --backend:js, --doccmd:skip + other improvements (#14278)

* `nim doc --backend:js|cpp...`
`nim doc --doccmd:'-d:foo --threads:on'`
`nim r --backend:cpp...` (implies --run --usenimcache)
* --usenimcache works with all targets
* --docCmd:skip now skips compiling snippets; 50X speedup for doc/manual.rst
This commit is contained in:
Timothee Cour 2020-05-11 03:01:18 -07:00 • committed by GitHub
commit 9502e39b63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 213 additions and 99 deletions

View file

@ -6,7 +6,7 @@ discard """
## tests that don't quite fit the mold and are easier to handle via `execCmdEx`
## A few others could be added to here to simplify code.
import std/[strformat,os,osproc]
import std/[strformat,os,osproc,unittest]
const nim = getCurrentCompilerExe()
@ -15,8 +15,9 @@ const mode =
elif defined(cpp): "cpp"
else: static: doAssert false
const testsDir = currentSourcePath().parentDir
proc runCmd(file, options = ""): auto =
const testsDir = currentSourcePath().parentDir
let fileabs = testsDir / file.unixToNativePath
doAssert fileabs.existsFile, fileabs
let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs}"
@ -55,11 +56,11 @@ ret=[s1:foobar s2:foobar age:25 pi:3.14]
else: # don't run twice the same test
import std/[strutils]
template check(msg) = doAssert msg in output, output
template check2(msg) = doAssert msg in output, output
block: # mstatic_assert
let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad")
check "sizeof(bool) == 2"
check2 "sizeof(bool) == 2"
doAssert exitCode != 0
block: # ABI checks
@ -72,11 +73,11 @@ else: # don't run twice the same test
# on platforms that support _StaticAssert natively, errors will show full context, eg:
# error: static_assert failed due to requirement 'sizeof(unsigned char) == 8'
# "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]"
check "sizeof(unsigned char) == 8"
check "sizeof(struct Foo2) == 1"
check "sizeof(Foo5) == 16"
check "sizeof(Foo5) == 3"
check "sizeof(struct Foo6) == "
check2 "sizeof(unsigned char) == 8"
check2 "sizeof(struct Foo2) == 1"
check2 "sizeof(Foo5) == 16"
check2 "sizeof(Foo5) == 3"
check2 "sizeof(struct Foo6) == "
doAssert exitCode != 0
import streams
@ -103,3 +104,21 @@ else: # don't run twice the same test
var (output, exitCode) = execCmdEx(cmd)
output.stripLineEnd
doAssert output == expected
block: # nim doc --backend:$backend --doccmd:$cmd
# test for https://github.com/nim-lang/Nim/issues/13129
# test for https://github.com/nim-lang/Nim/issues/13891
const buildDir = testsDir.parentDir / "build"
const nimcache = buildDir / "nimcacheTrunner"
# `querySetting(nimcacheDir)` would also be possible, but we thus
# avoid stomping on other parallel tests
let file = testsDir / "nimdoc/m13129.nim"
for backend in fmt"{mode} js".split:
let cmd = fmt"{nim} doc -b:{backend} --nimcache:{nimcache} -d:m13129Foo1 --doccmd:'-d:m13129Foo2 --hints:off' --usenimcache --hints:off {file}"
check execCmdEx(cmd) == (&"ok1:{backend}\nok2: backend: {backend}\n", 0)
# checks that --usenimcache works with `nim doc`
check fileExists(nimcache / "m13129.html")
block: # mak sure --backend works with `nim r`
let cmd = fmt"{nim} r --backend:{mode} --hints:off --nimcache:{nimcache} {file}"
check execCmdEx(cmd) == ("ok3\n", 0)