Skip to content

Commit 72ef2bd

Browse files
committed
Auto merge of #9904 - ehuss:contrib-debug-test, r=alexcrichton
Add some contributor docs for debugging testsuite tests. This adds some suggestions on how to debug testsuite tests. Closes #9757
2 parents ed8590e + f437af3 commit 72ef2bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/doc/contrib/src/tests/writing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,39 @@ If you need to test with registry dependencies, see
123123
If you need to test git dependencies, see [`support::git`] to create a git
124124
dependency.
125125

126+
## Debugging tests
127+
128+
In some cases, you may need to dig into a test that is not working as you
129+
expect, or you just generally want to experiment within the sandbox
130+
environment. The general process is:
131+
132+
1. Build the sandbox for the test you want to investigate. For example:
133+
134+
`cargo test --test testsuite -- features2::inactivate_targets`.
135+
2. In another terminal, head into the sandbox directory to inspect the files and run `cargo` directly.
136+
1. The sandbox directories start with `t0` for the first test.
137+
138+
`cd target/tmp/cit/t0`
139+
2. Set up the environment so that the sandbox configuration takes effect:
140+
141+
`export CARGO_HOME=$(pwd)/home/.cargo`
142+
3. Most tests create a `foo` project, so head into that:
143+
144+
`cd foo`
145+
3. Run whatever cargo command you want. See [Running Cargo] for more details
146+
on running the correct `cargo` process. Some examples:
147+
148+
* `/path/to/my/cargo/target/debug/cargo check`
149+
* Using a debugger like `lldb` or `gdb`:
150+
1. `lldb /path/to/my/cargo/target/debug/cargo`
151+
2. Set a breakpoint, for example: `b generate_targets`
152+
3. Run with arguments: `r check`
153+
126154
[`testsuite`]: https://github.com/rust-lang/cargo/tree/master/tests/testsuite/
127155
[`ProjectBuilder`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/crates/cargo-test-support/src/lib.rs#L225-L231
128156
[`Execs`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/crates/cargo-test-support/src/lib.rs#L558-L579
129157
[`support`]: https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/lib.rs
130158
[`support::compare`]: https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/compare.rs
131159
[`support::registry::Package`]: https://github.com/rust-lang/cargo/blob/e4b65bdc80f2a293447f2f6a808fa7c84bf9a357/crates/cargo-test-support/src/registry.rs#L73-L149
132160
[`support::git`]: https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/git.rs
161+
[Running Cargo]: ../process/working-on-cargo.md#running-cargo

0 commit comments

Comments
 (0)