rules.bzl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. """Rules for building file tests.
  5. file_test uses the tests_as_input_file rule to transform test dependencies into
  6. a file which can be accessed as a list. This avoids long argument parsing.
  7. """
  8. load("//bazel/cc_rules:defs.bzl", "cc_test")
  9. load("//bazel/manifest:defs.bzl", "manifest_as_cpp")
  10. def file_test(
  11. name,
  12. tests,
  13. srcs = [],
  14. deps = [],
  15. data = [],
  16. args = [],
  17. **kwargs):
  18. """Generates tests using the file_test base.
  19. There will be one main test using `name` that can be sharded, and includes
  20. all files. Additionally, per-file tests will be generated as
  21. `name.file_path`; these per-file tests will be manual.
  22. Args:
  23. name: The base name of the tests.
  24. tests: The list of test files to use as data, typically a glob.
  25. srcs: Passed to cc_test.
  26. deps: Passed to cc_test.
  27. data: Passed to cc_test.
  28. args: Passed to cc_test.
  29. **kwargs: Passed to cc_test.
  30. """
  31. # Ensure tests are always a filegroup for tests_as_input_file_rule.
  32. manifest_cpp = "{0}_autogen_manifest.cpp".format(name)
  33. manifest_as_cpp(
  34. name = manifest_cpp,
  35. var_name = "CarbonFileTestManifest",
  36. srcs = tests,
  37. testonly = 1,
  38. )
  39. cc_test(
  40. name = name,
  41. srcs = srcs + [":" + manifest_cpp],
  42. deps = deps + ["//testing/file_test:manifest_impl"],
  43. data = tests + data,
  44. args = args,
  45. **kwargs
  46. )