-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust: add rust_test_binary rule #316
Conversation
Hi, Thanks for sending this PR! I would like to figure out a better way to do it. I am not fond of the
Thanks! |
Good suggestions - I've had a bit of a dig, these are my initial reactions:
rust_test_binary(
name = "my_test_bin",
crate = ":lib", # resolves to a rust_library
)
sh_test(
name = "my_test_runner",
# The source code of this runner does other things, but the main one is:
#
# # setup environment
# PYTHONPATH="$PYTHONPATH:$python_library_path"
# export PYTHONPATH
#
# # run rust test binary
# "$BINARY"
srcs = ["test_runner.sh"],
data = ["my_test_bin", "//some/other:python_lib"],
args = [
"--binary",
"$(location :my_test_bin)", # path of the rust binary to test
"--python-path",
"some/other" # value which will be set on PYTHONPATH
],
)
I agree that I initially didn't like having a separate rule, but I think it makes sense for a couple of reasons:
|
Ok so from your description it really sounds like an edge case. What do you think about making |
That sounds good in principle - the only snag I can see is that I agree that this is an edge case - this is why the solution I've proposed doesn't relate to the details of it in any way. It just provides an entrypoint for the user to add their own test runner. Could you clarify why expecially you don't like the |
You are correct, exposing Since I cannot find any good way to make it better, could we just replace the documentation by a warning that this is experimental? |
Happy to do so - I have updated the docstring. I have been trying to find a generic solution for other test targets that produce executable output, but from reading the Bazel docs, it seems test rules really are a special case all of their own. You even have to ensure that the rule name is I've just noticed that the HTML documentation is not autogenerated - I'm happy to add an entry in the docs, but from the sound of it you may prefer to leave it undocumented for now? |
Correct. Thanks for the update! |
I have a case where I would like to build a rust binary exactly as output by
rust_test
, but not call it directly. Instead, I have ash_test
rule that will be the entrypoint for the test, acting as a test runner and setting up environment variables required by the test code.This already works (amazing!), but I don't want to run the binary output by
rust_test
directly, as it will fail without the setup performed in thesh_test
rule. This happens when running all tests with:bazel test //...
In this PR, I have added the new rule
rust_test_binary
which is simply the definition ofrust_test
withtest = True
removed, and docs updated.If there's a way to make this an argument of the existing
rust_test
rule please let me know, but I couldn't find any examples of how I might set the value oftest
on a rule dynamically.