run_tests.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import sys
  3. import time
  4. def test_file(filepath, cpython=False):
  5. if cpython:
  6. return os.system("python3 " + filepath) == 0
  7. if sys.platform == 'win32':
  8. return os.system("main.exe " + filepath) == 0
  9. else:
  10. return os.system("./main " + filepath) == 0
  11. def test_dir(path):
  12. print("Testing directory:", path)
  13. for filename in sorted(os.listdir(path)):
  14. if not filename.endswith('.py'):
  15. continue
  16. filepath = os.path.join(path, filename)
  17. print("> " + filepath, flush=True)
  18. if path == 'benchmarks/':
  19. _0 = time.time()
  20. if not test_file(filepath, cpython=True):
  21. print('cpython run failed')
  22. continue
  23. _1 = time.time()
  24. if not test_file(filepath): exit(1)
  25. _2 = time.time()
  26. print(f' cpython: {_1 - _0:.6f}s (100%)')
  27. print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)')
  28. else:
  29. if not test_file(filepath):
  30. print('-' * 50)
  31. print("TEST FAILED! Press any key to continue...")
  32. input()
  33. if len(sys.argv) == 2:
  34. assert 'benchmark' in sys.argv[1]
  35. d = 'benchmarks/'
  36. else:
  37. d = 'tests/'
  38. test_dir(d)
  39. print("ALL TESTS PASSED")