Skip to content
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

cargo test --no-run should print the resulting binary name #9957

Closed
matklad opened this issue Oct 4, 2021 · 5 comments · Fixed by #9959 or #10346
Closed

cargo test --no-run should print the resulting binary name #9957

matklad opened this issue Oct 4, 2021 · 5 comments · Fixed by #9959 or #10346
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy

Comments

@matklad
Copy link
Member

matklad commented Oct 4, 2021

Problem:

I am profiling my Rust application, so I want to compile the tests with --no-run and run the binary directly. However, the output doesn't say where the result is:

$ cargo test --no-run --release --package runtime-tester --features nearcore/no_cache --lib -- perf_cliff --exact --nocapture
   Compiling runtime-tester v0.1.0 (/home/matklad/projects/nearcore/test-utils/runtime-tester)
    Finished release [optimized] target(s) in 5.49s
$

I have to manually ls traget/release/deps to get the file name

Proposed solution:

The name is convenientl printed when you don't pass no-run:

$ cargo test --release --package runtime-tester --features nearcore/no_cache --lib -- perf_cliff --exact --nocapture
    Finished release [optimized] target(s) in 0.13s
     Running unittests (target/release/deps/runtime_tester-160c2544f9ae8411)

Would be great to add a message similar to Running target (path) to --no-run output.

@matklad matklad added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 4, 2021
@matklad matklad changed the title cargo test --no-run should pring the resulting binary name cargo test --no-run should print the resulting binary name Oct 4, 2021
@ehuss
Copy link
Contributor

ehuss commented Oct 4, 2021

Hm, yea, as you probably know the usual intended use-case is to use --no-run with JSON. I think it probably would be reasonable to display the executables generated with --no-run. I wouldn't use the status Running since it isn't actually running it, though I'm not sure what to say. Generated? Built? Executable? Those don't sound great to me, but maybe something like that.

In the meantime, one workaround is to use jq:

cargo test --no-run --message-format=json | jq 'select(.reason=="compiler-artifact") | .executable'

@ehuss ehuss added A-console-output Area: Terminal output, colors, progress bar, etc. E-easy Experience: Easy labels Oct 4, 2021
@matklad
Copy link
Member Author

matklad commented Oct 4, 2021

the usual intended use-case is to use --no-run with JSON.

I think no-run actually predates JSON support, so I imagine original use-case was different.

Perhaps

Compiled unittests (target/release/deps/runtime_tester-160c2544f9ae8411)

?

Would also be cool to put the tests into a better location that deps, but target directory layout is a whole different yak

@vrongmeal
Copy link
Contributor

I guess we might also want to do the same for cargo build ?

Anyways, I would like to work on this, if possible.

@ehuss
Copy link
Contributor

ehuss commented Oct 4, 2021

I think no-run actually predates JSON support, so I imagine original use-case was different.

Ah, indeed. Perhaps Alex just used * to glob on the filename hash.

@vrongmeal Sure! I would start off being a little conservative and just add a message when --no-run is used with test or bench. Let me know if you have any questions.

@vrongmeal
Copy link
Contributor

@ehuss I just submitted a draft PR for now: #9959

bors added a commit that referenced this issue Feb 20, 2022
Print executable name on cargo test --no-run #2

Closes #9957

This is a continuation of #9959.
@bors bors closed this as completed in bef4d79 Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-console-output Area: Terminal output, colors, progress bar, etc. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` E-easy Experience: Easy
Projects
None yet
3 participants