A generic method for executing runnable targets via `buck2 test`?
- Dominant language
- Rust
- Stars
- 4.4k
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
I have a C library (target `:lib`), and then a C test file (target `:test-foo`) that is a smoke test and it should always return 0 or 1 from the executable if the library testing passes or fails. I have a number of these smoke tests, and all of them should succeed (return 0) to have the test process succeed.
It is annoyingly difficult, and I see no way out of the box, to make a target like `:test-foo` work as a `buck2 test` target, i.e. to have a `ExternalRunnerTestInfo` attached alongside its `RunInfo`, just from using `cxx_binary`. It's more annoying than that actually, since a macro can't fix it; I'd actually have to call the implementation in a new rule if I wanted to attach that new provider.
Part of the reason this is muddled is because the real analogue for "`cxx_binary`, but for testing" is called `cxx_test`, but `cxx_test` is annoyingly inflexible and requires things like `gtest`, which is a rather large addon for just running a "does this pass or fail" style smoke integration.
We could fix `cxx_test` of course, and I'd like that, but realistically this kind of smoke test comes up all the time and it might be a Python script, a bash script, a C program, a 3rd party Rust program, etc. I think there's a reasonable desire for a test that is just "run this command and pass or fail."
`sh_test` is close to what could work, but its argument is a `source` and not an `arg`, so you can't use macros inside of it; otherwise I could have a `sh_test` that just invokes something like `$(location_exe :test-foo)` and be done with it. So what I think would be needed is some kind of combination of `genrule` and `sh_test` that would let you invoke an executable and have the whole "wrapper rule" succeed or fail.
Contributor guide
Assessment
This issue has not been assessed yet.