cargo icon indicating copy to clipboard operation
cargo copied to clipboard

BUG: The output results of cargo test and cargo run seem to be different

Open yymm120 opened this issue 1 year ago • 5 comments

bug description

I placed the configuration folder in the root path and when I cargo run everything works fine. But cargo test keeps failing. It wants me to put the configuration folder inside src-axum.

Then I found that cargo test and cargo run output different results

cargo run

image image

cargo test

image image

environment

in workspace image

os: ubuntu !❯ rustup --version rustup 1.27.1 (54dd3d00f 2024-04-24) info: This is the version for the rustup toolchain manager, not the rustc compiler. info: The currently active rustc version is `rustc 1.80.0 (051478957 2024-07-21)

yymm120 avatar Aug 02 '24 13:08 yymm120

image

In this case I had to place two configuration folders to make everything look normal. After this error, I'm not sure whether cargo test is trustworthy anymore. Should I always cargo run

yymm120 avatar Aug 02 '24 13:08 yymm120

@rustbot label -needs-triage @rustbot transfer cargo

fmease avatar Aug 02 '24 14:08 fmease

As the reproduction steps involve third-party commands that I'm not as familiar with and is focusing on inferring the problem from screenshots rather than explicitly calling things out, this is going to be a guess as to what is going on .

It looks like the concern is with cargo run running the binary in the current working directory while cargo test is running the test harness in the package root.

This is expected behavior. cargo run is trying to act as if you ran the binary directly. cargo test needs a predictable location to run the test for accessing fixtures, independent of what your current working directory is.

epage avatar Aug 02 '24 14:08 epage

I'm not too sure how config fits into this. In general, config is environmental configuration and is dependent on the current working directory that cargo was run in.

epage avatar Aug 02 '24 14:08 epage

@rustbot transfer cargo

TIL 😬

This is expected behavior. cargo run is trying to act as if you ran the binary directly. cargo test needs a predictable location to run the test for accessing fixtures, independent of what your current working directory is.

For the reference, see the cargo-test doc:

The working directory when running each unit and integration test is set to the root directory of the package the test belongs to. Setting the working directory of tests to the package’s root directory makes it possible for tests to reliably access the package’s files using relative paths, regardless from where cargo test was executed from.

weihanglo avatar Aug 02 '24 15:08 weihanglo