rsttester.nim 1.1 KB

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