rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.06k stars 1.56k forks source link

Feature Request: Code Lens to run test with UPDATE_EXPECT=1 #10224

Open alanz opened 3 years ago

alanz commented 3 years ago

If a test uses an expect-test assertion, add an additional code lens to run the test with UPDATE_EXPECT set to 1, so the test gets updated.

vsrs commented 2 years ago

@alanz please check this section: https://rust-analyzer.github.io/manual.html#setting-runnable-environment-variables, you can set env variables manually

alanz commented 2 years ago

you can set env variables manually

Perhaps I am doing it wrong, but I find I change code, then a test fails. I need to inspect the diff presented by expect-test to decide if it is an acceptable change, or if it is flagging a problem.

Setting UPDATE_EXPECT=1 always basically negates the usefulness of the tests, as it just silently updates them.

So I would like to be able to run a test with the flag off, see the result, and have an easy option to accept it by running it with the flag on.

Wilfred commented 6 months ago

I see there is some support for setting UPDATE_EXPECT=1 already, added in #5101. I'm not sure how to use it though.

alanz commented 6 months ago

I'm not sure how to use it though.

In emacs, with lsp-mode, put your cursor on an expect! macro in the test, then M-x lsp-rust-analyzer-run should give an option to run with update expect. See https://github.com/emacs-lsp/lsp-mode/pull/3597