rsttester.nim 1.3 KB

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