Skip to content

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

Open
@voidbar

Description

@voidbar

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions