diff --git a/.travis.yml b/.travis.yml index 0f74c56acf..a0f8765a25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,3 +51,4 @@ script: - ./koch csource - ./koch nimsuggest - nim c -r nimsuggest/tester + - nim c -r nimdoc/tester diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 428fcbfe31..4f1070af07 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -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], "$1", - "$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 diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 47858f1433..d817b2956c 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -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 diff --git a/compiler/pathutils.nim b/compiler/pathutils.nim index f84d964bb6..b279811594 100644 --- a/compiler/pathutils.nim +++ b/compiler/pathutils.nim @@ -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" diff --git a/nimdoc/tester.nim b/nimdoc/tester.nim new file mode 100644 index 0000000000..7ca8b45fed --- /dev/null +++ b/nimdoc/tester.nim @@ -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.") diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html new file mode 100644 index 0000000000..0e09b10cd1 --- /dev/null +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -0,0 +1,1299 @@ + + + + +
+ + + + + + + + + + + + +