Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

74 rindas
1.7KB

  1. #!/usr/bin/env python3
  2. import argparse
  3. from pathlib import Path
  4. from typing import List, NamedTuple
  5. import shutil
  6. import subprocess
  7. import sys
  8. class TestOptions(NamedTuple):
  9. exe: Path
  10. toolchain: str
  11. def run_test_dir(dir: Path, opts: TestOptions) -> bool:
  12. print(f'Running test: {dir.name} ...')
  13. out_dir = dir / '_build'
  14. if out_dir.exists():
  15. shutil.rmtree(out_dir)
  16. res = subprocess.run(
  17. [
  18. str(opts.exe),
  19. 'build',
  20. '--export',
  21. '--warnings',
  22. '--tests',
  23. f'--toolchain={opts.toolchain}',
  24. f'--out-dir={out_dir}',
  25. ],
  26. cwd=dir,
  27. stdout=subprocess.PIPE,
  28. stderr=subprocess.STDOUT,
  29. )
  30. if res.returncode != 0:
  31. print(f'Test failed with exit code [{res.returncode}]:\n{res.stdout}')
  32. return res.returncode == 0
  33. def run_tests(opts: TestOptions) -> int:
  34. print('Sanity check...')
  35. subprocess.check_output([str(opts.exe), '--help'])
  36. tests_subdir = Path(__file__).parent.absolute() / 'tests'
  37. test_dirs = tests_subdir.glob('*.test')
  38. ret = 0
  39. for td in test_dirs:
  40. if not run_test_dir(td, opts):
  41. ret = 1
  42. return ret
  43. def main(argv: List[str]) -> int:
  44. parser = argparse.ArgumentParser()
  45. parser.add_argument(
  46. '--exe',
  47. '-e',
  48. help='Path to the ddslim executable to test',
  49. required=True)
  50. parser.add_argument(
  51. '--toolchain',
  52. '-T',
  53. help='The ddslim toolchain to use while testing',
  54. required=True,
  55. )
  56. args = parser.parse_args(argv)
  57. opts = TestOptions(exe=Path(args.exe).absolute(), toolchain=args.toolchain)
  58. return run_tests(opts)
  59. if __name__ == "__main__":
  60. sys.exit(main(sys.argv[1:]))