diff options
-rw-r--r-- | docs/dev/architecture.md | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index 3cd63bf73..f990d5bf0 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md | |||
@@ -171,4 +171,29 @@ A CLI interface to rust-analyzer. | |||
171 | 171 | ||
172 | ## Testing Infrastructure | 172 | ## Testing Infrastructure |
173 | 173 | ||
174 | 174 | Rust Analyzer has three interesting [systems | |
175 | boundaries](https://www.tedinski.com/2018/04/10/making-tests-a-positive-influence-on-design.html) | ||
176 | to concentrate tests on. | ||
177 | |||
178 | The outermost boundary is the `ra_lsp_server` crate, which defines an LSP | ||
179 | interface in terms of stdio. We do integration testing of this component, by | ||
180 | feeding it with a stream of LSP requests and checking responses. These tests are | ||
181 | known as "heavy", because they interact with Cargo and read real files from | ||
182 | disk. For this reason, we try to avoid writing too many tests on this boundary: | ||
183 | in a statically typed language, it's hard to make an error in the protocol | ||
184 | itself if messages are themselves typed. | ||
185 | |||
186 | The middle, and most important, boundary is `ra_ide_api`. Unlike | ||
187 | `ra_lsp_server`, which exposes API, `ide_api` uses Rust API and is intended to | ||
188 | use by various tools. Typical test creates an `AnalysisHost`, calls some | ||
189 | `Analysis` functions and compares the results against expectation. | ||
190 | |||
191 | The innermost and most elaborate boundary is `hir`. It has a much richer | ||
192 | vocabulary of types than `ide_api`, but the basic testing setup is the same: we | ||
193 | create a database, run some queries, assert result. | ||
194 | |||
195 | For comparisons, we use [insta](https://github.com/mitsuhiko/insta/) library for | ||
196 | snapshot testing. | ||
197 | |||
198 | To test various analysis corner cases and avoid forgetting about old tests, we | ||
199 | use so-called marks. See the `marks` module in the `test_utils` crate for more. | ||