Files
carbon-lang/testing/lit_test/lit.cfg.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

82 lines
2.5 KiB
Python

__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 lit.formats
import os
from pathlib import Path
# This is a provided variable, ignore the undefined name warning.
config = config # noqa: F821
def fullpath(relative_path):
return Path(os.environ["TEST_SRCDIR"]).joinpath(relative_path)
def add_substitution(before, after):
"""Adds a substitution to the config. Wraps before as `%{before}`."""
config.substitutions.append((f"%{{{before}}}", after))
def add_substitutions():
"""Adds required substitutions to the config."""
tools = {
"carbon": fullpath("carbon/toolchain/driver/carbon"),
"explorer": fullpath("carbon/explorer/explorer"),
"explorer_prelude": fullpath("carbon/explorer/data/prelude.carbon"),
"filecheck": fullpath("llvm-project/llvm/FileCheck"),
"not": fullpath("llvm-project/llvm/not"),
"merge_output": fullpath("carbon/testing/lit_test/merge_output"),
}
run_carbon = f"{tools['merge_output']} {tools['carbon']}"
run_explorer = (
f"{tools['merge_output']} {tools['explorer']} %s "
f"--prelude={tools['explorer_prelude']}"
)
filecheck_allow_unmatched = (
f"{tools['filecheck']} %s --match-full-lines --strict-whitespace"
)
filecheck_strict = (
f"{filecheck_allow_unmatched} --implicit-check-not={{{{.}}}}"
)
add_substitution("carbon", f"{run_carbon}")
add_substitution(
"carbon-run-lowering",
f"{run_carbon} dump llvm-ir %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-parser",
f"{run_carbon} dump parse-tree %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-semantics",
f"{run_carbon} dump semantics-ir %s | {filecheck_strict}",
)
add_substitution(
"carbon-run-tokens", f"{run_carbon} dump tokens %s | {filecheck_strict}"
)
add_substitution(
"explorer-run",
f"{run_explorer} | {filecheck_strict}",
)
add_substitution(
"explorer-run-trace",
f"{run_explorer} --parser_debug --trace_file=- | "
f"{filecheck_allow_unmatched}",
)
add_substitution("FileCheck-allow-unmatched", filecheck_allow_unmatched)
add_substitution("FileCheck-strict", filecheck_strict)
add_substitution("not", tools["not"])
config.name = "lit"
config.suffixes = [".carbon"]
config.test_format = lit.formats.ShTest()
add_substitutions()