tester.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Small program that runs the test cases
  2. import strutils, os
  3. const
  4. dir = "nimpretty/tests/"
  5. var
  6. failures = 0
  7. when defined(develop):
  8. const nimp = "bin" / "nimpretty".addFileExt(ExeExt)
  9. if execShellCmd("nim c -o:$# nimpretty/nimpretty.nim" % [nimp]) != 0:
  10. quit("FAILURE: compilation of nimpretty failed")
  11. else:
  12. const nimp = "nimpretty"
  13. proc test(infile, ext: string) =
  14. if execShellCmd("$# -o:$# --backup:off $#" % [nimp, infile.changeFileExt(ext), infile]) != 0:
  15. echo "FAILURE: nimpretty cannot prettify ", infile
  16. failures += 1
  17. return
  18. let nimFile = splitFile(infile).name
  19. let expected = dir / "expected" / nimFile & ".nim"
  20. let produced = dir / nimFile.changeFileExt(ext)
  21. if readFile(expected) != readFile(produced):
  22. echo "FAILURE: files differ: ", nimFile
  23. discard execShellCmd("diff -uNdr " & expected & " " & produced)
  24. failures += 1
  25. else:
  26. echo "SUCCESS: files identical: ", nimFile
  27. for t in walkFiles(dir / "*.nim"):
  28. test(t, "pretty")
  29. # also test that pretty(pretty(x)) == pretty(x)
  30. test(t.changeFileExt("pretty"), "pretty2")
  31. removeFile(t.changeFileExt("pretty"))
  32. removeFile(t.changeFileExt("pretty2"))
  33. if failures > 0: quit($failures & " failures occurred.")