lit_test.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. "--test_dir", help="The directory containing tests to run."
  19. )
  20. arg_parser.add_argument(
  21. "lit_args", nargs="*", help="Arguments to pass through to lit."
  22. )
  23. return arg_parser.parse_args()
  24. def main():
  25. parsed_args = _parse_args()
  26. args = [
  27. str(Path(os.environ["TEST_SRCDIR"]).joinpath("llvm-project/llvm/lit")),
  28. str(
  29. Path.cwd().joinpath(parsed_args.package_name, parsed_args.test_dir)
  30. ),
  31. "-sv",
  32. ]
  33. # Force tests to be explicit about command paths.
  34. env = os.environ.copy()
  35. del env["PATH"]
  36. # Run lit.
  37. try:
  38. subprocess.check_call(args=args + parsed_args.lit_args, env=env)
  39. except subprocess.CalledProcessError as e:
  40. # Print without the stack trace.
  41. print(e)
  42. if __name__ == "__main__":
  43. exit(main())