rsttester.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import os, strutils
  2. from std/private/gitutils import diffFiles
  3. const
  4. baseDir = "nimdoc/rst2html"
  5. var failures = 0
  6. proc exec(cmd: string) =
  7. if execShellCmd(cmd) != 0:
  8. quit("FAILURE: " & cmd)
  9. proc testRst2Html(fixup = false) =
  10. putEnv("SOURCE_DATE_EPOCH", "100000")
  11. const nimExe = getCurrentCompilerExe() # so that `bin/nim_temp r nimdoc/tester.nim` works
  12. for expectedHtml in walkDir(baseDir / "expected"):
  13. let expectedHtml = expectedHtml.path
  14. let sourceFile = expectedHtml.replace('\\', '/').replace("/expected/", "/source/").replace(".html", ".rst")
  15. exec("$1 rst2html $2" % [nimExe, sourceFile])
  16. let producedHtml = expectedHtml.replace('\\', '/').replace("/expected/", "/source/htmldocs/")
  17. if readFile(expectedHtml) != readFile(producedHtml):
  18. echo diffFiles(expectedHtml, producedHtml).output
  19. inc failures
  20. if fixup:
  21. copyFile(producedHtml, expectedHtml)
  22. else:
  23. echo "SUCCESS: files identical: ", producedHtml
  24. if failures == 0:
  25. removeDir(baseDir / "source/htmldocs")
  26. testRst2Html(defined(fixup))
  27. # Check for failures
  28. if failures > 0: quit($failures & " failures occurred.")