golden_test.bzl 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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 golden test."""
  5. def golden_test(name, golden, cmd, data, env = None, golden_is_subset = False, **kwargs):
  6. """Compares two files. Passes if they are identical.
  7. Args:
  8. name: Name of the build rule.
  9. cmd: The command whose output is being tested.
  10. golden: The golden file to be compared against the command output.
  11. data: Data files.
  12. env: Optional environment.
  13. golden_is_subset: Set to True if the golden file should be a subset of
  14. command output.
  15. **kwargs: Any additional parameters for the generated py_test.
  16. """
  17. args = ["$(location %s)" % golden, cmd]
  18. if not env:
  19. env = {}
  20. if golden_is_subset:
  21. args.append("--golden_is_subset")
  22. native.py_test(
  23. name = name,
  24. srcs = ["//bazel/testing:golden_test.py"],
  25. main = "//bazel/testing:golden_test.py",
  26. args = args,
  27. data = [golden] + data,
  28. env = env,
  29. **kwargs
  30. )