lit.cfg.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. __copyright__ = """
  2. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  3. Exceptions. See /LICENSE for license information.
  4. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. """
  6. import lit.formats
  7. import os
  8. from pathlib import Path
  9. # This is a provided variable, ignore the undefined name warning.
  10. config = config # noqa: F821
  11. def fullpath(relative_path):
  12. return Path(os.environ["TEST_SRCDIR"]).joinpath(relative_path)
  13. def add_substitution(before, after):
  14. """Adds a substitution to the config. Wraps before as `%{before}`."""
  15. config.substitutions.append((f"%{{{before}}}", after))
  16. def add_substitutions():
  17. """Adds required substitutions to the config."""
  18. tools = {
  19. "carbon": fullpath("carbon/toolchain/driver/carbon"),
  20. "explorer": fullpath("carbon/explorer/explorer"),
  21. "explorer_prelude": fullpath("carbon/explorer/data/prelude.carbon"),
  22. "filecheck": fullpath("llvm-project/llvm/FileCheck"),
  23. "not": fullpath("llvm-project/llvm/not"),
  24. "merge_output": fullpath("carbon/testing/lit_test/merge_output"),
  25. }
  26. run_carbon = f"{tools['merge_output']} {tools['carbon']}"
  27. run_explorer = (
  28. f"{tools['merge_output']} {tools['explorer']} %s "
  29. f"--prelude={tools['explorer_prelude']}"
  30. )
  31. filecheck_allow_unmatched = (
  32. f"{tools['filecheck']} %s --match-full-lines --strict-whitespace"
  33. )
  34. filecheck_strict = (
  35. f"{filecheck_allow_unmatched} --implicit-check-not={{{{.}}}}"
  36. )
  37. add_substitution("carbon", f"{run_carbon}")
  38. add_substitution(
  39. "carbon-run-lowering",
  40. f"{run_carbon} dump llvm-ir %s | {filecheck_strict}",
  41. )
  42. add_substitution(
  43. "carbon-run-parser",
  44. f"{run_carbon} dump parse-tree %s | {filecheck_strict}",
  45. )
  46. add_substitution(
  47. "carbon-run-semantics",
  48. f"{run_carbon} dump semantics-ir %s | {filecheck_strict}",
  49. )
  50. add_substitution(
  51. "carbon-run-tokens", f"{run_carbon} dump tokens %s | {filecheck_strict}"
  52. )
  53. add_substitution(
  54. "explorer-run",
  55. f"{run_explorer} | {filecheck_strict}",
  56. )
  57. add_substitution(
  58. "explorer-run-trace",
  59. f"{run_explorer} --parser_debug --trace_file=- | "
  60. f"{filecheck_allow_unmatched}",
  61. )
  62. add_substitution("FileCheck-allow-unmatched", filecheck_allow_unmatched)
  63. add_substitution("FileCheck-strict", filecheck_strict)
  64. add_substitution("not", tools["not"])
  65. config.name = "lit"
  66. config.suffixes = [".carbon"]
  67. config.test_format = lit.formats.ShTest()
  68. add_substitutions()