tester.nim 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Small program that runs the test cases for 'nim doc'.
  2. # To run this, cd to the git repo root, and run "nim c -r nimdoc/tester.nim".
  3. import strutils, os
  4. var
  5. failures = 0
  6. const
  7. baseDir = "nimdoc"
  8. type
  9. NimSwitches = object
  10. doc: seq[string]
  11. buildIndex: seq[string]
  12. proc testNimDoc(prjDir, docsDir: string; switches: NimSwitches; fixup = false) =
  13. let
  14. nimDocSwitches = switches.doc.join(" ")
  15. nimBuildIndexSwitches = switches.buildIndex.join(" ")
  16. putEnv("SOURCE_DATE_EPOCH", "100000")
  17. if nimDocSwitches != "":
  18. if execShellCmd("nim doc $1" % [nimDocSwitches]) != 0:
  19. quit("FAILURE: nim doc failed")
  20. if nimBuildIndexSwitches != "":
  21. if execShellCmd("nim buildIndex $1" % [nimBuildIndexSwitches]) != 0:
  22. quit("FAILURE: nim buildIndex failed")
  23. for expected in walkDirRec(prjDir / "expected/"):
  24. let produced = expected.replace('\\', '/').replace("/expected/", "/$1/" % [docsDir])
  25. if not fileExists(produced):
  26. echo "FAILURE: files not found: ", produced
  27. inc failures
  28. elif readFile(expected) != readFile(produced):
  29. echo "FAILURE: files differ: ", produced
  30. discard execShellCmd("diff -uNdr " & expected & " " & produced)
  31. inc failures
  32. if fixup:
  33. copyFile(produced, expected)
  34. else:
  35. echo "SUCCESS: files identical: ", produced
  36. if failures == 0 and ((prjDir / docsDir) != prjDir):
  37. removeDir(prjDir / docsDir)
  38. # Test "nim doc --project --out:.. --index:on .."
  39. let
  40. test1PrjName = "testproject"
  41. test1Dir = baseDir / test1PrjName
  42. test1DocsDir = "htmldocs"
  43. test1Switches = NimSwitches(doc: @["--project",
  44. "--out:$1/$2" % [test1Dir, test1DocsDir],
  45. "--index:on",
  46. "$1/$2.nim" % [test1Dir, test1PrjName]],
  47. buildIndex: @["--out:$1/$2/theindex.html" % [test1Dir, test1DocsDir],
  48. "$1/$2" % [test1Dir, test1DocsDir]])
  49. testNimDoc(test1Dir, test1DocsDir, test1Switches, defined(fixup))
  50. # Test "nim doc --out:.. --index:on .."
  51. let
  52. test2PrjDir = "test_out_index_dot_html"
  53. test2PrjName = "foo"
  54. test2Dir = baseDir / test2PrjDir
  55. test2DocsDir = "htmldocs"
  56. test2Switches = NimSwitches(doc: @["--out:$1/$2/index.html" % [test2Dir, test2DocsDir],
  57. "--index:on",
  58. "$1/$2.nim" % [test2Dir, test2PrjName]],
  59. buildIndex: @["--out:$1/$2/theindex.html" % [test2Dir, test2DocsDir],
  60. "$1/$2" % [test2Dir, test2DocsDir]])
  61. testNimDoc(test2Dir, test2DocsDir, test2Switches, defined(fixup))
  62. # Check for failures
  63. if failures > 0: quit($failures & " failures occurred.")