rsttester.nim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. let versionCacheParam = "?v=" & $NimMajor & "." & $NimMinor & "." & $NimPatch
  21. let producedFile = readFile(producedHtml).replace(versionCacheParam,"") #remove version cache param used for cache invalidation
  22. if readFile(expectedHtml) != producedFile:
  23. echo diffFiles(expectedHtml, producedHtml).output
  24. inc failures
  25. if fixup:
  26. writeFile(expectedHtml, producedFile)
  27. else:
  28. echo "SUCCESS: files identical: ", producedHtml
  29. if failures == 0:
  30. removeDir(baseDir / "source/htmldocs")
  31. testRst2Html(fixup)
  32. # Check for failures
  33. if failures > 0: quit($failures & " failures occurred.")