Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

78 lines
1.9KB

  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} ', end='')
  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. f'--export-name={dir.stem}',
  26. ],
  27. cwd=dir,
  28. stdout=subprocess.PIPE,
  29. stderr=subprocess.STDOUT,
  30. )
  31. if res.returncode != 0:
  32. print('- FAILED')
  33. print(f'Test failed with exit code [{res.returncode}]:\n{res.stdout.decode()}')
  34. else:
  35. print('- PASSED')
  36. return res.returncode == 0
  37. def run_tests(opts: TestOptions) -> int:
  38. print('Sanity check...')
  39. subprocess.check_output([str(opts.exe), '--help'])
  40. tests_subdir = Path(__file__).parent.absolute() / 'tests'
  41. test_dirs = tests_subdir.glob('*.test')
  42. ret = 0
  43. for td in test_dirs:
  44. if not run_test_dir(td, opts):
  45. ret = 1
  46. return ret
  47. def main(argv: List[str]) -> int:
  48. parser = argparse.ArgumentParser()
  49. parser.add_argument(
  50. '--exe',
  51. '-e',
  52. help='Path to the ddslim executable to test',
  53. required=True)
  54. parser.add_argument(
  55. '--toolchain',
  56. '-T',
  57. help='The ddslim toolchain to use while testing',
  58. required=True,
  59. )
  60. args = parser.parse_args(argv)
  61. opts = TestOptions(exe=Path(args.exe).absolute(), toolchain=args.toolchain)
  62. return run_tests(opts)
  63. if __name__ == "__main__":
  64. sys.exit(main(sys.argv[1:]))