simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 158 forks source link

debugging single test runs the main program instead (nonconsistently) #313

Closed sveatlo closed 1 year ago

sveatlo commented 1 year ago

I have a minimal example project with a main.rs and lib.rs files in src directory and adding.rs file in tests directory

When I call :RustDebuggables and select test --no-run --package tests-debug-dap-async --test addition -- test_add --nocapture it often runs the main program in the debugger outputting:

1+2=3

[Process exited 0]

It doesn't happen all the time and rerunning the debuggable it eventually gets to running the test, but rerunning it again (maybe couple of times) gets me back to running the main program.

I've turned on dap debugging using :DapSetLogLevel TRACE and here are the output logs: incorrect case, correct case. In the "incorrect" case's "request" log line, you can clearly see it is running target/debug/tests-debug-dap-async instead of target/debug/deps/addition-acbfb4ac66cbe508 even though they were started using the same debuggable command.

Gist with the code used: https://gist.github.com/sveatlo/3573851140184a9a3e890526c8d6cdfa

EDIT: It seems it may also happen with other debuggable test types. I've managed to get the same results with both test --no-run --package tests-debug-dap-async --all-targets and test --no-run --package tests-debug-dap-async --test addition -- --nocapture

EDIT 2: I forgot to add that I'm using codelldb, but results are consistent with lldb-vscode.

sveatlo commented 1 year ago

I've been debugging this some more and I've found out, that running cargo test in dap.lua:start(...) outputs 3 (in this case) "compiler artifacts". These artifacts contain both the main executable and the specific test I want to run, but the order seem to be nondeterministic and therefore whichever artifact with non-nil executable property is first gets executed (artifacts with nil executable are filtered out)

correct example incorrect example