question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[new feature] add a `Cargo test` debug configuration

See original GitHub issue

While it’s somehow possible to work this around, there should be a simple option to run cargo test in a debugging session.

The way I currently do it is:

  • run cargo test in a shell
  • take note of the (random) executable name generated by cargo in the target directory
  • create a new debug profile using the executable above rather than the default executable name

This is error prone as you have to remember to change the debug profile when the test executable name changes (otherwise gdb will load a binary which is out of sync with the source code)

The way it should be is:

  • create a new cargo test profile
  • choose the project in the created profile
  • profit!

This may actually require changes in Cargo to set/get the temp il

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:42 (35 by maintainers)

github_iconTop GitHub Comments

2reactions
norrucommented, Apr 4, 2019

Solution 1) works (needs some Json parsing)

norru@GBWWSRUNUBWS02:~/Projects/itadinanta/rust-oids$ cargo test --no-run --message-format=json 2>/dev/null | jq --raw-output -M ".executable" | grep -v null

/home/norru/Projects/itadinanta/rust-oids/target/debug/rust_oids-d9c4a6ba4677afc4
1reaction
norrucommented, Apr 4, 2019

@mickaelistria good find. I think there is a solution for us which requires no changes in Cargo.

@gbutler69 if we want to attempt to implement a profile, think there is a solution there: In the link to https://github.com/rust-lang/cargo/issues/1924 @mickaelistria provided:

cargo test --no-run --message-format=json produces a list just built binaries in JSON format.

We can run this as the preliminary build step, parse the output (this is the bit we need implementation for), somehow filter the list to match the correct executable and then feed the result to gdb in the usual way.

Nevertheless, I will give hacking cargo-test a go just to see how hard it is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cargo test - The Cargo Book
Compile and execute unit, integration, and documentation tests. The test filtering argument TESTNAME and all the arguments following the two dashes ( --...
Read more >
Run a Cargo command - Rust - JetBrains Marketplace
Go to Run | Edit Configurations. · To create a new configuration, click · After saving the configuration, select it in the configuration...
Read more >
Testing - The Rust Programming Language
At its simplest, a test in Rust is a function that's annotated with the test attribute. Let's make a new project with Cargo...
Read more >
Can tests be built in release mode using Cargo?
cargo test --release exists, but it is slightly different than just enabling optimizations. For example, debug assertions become disabled.
Read more >
Testing & Debugging Rust Code - Firefox Source Docs - Mozilla
If a Mozilla crate has “normal” Rust tests (i.e. #[test] functions that run with cargo test ), you can add the crate's name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found