Skip to content

Running cargo test -- --logfile log.txt overrides test results when running multiple testers #105424

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

Open
voidbar opened this issue Dec 7, 2022 · 1 comment
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@voidbar
Copy link

voidbar commented Dec 7, 2022

Problem

When running cargo test -- --logfile log.txt, all testers will write their logs into log.txt, meaning that for project with more than 1 test executable, this will result in log.txt being overridden by the last test run.

Steps

Create a project with 2 different test modules. 2 different tester executables will be created when running cargo --test

Possible Solution(s)

Introduce new command line argument such as --logsuffix and --logdir. The tester will append a random string to the log name. Example:

mkdir out
cargo test -- --logdir "out" --logsuffix "-ut.txt"
# Tests running...
ls out/
{tester_name}-{random_1}-ut.txt {tester_name}-{random_2}-ut.txt {tester_name}-{random_3}-ut.txt

Notes

The proposed solution will be especially useful when dealing with CI systems, needing to consume JUint reports (where piping result to a single file wouldn't work because it won't be a valid XML):

mkdir out
cargo test -- -Z unstable-options --format junit --report-time --logdir "out" --logsuffix "-ut.xml"
# Tests running
# Let CI digest out/ dir *-ut.xml files

Version

cargo 1.65.0 (4bc8f24d3 2022-10-20)
@voidbar voidbar added the C-bug Category: This is a bug. label Dec 7, 2022
@ehuss ehuss transferred this issue from rust-lang/cargo Dec 7, 2022
@ehuss
Copy link
Contributor

ehuss commented Dec 7, 2022

Transferred to rust-lang/rust since logging is part of libtest and it lives here.

@Enselic Enselic added A-libtest Area: `#[test]` / the `test` library T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage-legacy labels Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

4 participants