From 4b96d85dac392052947e036ba4ff70ec9cd635ad Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Thu, 19 May 2022 21:30:17 -0700 Subject: Add exec_test. exec_test is like exec, but it can be provided to bazel test. Test: TH Change-Id: Ia8cb2c54a7fd7305b718875027bd09f1a9dfa862 --- exec/exec.bzl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/exec/exec.bzl b/exec/exec.bzl index 0769354..ee18f94 100644 --- a/exec/exec.bzl +++ b/exec/exec.bzl @@ -67,3 +67,30 @@ See `build/bazel_common_rules/exec/tests/BUILD` for examples. }, executable = True, ) + +exec_test = rule( + implementation = _impl, + doc = """Run a test script when `bazel test` this target. + +See [documentation] for the `args` attribute. +""", + attrs = { + "data": attr.label_list(aspects = [exec_aspect], allow_files = True, doc = """A list of labels providing runfiles. Labels may be used in `script`. + +Executables in `data` must not have the `args` and `env` attribute. Use +[`embedded_exec`](#embedded_exec) to wrap the depended target so its env and args +are preserved. +"""), + "hashbang": attr.string(default = "/bin/bash -e", doc = "Hashbang of the script."), + "script": attr.string(doc = """The script. + +Use `$(rootpath