Files
carbon-lang/testing/lit_test/lit_test.py
T
Jon Ross-Perkins 735502273b Refactor lit test infra under //testing. (#2829)
- Moves most parts to //testing/lit_test to be consistent with //testing/file_test.
- Separates the autoupdate script out because it's shared between lit_test and file_test now, not lit-specific.
- Renames scripts to autoupdate_testdata (or autoupdate_lit_testdata for explorer's extra) to be more consistent with the non-lit-specific setup.
  - Switches from execv to subprocess.call to head off a subtle issue regarding execution of multiple scripts, which we're likely to want in the future. Mostly in this PR because everything was already being touched.
- Removes autoupdate's dependency on merge_output in order to (a) better support the division of lit and non-lit logic and (b) remove a subprocess, for reasons similar to file_test's removal of subprocesses.
2023-05-18 08:01:03 -07:00

58 lines
1.7 KiB
Python

"""Runs `lit` for testing."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
def _parse_args():
"""Parses command line arguments, returning the result."""
arg_parser = argparse.ArgumentParser(description=__doc__)
arg_parser.add_argument(
"--package_name", help="The directory containing tests to run."
)
arg_parser.add_argument(
"lit_args", nargs="*", help="Arguments to pass through to lit."
)
return arg_parser.parse_args()
def main():
parsed_args = _parse_args()
args = [
str(Path(os.environ["TEST_SRCDIR"]).joinpath("llvm-project/llvm/lit")),
str(Path.cwd().joinpath(parsed_args.package_name)),
"-v",
]
# Force tests to be explicit about command paths. Some tools are required by
# bazel's py_binary output in order to find python3, so we add these. The
# list of tools may prove to be fragile: if so, we may need to change or
# remove the PATH hiding.
system_tools = Path(os.environ["TEST_TMPDIR"]).joinpath("system_tools")
system_tools.mkdir()
for tool in ("env", "grep", "python3", "sh", "which"):
system_tools.joinpath(tool).symlink_to(shutil.which(tool))
env = os.environ.copy()
env["PATH"] = str(system_tools)
# Run lit.
try:
subprocess.check_call(args=args + parsed_args.lit_args, env=env)
except subprocess.CalledProcessError as e:
# Print without the stack trace.
exit(e)
if __name__ == "__main__":
exit(main())