Skip to content

Commit cf2682a

Browse files
committed
Chalk Overview: Fill in testing section
1 parent 7f14c82 commit cf2682a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/traits/chalk-overview.md

+32-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ No possible solution.
4949
Ambiguous; no inference guidance
5050
```
5151

52-
You can see more examples of programs and queries in the [unit tests][chalk-tests].
52+
You can see more examples of programs and queries in the [unit
53+
tests][chalk-test-example].
5354

5455
Next we'll go through each stage required to produce the output above.
5556

@@ -175,11 +176,29 @@ Chalk's functionality is broken up into the following crates:
175176

176177
## Testing
177178

178-
TODO: Basically, [there is a macro](https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/solve/test.rs#L112-L148)
179-
that will take chalk's Rust-like syntax and run it through the full pipeline
180-
described above.
181-
[This](https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/solve/test.rs#L83-L110)
182-
is the function that is ultimately called.
179+
chalk has a test framework for lowering programs to logic, checking the
180+
lowered logic, and performing queries on it. This is how we test the
181+
implementation of chalk itself, and the viability of the [lowering
182+
rules][lowering-rules].
183+
184+
The main kind of tests in chalk are **goal tests**. They contain a program,
185+
which is expected to lower to logic successfully, and a set of queries
186+
(goals) along with the expected output. Here's an
187+
[example][chalk-test-example]. Since chalk's output can be quite long, goal
188+
tests support specifying only a prefix of the output.
189+
190+
**Lowering tests** check the stages that occur before we can issue queries
191+
to the solver: the [lowering to rust_ir][chalk-test-lowering], and the
192+
[well-formedness checks][chalk-test-wf] that occur after that.
193+
194+
### Testing internals
195+
196+
Goal tests use a [`test!` macro][test-macro] that takes chalk's Rust-like
197+
syntax and runs it through the full pipeline described above. The macro
198+
ultimately calls the [`solve_goal` function][solve_goal].
199+
200+
Likewise, lowering tests use the [`lowering_success!` and
201+
`lowering_error!` macros][test-lowering-macros].
183202

184203
## More Resources
185204

@@ -222,11 +241,17 @@ is the function that is ultimately called.
222241

223242
[binders-struct]: https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/ir.rs#L661
224243
[chalk-ast]: https://github.com/rust-lang-nursery/chalk/blob/master/chalk-parse/src/ast.rs
225-
[chalk-tests]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L115
244+
[chalk-test-example]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L115
245+
[chalk-test-lowering-example]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/rust_ir/lowering/test.rs#L8-L31
246+
[chalk-test-lowering]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/rust_ir/lowering/test.rs
247+
[chalk-test-wf]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/rules/wf/test.rs#L1
226248
[chalki]: https://rust-lang-nursery.github.io/chalk/doc/chalki/index.html
227249
[clause]: https://github.com/rust-lang-nursery/chalk/blob/master/GLOSSARY.md#clause
228250
[coherence-src]: https://github.com/rust-lang-nursery/chalk/blob/master/src/coherence.rs
229251
[ir-code]: https://github.com/rust-lang-nursery/chalk/blob/master/src/rust_ir.rs
230252
[rules-environment]: https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/rules.rs#L9
231253
[rules-src]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/rules.rs
232254
[rules-wf-src]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/rules/wf.rs
255+
[solve_goal]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L85
256+
[test-lowering-macros]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test_util.rs#L21-L54
257+
[test-macro]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L33

0 commit comments

Comments
 (0)