Files
carbon-lang/testing/lit_test/lit.cfg.py
T
Jon Ross-Perkins e2b1511a0d Clean up lit tests and config to reflect current uses. (#2913)
Overall, cleaning up remaining lit uses.

#2851 had removed FileCheck invocations from some of the explorer tests; this starts as just restoring that. But, now that we have far fewer `lit` tests, it seems best to refine `lit.cfg.py` to focus on providing fewer commands (not all were even used).

Also, adding testing of an error to explorer (which I noticed due to a change that would've broken that) made me notice that autoupdate_lit_test's for_lit logic didn't actually work, so I'm just cutting it and going to manual updates. Really, we might want to just remove lit autoupdate support altogether since it's only a couple tests using it, but I'm not ready to make that change right now.

Fixes #2912
2023-06-16 11:52:11 -07:00

59 lines
1.9 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("explorer", f"{run_explorer}")
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()