rust-analyzer/editors/code/src
bors[bot] d13ded6cbc
Merge #5101
5101: Add expect -- a light-weight alternative to insta r=matklad a=matklad

This PR implements a small snapshot-testing library. Snapshot updating is done by setting an env var, or by using editor feature (which runs  a test with env-var set). 

Here's workflow for updating a failing test:

![expect](https://user-images.githubusercontent.com/1711539/85926956-28afa080-b8a3-11ea-9260-c6d0d8914d0b.gif)

Here's workflow for adding a new test:

![expect-fresh](https://user-images.githubusercontent.com/1711539/85926961-306f4500-b8a3-11ea-9369-f2373e327a3f.gif)

Note that colorized diffs are not implemented in this PR, but should be easy to add (we already use them in test_utils). 

Main differences from insta (which is essential for rust-analyzer development, thanks @mitsuhiko!):
* self-updating tests, no need for a separate tool
* fewer features (only inline snapshots, no redactions)
* fewer deps (no yaml, no persistence)
* tighter integration with editor
* first-class snapshot object, which can be used to write test functions (as opposed to testing macros)
* trivial to tweak for rust-analyzer needs, by virtue of being a workspace member. 

I think eventually we should converge to a single snapshot testing library, but I am not sure that `expect` is exactly right, so I suggest rolling with both insta and expect for some time (if folks agree that expect might be better in the first place!). 

# Editor Integration Implementation 

The thing I am most excited about is the ability to update a specific snapshot from the editor. I want this to be available to other snapshot-testing libraries (cc @mitsuhiko, @aaronabramov), so I want to document how this works. 

The ideal UI here would be a code action (💡). Unfortunately, it seems like it is impossible to implement without some kind of persistence (if you save test failures into some kind of a database, like insta does, than you can read the database from the editor plugin). Note that it is possible to highlight error by outputing error message in rustc's format. Unfortunately, one can't use the same trick to implement a quick fix. 

For this reason, expect makes use of another rust-analyzer feature -- ability to run a single test at the cursor position. This does need some expect-specific code in rust-analyzer unfortunately. Specifically, if rust-analyzer notices that the cursor is on `expect!` macro, it adds a special flag to runnable's JSON. However, given #5017 it is possible to approximate this well-enough without rust-analyzer integration. Specifically, an extension can register a special runner which checks (using regexes) if rust-anlyzer runnable covers text with specific macro invocation and do special magic in that case. 

closes #3835 


Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-30 08:34:08 +00:00
..
ast_inspector.ts Flatten commands.ts 2020-05-25 12:14:44 +02:00
client.ts Remove hover contents marking as trusted. 2020-06-05 15:25:01 +03:00
commands.ts Merge #5119 2020-06-29 16:10:43 +00:00
config.ts Add custom cargo runners 2020-06-24 10:53:49 +03:00
ctx.ts Remove unnecessary async from vscode language client creation 2020-04-25 20:52:50 +03:00
debug.ts Fix rust-analyzer.debug.openDebugPane option 2020-06-18 10:15:42 +03:00
inlay_hints.ts Cleanup lsp extensions on the client side 2020-05-25 14:56:26 +02:00
lsp_ext.ts Add light-weight snapshot testing library with editor integration 2020-06-27 19:22:31 +02:00
main.ts Merge #5017 2020-06-26 16:52:53 +00:00
net.ts Append 10 random hex chars to temp artifact files 2020-06-25 01:00:30 +03:00
persistent_state.ts Rewrite auto-update 2020-03-19 09:04:59 +01:00
run.ts Add light-weight snapshot testing library with editor integration 2020-06-27 19:22:31 +02:00
snippets.ts Less rust-analyzer specific onEnter 2020-05-25 14:28:47 +02:00
tasks.ts Fix ts lints 2020-06-24 12:30:41 +03:00
toolchain.ts Change Runnable.bin -> Runnable.kind 2020-05-31 05:21:45 +03:00
util.ts Never disable error logging on the frontend 2020-06-22 21:30:32 +03:00