added a test for 'nim doc'
This commit is contained in:
parent
86556ebfdb
commit
b017138c32
10 changed files with 2696 additions and 7 deletions
|
|
@ -51,3 +51,4 @@ script:
|
||||||
- ./koch csource
|
- ./koch csource
|
||||||
- ./koch nimsuggest
|
- ./koch nimsuggest
|
||||||
- nim c -r nimsuggest/tester
|
- nim c -r nimsuggest/tester
|
||||||
|
- nim c -r nimdoc/tester
|
||||||
|
|
|
||||||
|
|
@ -670,12 +670,12 @@ proc traceDeps(d: PDoc, it: PNode) =
|
||||||
let full = AbsoluteFile toFullPath(d.conf, FileIndex it.sym.position)
|
let full = AbsoluteFile toFullPath(d.conf, FileIndex it.sym.position)
|
||||||
let tmp = getOutFile2(d.conf, full.relativeTo(d.conf.projectPath), HtmlExt,
|
let tmp = getOutFile2(d.conf, full.relativeTo(d.conf.projectPath), HtmlExt,
|
||||||
RelativeDir"htmldocs")
|
RelativeDir"htmldocs")
|
||||||
let external = relativeTo(tmp, d.thisDir, '/')
|
let external = relativeTo(tmp, d.thisDir, '/').string
|
||||||
if d.section[k] != nil: add(d.section[k], ", ")
|
if d.section[k] != nil: add(d.section[k], ", ")
|
||||||
dispA(d.conf, d.section[k],
|
dispA(d.conf, d.section[k],
|
||||||
"<a class=\"reference external\" href=\"$2\">$1</a>",
|
"<a class=\"reference external\" href=\"$2\">$1</a>",
|
||||||
"$1", [rope esc(d.target, it.sym.name.s),
|
"$1", [rope esc(d.target, changeFileExt(external, "")),
|
||||||
rope changeFileExt(external, "html").string])
|
rope changeFileExt(external, "html")])
|
||||||
|
|
||||||
proc generateDoc*(d: PDoc, n: PNode) =
|
proc generateDoc*(d: PDoc, n: PNode) =
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ proc fileInfoKnown*(conf: ConfigRef; filename: AbsoluteFile): bool =
|
||||||
canon: AbsoluteFile
|
canon: AbsoluteFile
|
||||||
try:
|
try:
|
||||||
canon = canonicalizePath(conf, filename)
|
canon = canonicalizePath(conf, filename)
|
||||||
except:
|
except OSError:
|
||||||
canon = filename
|
canon = filename
|
||||||
result = conf.m.filenameToIndexTbl.hasKey(canon.string)
|
result = conf.m.filenameToIndexTbl.hasKey(canon.string)
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ proc fileInfoIdx*(conf: ConfigRef; filename: AbsoluteFile; isKnownFile: var bool
|
||||||
try:
|
try:
|
||||||
canon = canonicalizePath(conf, filename)
|
canon = canonicalizePath(conf, filename)
|
||||||
shallow(canon.string)
|
shallow(canon.string)
|
||||||
except:
|
except OSError:
|
||||||
canon = filename
|
canon = filename
|
||||||
# The compiler uses "filenames" such as `command line` or `stdin`
|
# The compiler uses "filenames" such as `command line` or `stdin`
|
||||||
# This flag indicates that we are working with such a path here
|
# This flag indicates that we are working with such a path here
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ proc relativeTo(full, base: string; sep = DirSep): string =
|
||||||
when true:
|
when true:
|
||||||
proc eqImpl(x, y: string): bool =
|
proc eqImpl(x, y: string): bool =
|
||||||
when FileSystemCaseSensitive:
|
when FileSystemCaseSensitive:
|
||||||
result = toLowerAscii(canon x) == toLowerAscii(canon y)
|
result = cmpIgnoreCase(canon x, canon y) == 0
|
||||||
else:
|
else:
|
||||||
result = canon(x) == canon(y)
|
result = canon(x) == canon(y)
|
||||||
|
|
||||||
|
|
@ -251,4 +251,5 @@ when isMainModule and defined(posix):
|
||||||
doAssert relativeTo("", "/users/moo") == ""
|
doAssert relativeTo("", "/users/moo") == ""
|
||||||
doAssert relativeTo("foo", "") == "foo"
|
doAssert relativeTo("foo", "") == "foo"
|
||||||
|
|
||||||
echo string(AbsoluteDir"/Users/me///" / RelativeFile"z.nim")
|
doAssert AbsoluteDir"/Users/me///" / RelativeFile"z.nim" == AbsoluteFile"/Users/me/z.nim"
|
||||||
|
doAssert relativeTo("/foo/bar.nim", "/foo/") == "bar.nim"
|
||||||
|
|
|
||||||
29
nimdoc/tester.nim
Normal file
29
nimdoc/tester.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Small program that runs the test cases for 'nim doc'.
|
||||||
|
|
||||||
|
import strutils, os
|
||||||
|
|
||||||
|
var
|
||||||
|
failures = 0
|
||||||
|
|
||||||
|
proc test(dir: string; fixup = false) =
|
||||||
|
putEnv("SOURCE_DATE_EPOCH", "100000")
|
||||||
|
if execShellCmd("nim doc --project -o:$1/htmldocs $1/testproject.nim" % dir) != 0:
|
||||||
|
quit("FAILURE: nim doc failed")
|
||||||
|
|
||||||
|
for expected in walkDirRec(dir / "expected/"):
|
||||||
|
let produced = expected.replace("/expected/", "/htmldocs/")
|
||||||
|
if not fileExists(produced):
|
||||||
|
echo "FAILURE: files not found: ", produced
|
||||||
|
inc failures
|
||||||
|
elif readFile(expected) != readFile(produced):
|
||||||
|
echo "FAILURE: files differ: ", produced
|
||||||
|
discard execShellCmd("diff -uNdr " & expected & " " & produced)
|
||||||
|
inc failures
|
||||||
|
if fixup:
|
||||||
|
copyFile(produced, expected)
|
||||||
|
else:
|
||||||
|
echo "SUCCESS: files identical: ", produced
|
||||||
|
removeDir(dir / "htmldocs")
|
||||||
|
|
||||||
|
test("nimdoc/testproject", false)
|
||||||
|
if failures > 0: quit($failures & " failures occurred.")
|
||||||
1299
nimdoc/testproject/expected/subdir/subdir_b/utils.html
Normal file
1299
nimdoc/testproject/expected/subdir/subdir_b/utils.html
Normal file
File diff suppressed because it is too large
Load diff
1331
nimdoc/testproject/expected/testproject.html
Normal file
1331
nimdoc/testproject/expected/testproject.html
Normal file
File diff suppressed because it is too large
Load diff
7
nimdoc/testproject/subdir/subdir_b/utils.nim
Normal file
7
nimdoc/testproject/subdir/subdir_b/utils.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
type
|
||||||
|
SomeType* = int
|
||||||
|
|
||||||
|
proc someType*(): SomeType =
|
||||||
|
## constructor.
|
||||||
|
SomeType(2)
|
||||||
21
nimdoc/testproject/testproject.nim
Normal file
21
nimdoc/testproject/testproject.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
import subdir / subdir_b / utils
|
||||||
|
|
||||||
|
## This is the top level module.
|
||||||
|
runnableExamples:
|
||||||
|
doAssert bar(3, 4) == 7
|
||||||
|
foo(1, 2)
|
||||||
|
|
||||||
|
|
||||||
|
template foo*(a, b: SomeType) =
|
||||||
|
## This does nothing
|
||||||
|
##
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc bar*[T](a, b: T): T =
|
||||||
|
result = a + b
|
||||||
|
|
||||||
|
import std/macros
|
||||||
|
|
||||||
|
macro bar*(): untyped =
|
||||||
|
result = newStmtList()
|
||||||
0
nimdoc/testproject/testproject.nimble
Normal file
0
nimdoc/testproject/testproject.nimble
Normal file
Loading…
Add table
Add a link
Reference in a new issue