tester.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # Small program that runs the test cases for 'nim doc'.
  2. import strutils, os
  3. var
  4. failures = 0
  5. proc test(dir: string; fixup = false) =
  6. putEnv("SOURCE_DATE_EPOCH", "100000")
  7. if execShellCmd("nim doc --project --index:on -o:$1/htmldocs $1/testproject.nim" % dir) != 0:
  8. quit("FAILURE: nim doc failed")
  9. if execShellCmd("nim buildIndex -o:$1/htmldocs/theindex.html $1/htmldocs" % [dir]) != 0:
  10. quit("FAILURE: nim buildIndex failed")
  11. for expected in walkDirRec(dir / "expected/"):
  12. let produced = expected.replace('\\', '/').replace("/expected/", "/htmldocs/")
  13. if not fileExists(produced):
  14. echo "FAILURE: files not found: ", produced
  15. inc failures
  16. elif readFile(expected) != readFile(produced):
  17. echo "FAILURE: files differ: ", produced
  18. discard execShellCmd("diff -uNdr " & expected & " " & produced)
  19. inc failures
  20. if fixup:
  21. copyFile(produced, expected)
  22. else:
  23. echo "SUCCESS: files identical: ", produced
  24. removeDir(dir / "htmldocs")
  25. test("nimdoc/testproject", false)
  26. if failures > 0: quit($failures & " failures occurred.")