|
2 | 2 |
|
3 | 3 | ## Testing the dependency graph |
4 | 4 |
|
5 | | -There are various ways to write tests against the dependency graph. |
6 | | -The simplest mechanisms are the `#[rustc_if_this_changed]` and |
7 | | -`#[rustc_then_this_would_need]` annotations. These are used in ui tests |
8 | | -to test whether the expected set of paths exist in the dependency graph. |
9 | | -As an example, see `tests/ui/dep-graph/dep-graph-caller-callee.rs`. |
| 5 | +There are various ways to write tests against the dependency graph. The |
| 6 | +simplest mechanisms are the `#[rustc_if_this_changed]` and |
| 7 | +`#[rustc_then_this_would_need]` annotations. These are used in [ui] tests to test |
| 8 | +whether the expected set of paths exist in the dependency graph. |
10 | 9 |
|
11 | | -The idea is that you can annotate a test like: |
| 10 | +[`tests/ui/dep-graph/dep-graph-caller-callee.rs`]: https://github.com/rust-lang/rust/blob/master/tests/ui/dep-graph/dep-graph-caller-callee.rs |
| 11 | +[ui]: tests/ui.html |
| 12 | + |
| 13 | +As an example, see [`tests/ui/dep-graph/dep-graph-caller-callee.rs`], or the |
| 14 | +tests below. |
12 | 15 |
|
13 | 16 | ```rust,ignore |
14 | 17 | #[rustc_if_this_changed] |
15 | 18 | fn foo() { } |
16 | 19 |
|
17 | 20 | #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK |
18 | 21 | fn bar() { foo(); } |
| 22 | +``` |
| 23 | + |
| 24 | +This should be read as |
| 25 | +> If this (`foo`) is changed, then this (i.e. `bar`)'s TypeckTables would need |
| 26 | + to be changed. Also, this |
19 | 27 |
|
| 28 | +You could also add the lines |
| 29 | + |
| 30 | +```rust,ignore |
20 | 31 | #[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path |
21 | 32 | fn baz() { } |
22 | 33 | ``` |
23 | 34 |
|
24 | | -This will check whether there is a path in the dependency graph from `Hir(foo)` |
25 | | -to `TypeckTables(bar)`. An error is reported for each |
26 | | -`#[rustc_then_this_would_need]` annotation that indicates whether a path |
27 | | -exists. `//~ ERROR` annotations can then be used to test if a path is found (as |
28 | | -demonstrated above). |
| 35 | +Whose meaning is |
| 36 | +> If `foo` is changed, then `baz`'s TypeckTables does not need to be changed, as there is no path. |
| 37 | +
|
| 38 | +Recall that the `//~ ERROR OK` is a comment from the point of view of the Rust |
| 39 | +code we test, but is meaningful from the point of view of the test itself. |
29 | 40 |
|
30 | 41 | ## Debugging the dependency graph |
31 | 42 |
|
|
0 commit comments