added a test for 'nim doc'

This commit is contained in:
Andreas Rumpf
2018-09-07 13:13:35 +02:00
committed by Araq
parent 86556ebfdb
commit b017138c32
10 changed files with 2696 additions and 7 deletions

View File

@@ -51,3 +51,4 @@ script:
- ./koch csource
- ./koch nimsuggest
- nim c -r nimsuggest/tester
- nim c -r nimdoc/tester

View File

@@ -670,12 +670,12 @@ proc traceDeps(d: PDoc, it: PNode) =
let full = AbsoluteFile toFullPath(d.conf, FileIndex it.sym.position)
let tmp = getOutFile2(d.conf, full.relativeTo(d.conf.projectPath), HtmlExt,
RelativeDir"htmldocs")
let external = relativeTo(tmp, d.thisDir, '/')
let external = relativeTo(tmp, d.thisDir, '/').string
if d.section[k] != nil: add(d.section[k], ", ")
dispA(d.conf, d.section[k],
"<a class=\"reference external\" href=\"$2\">$1</a>",
"$1", [rope esc(d.target, it.sym.name.s),
rope changeFileExt(external, "html").string])
"$1", [rope esc(d.target, changeFileExt(external, "")),
rope changeFileExt(external, "html")])
proc generateDoc*(d: PDoc, n: PNode) =
case n.kind

View File

@@ -63,7 +63,7 @@ proc fileInfoKnown*(conf: ConfigRef; filename: AbsoluteFile): bool =
canon: AbsoluteFile
try:
canon = canonicalizePath(conf, filename)
except:
except OSError:
canon = filename
result = conf.m.filenameToIndexTbl.hasKey(canon.string)
@@ -75,7 +75,7 @@ proc fileInfoIdx*(conf: ConfigRef; filename: AbsoluteFile; isKnownFile: var bool
try:
canon = canonicalizePath(conf, filename)
shallow(canon.string)
except:
except OSError:
canon = filename
# The compiler uses "filenames" such as `command line` or `stdin`
# This flag indicates that we are working with such a path here

View File

@@ -180,7 +180,7 @@ proc relativeTo(full, base: string; sep = DirSep): string =
when true:
proc eqImpl(x, y: string): bool =
when FileSystemCaseSensitive:
result = toLowerAscii(canon x) == toLowerAscii(canon y)
result = cmpIgnoreCase(canon x, canon y) == 0
else:
result = canon(x) == canon(y)
@@ -251,4 +251,5 @@ when isMainModule and defined(posix):
doAssert relativeTo("", "/users/moo") == ""
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
View 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.")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
type
SomeType* = int
proc someType*(): SomeType =
## constructor.
SomeType(2)

View 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()

View File