use of gentest unclear?
_cmd = """$TOOLS_TRUE
$TOOLS_CAT $SRCS
"""
gentest(
name="a_test",
test_cmd=_cmd,
srcs=glob(["*"]),
tools={
"TRUE": ["true"],
"CAT": ["cat"],
},
no_test_output=True,
)
# plz test :a_test
Fail: //:a_test 0 passed 0 skipped 1 failed 0 errored Took 0s
Failure: TestFailed in a_test
Test failed: exit status 127
Standard output:
bash: TOOLS_TRUE: unbound variable
//:a_test 1 test run in 2ms; 0 passed, 1 failed
a_test FAIL 2ms
1 test target and 1 test run in 0s; 0 passed, 1 failed. Total time 30ms.
#
Additionally, when I do plz test :a_test --shell there's no source files (as specified by glob(["*"])).
Inputs like srcs and tools are build-time things, not test-time; if you want to consume files at test time it needs to use data.
Happy to take some suggestions if you think the documentation could be clearer here!
Since making this issue I think I have a better understanding of how this is meant to be used: please correct me if I'm wrong about anything, and I'd love to contribute documentation changes once I have things straight:
A test in please consists of a separate "build" (cmd) and "test" (test_cmd) script.
The build script runs as any other build does, having access to srcs, tools, and deps, and is expected to produce an out.
The test script run, having access only to the out of the build (as $TEST), and separately stated data files. A test marked flaky only has the test script re-run automatically on failure.
Thus, the expected structure is as follows:
- a build script produces an isolated "test binary"
- the "test binary" receives only "data files" as available input
This expected structure has some interesting ramifications:
- Go (and other compiled languages) work(s) well, functionally a normal binary with a different
main() - Python requires consolidating code and dependencies into a single file (i.e. with a PEX)
sh_binarymay be intensely useful for wrapping up other test mechanisms
I also have some questions:
- If I depend on a rule marked as a test (and with a
test_cmd), what do I get as my dependency? The output of thecmdor the test output? - Is there any caching involved in the output of the
test_cmd? Or is it re-run every time? - does
plz buildrun the build part of the test?
I would also like to chip in that gentest() doesn't seem to include the outs of its rules' deps but only the srcs which makes cmd pretty hard to use. Should I build them in gentest() too? But then what's the point of adding them into deps in the first place?
Appologies for the late reply.
@ThisGuyCodes You're right with your assumptions there.
- if you depend on a test, you get the outputs of cmd.
- Tests are indeed cached and will only be run when the inputs to the rule changes.
- plz buid does build the tests binaries (but does not run them)
@binhonglee I'm not sure your observation is correct. If a test depends on a another rule, you will get the outputs of that rule. There's no way to depend on the sources of another rule.