runTests.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/python3
  2. import sys
  3. import os
  4. import subprocess
  5. import difflib
  6. if len(sys.argv) <= 1:
  7. print("please specify the qlow executable as a command line argument")
  8. exit()
  9. qlow_executable = sys.argv[1]
  10. succeeded = 0
  11. failed = 0
  12. def test_file(path):
  13. test = [qlow_executable, path, "-o", path + ".o"]
  14. print("running test " + " ".join(test))
  15. output = subprocess.run(test, stdout=subprocess.PIPE)
  16. with open(path + ".c.out", "w") as out:
  17. out.write(output.stdout.decode("utf-8"))
  18. with open(path + ".c.out", "r") as did, open(path + ".c.out.ref", "r") as should:
  19. if did.readlines() == should.readlines():
  20. global succeeded
  21. succeeded += 1
  22. else:
  23. global failed
  24. failed += 1
  25. exefile = path + ".o"
  26. if os.path.isfile(exefile):
  27. runOut = subprocess.run(exefile, stdout=subprocess.PIPE)
  28. def run_directory(dir):
  29. for root, dirs, files in os.walk(dir):
  30. for filename in files:
  31. if filename.endswith(".qlw"):
  32. test_file(os.path.join(root, filename))
  33. def print_results():
  34. print("%d out of %d tests succeeded: %d%%" % (succeeded, succeeded + failed, 100 * succeeded / (succeeded + failed)))
  35. run_directory(".")
  36. print_results()