-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support test output postprocessing by a child process.
Rationale for adding this functionality: * Bazel (build system) doesn't provide a way to process output from a binary (in this case, Rust test binary's output) other using a wrapper binary. However, using a wrapper binary potentially breaks debugging, because Bazel would suggest to debug the wrapper binary rather than the Rust test itself. * See bazelbuild/rules_rust#1303. * Cargo is not used in Rust Bazel rules. * Although we could wait for #96290 and then modify Rust Bazel rules to pass `--logfile` on the command line to provisionally unblock bazelbuild/rules_rust#1303, that solution still wouldn't allow advanced test output postprocessing such as changing JSON/XML schema and injecting extra JUnit properties. * Due to limitations of Rust libtest formatters, Rust developers often use a separate tool to postprocess the test results output (see comments to #85563). * Examples of existing postprocessing tools: * https://crates.io/crates/cargo2junit * https://crates.io/crates/gitlab-report * https://crates.io/crates/cargo-suity * For these use cases, it might be helpful to use the new flags `--output_postprocess_executable`, `--output_postprocess_args` instead of piping the test output explicitly, e.g. to more reliably separate test results from other output. Rationale for implementation details: * Use platform-dependent scripts (.sh, .cmd) because it doesn't seem to be possible to enable unstable feature `bindeps` (https://rust-lang.github.io/rfcs/3028-cargo-binary-dependencies.html) in "x.py" by default. * Here's a preexisting test that also uses per-platform specialization: `library/std/src/process/tests.rs`. How to use: ``` ./testbinary --format=junit -Zunstable-options --output_postprocess_executable=/usr/bin/echo --output_postprocess_args=abc123 ```
- Loading branch information
1 parent
52f8aec
commit 9519fe2
Showing
8 changed files
with
273 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5445,6 +5445,7 @@ dependencies = [ | |
"libc", | ||
"panic_abort", | ||
"panic_unwind", | ||
"rand", | ||
"std", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@REM A very basic test output postprocessor. Used in `test_output_postprocessing()`. | ||
|
||
@echo off | ||
|
||
if [%TEST_POSTPROCESSOR_OUTPUT_FILE%] == [] ( | ||
echo Required environment variable TEST_POSTPROCESSOR_OUTPUT_FILE is not set. | ||
cmd /C exit /B 1 | ||
) | ||
|
||
@REM Forward script's input into file. | ||
find /v "" > %TEST_POSTPROCESSOR_OUTPUT_FILE% | ||
|
||
@REM Log every command line argument into the same file. | ||
:start | ||
if [%1] == [] goto done | ||
echo %~1>> %TEST_POSTPROCESSOR_OUTPUT_FILE% | ||
shift | ||
goto start | ||
:done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# | ||
# A very basic test output postprocessor. Used in `test_output_postprocessing()`. | ||
|
||
if [ -z "$TEST_POSTPROCESSOR_OUTPUT_FILE" ] | ||
then | ||
echo "Required environment variable TEST_POSTPROCESSOR_OUTPUT_FILE is not set." | ||
exit 1 | ||
fi | ||
|
||
# Forward script's input into file. | ||
cat /dev/stdin > "$TEST_POSTPROCESSOR_OUTPUT_FILE" | ||
|
||
# Log every command line argument into the same file. | ||
for i in "$@" | ||
do | ||
echo "$i" >> "$TEST_POSTPROCESSOR_OUTPUT_FILE" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.