Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I build standalone test binary to run under a debugger? [duplicate]

I want to package up a specific unit test into an executable binary that I can run myself under a debugger.

How can I do this with cargo?

like image 593
Eloff Avatar asked Oct 16 '20 23:10

Eloff


1 Answers

Running cargo test results in the following output:

❯ cargo test
   Compiling mycrate v0.1.0 (mycrate)
    Finished test [unoptimized + debuginfo] target(s) in 0.44s
     Running target/debug/deps/mycrate-1a3af12dafb80133

running tests...

As you can see by this line:

Running target/debug/deps/mycrate-1a3af12dafb80133

The test actually is a standalone executable, located in target/debug/deps/.

You can run the executable directly:

❯ ./target/debug/deps/mycrate-1a3af12dafb80133

running tests...

You can also build the executable without running the tests with the no-run flag:

❯ cargo test --no-run
   Compiling mycrate v0.1.0 (mycrate)
    Finished test [unoptimized + debuginfo] target(s) in 0.41s
like image 188
Ibraheem Ahmed Avatar answered Jan 04 '23 07:01

Ibraheem Ahmed