Stream: t-compiler/wg-rls-2.0

Topic: running tests


nikomatsakis (Mar 12 2020 at 10:41, on Zulip):

Hey, I'm trying to adopt vscode+rust-analyzer instead of my beloved emacs for some chalk hacking. I have a kind of silly question. How do I run tests? I can go to the Terminal and do cargo test --all but I was hoping there is some more "integrated" way for me to do this. (Chalk's tests in particular are mostly in a test directory.)

nikomatsakis (Mar 12 2020 at 10:42, on Zulip):

In any case is there a way to run cargo test via some shortcut or something?

nikomatsakis (Mar 12 2020 at 10:42, on Zulip):

Ah, I do see a "run test" popup highlighted over #[test] functions

nikomatsakis (Mar 12 2020 at 10:42, on Zulip):

I guess that will do

std::Veetaha (Mar 12 2020 at 10:45, on Zulip):

@nikomatsakis I'd recommend using this extension to run a test in a debugger. There is some work on merging this functionality to rust-analyzer. Beware that you also need vscode-lldb debug adapter extension to make it happen.

nikomatsakis (Mar 12 2020 at 10:46, on Zulip):

interesting

nikomatsakis (Mar 12 2020 at 10:52, on Zulip):

Side note that powershell doesn't seem to support FOO=BAR notation for setting environment variables for a single command; that's annoying

matklad (Mar 12 2020 at 10:57, on Zulip):

@nikomatsakis I generally use Rust Analyzer: Run which runs a single test/single test module at the cursor. It doesn't have a shortctut by default, but it's a good idea to assign one

matklad (Mar 12 2020 at 10:57, on Zulip):

run-tests.gif

matklad (Mar 12 2020 at 10:58, on Zulip):

run.gif

matklad (Mar 12 2020 at 11:00, on Zulip):

For running the whole test suite, I just run cargo qt in an external terminal.

I'd love to add an ability to run a cargo command with completion for arguments (which would be smarter than bash completion, b/c it can suggest packages for -p argument). This feature is implemented in IntelliJ, but VS Code I think lacks the necessary UI for it.

matklad (Mar 12 2020 at 11:01, on Zulip):

Also note that Rust Analyzer: Run remembers the last test you've run. So my typical workflow is:

  1. Using worksapce symbol/document symbol go to the interesting test
  2. Run it once with a shortcut
  3. Go back to hacking on the code, re-runing this single test with a shortcut
matklad (Mar 12 2020 at 11:11, on Zulip):

Coincidentally, the bot just said that the request for "command with completion for arguments" goes to vscode backlog: https://github.com/microsoft/vscode/issues/35785#issuecomment-478551918 :)

bjorn3 (Mar 12 2020 at 11:17, on Zulip):

It actually said the issue hasn't received enough upvotes yet. There are 10 more days to upvote.

Kirill Bulatov (Mar 12 2020 at 12:42, on Zulip):

I think we're able to create something like this in VS Code at least:

image.png

React on the input text change, propose the autocompleted options below, remember the input to be able to rerun the action with it (I think the last item is done by VS Code automatically)

I sometimes miss the possibility to constantly rerun the cargo check --all-targets or cargo clippy while iteratively fixing all the issue that pop up.
If I'm not mistaken, RA will also be able to parse this output to highlight the problems and provide the assists.

Kirill Bulatov (Mar 12 2020 at 12:43, on Zulip):

(the screenshot is the Run Cargo Command Action provided by intellij-rust)

std::Veetaha (Mar 12 2020 at 13:04, on Zulip):

@Kirill Bulatov The guy that created the issue referenced by matklad said:

There's also the quick picker, but as far as I know, it doesn't allow you to dynamically update the available options depending on what has been typed in.

Last update: Sep 22 2020 at 02:00UTC