lit_test.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """Runs `lit` for testing."""
  2. __copyright__ = """
  3. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. Exceptions. See /LICENSE for license information.
  5. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. """
  7. import argparse
  8. import os
  9. from pathlib import Path
  10. import subprocess
  11. def _parse_args():
  12. """Parses command line arguments, returning the result."""
  13. arg_parser = argparse.ArgumentParser(description=__doc__)
  14. arg_parser.add_argument(
  15. "--package_name", help="The directory containing tests to run."
  16. )
  17. arg_parser.add_argument(
  18. "lit_args", nargs="*", help="Arguments to pass through to lit."
  19. )
  20. return arg_parser.parse_args()
  21. def main():
  22. parsed_args = _parse_args()
  23. args = [
  24. str(Path(os.environ["TEST_SRCDIR"]).joinpath("llvm-project/llvm/lit")),
  25. str(Path.cwd().joinpath(parsed_args.package_name)),
  26. "-v",
  27. ]
  28. # Force tests to be explicit about command paths.
  29. env = os.environ.copy()
  30. del env["PATH"]
  31. # Run lit.
  32. try:
  33. subprocess.check_call(args=args + parsed_args.lit_args, env=env)
  34. except subprocess.CalledProcessError as e:
  35. # Print without the stack trace.
  36. exit(e)
  37. if __name__ == "__main__":
  38. exit(main())