lit_test.bzl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Rule for a lit test."""
  5. def lit_test(name, test_dir, data = None, **kwargs):
  6. """Runs `lit` on test_dir.
  7. `lit` reference:
  8. https://llvm.org/docs/CommandGuide/lit.html
  9. To pass flags to `lit`, use `--test_arg`. For example:
  10. bazel test :lit_test --test_arg=-v
  11. bazel test :lit_test --test_arg=--filter=REGEXP
  12. Args:
  13. name: Name of the build rule.
  14. test_dir: The directory with the lit tests.
  15. data: An optional list of tools to provide to the tests. These will be
  16. aliased for execution.
  17. **kwargs: Any additional parameters for the generated py_test.
  18. """
  19. if not data:
  20. data = []
  21. data += [
  22. "@llvm-project//llvm:lit",
  23. ]
  24. native.py_test(
  25. name = name,
  26. srcs = ["//bazel/testing:lit_test.py"],
  27. main = "//bazel/testing:lit_test.py",
  28. data = data + native.glob([test_dir + "/**"]),
  29. args = [test_dir, "--"],
  30. **kwargs
  31. )