I'm writing some bazel tests where I need to be able to provide the full path to some file.
bazel test //webservice:checkstyle-test --test_arg="path_to_some_file"
My question is how can you parse the input arguments in your bazel test? Is there anything like ctx.arg
?
BUILD
load("//:checkstyle.bzl", "checkstyle_test")
checkstyle_test(
name = ""
src = []
config = ""
)
checkstyle.bzl
def _checkstyle_test_impl(ctx):
// How can I get my input parameter here?
checkstyle_test = rule(
implementation = _checkstyle_test_impl,
test = True,
attrs = {
"_classpath": attr.label_list(default=[
Label("@com_puppycrawl_tools_checkstyle//jar")
]),
"config": attr.label(allow_single_file=True, default = "//config:checkstyle"),
"suppressions": attr.label(allow_single_file=True, default = "//config:suppressions"),
"license": attr.label(allow_single_file=True, default = "//config:license"),
"properties": attr.label(allow_single_file=True),
"opts": attr.string_list(),
"string_opts": attr.string_dict(),
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(),
},
)
The value of
--test_arg
is passed to the test executable as program arguments when bazel runs it duringbazel test
, see https://docs.bazel.build/versions/main/command-line-reference.html#flag--test_argFor example:
I don't think there's currently a way to get the value of
--test_arg
in a Starlark rule implementation (it's not added underctx.fragments
for example).