Skip to content

Commit 813cdf6

Browse files
rasendubimark-i-m
authored andcommitted
Update test-implementation chapter to current code
`test_main_static` is now used instead of `test_static_main`. The libsyntax no longer generates a `TESTS` constant but rather passes all test cases directly into `test_main_static` as a slice. Update the guide accordingly.
1 parent aa7bb2b commit 813cdf6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/test-implementation.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,18 @@ Now that our tests are accessible from the root of our crate, we need to do
8181
something with them. `libsyntax` generates a module like so:
8282

8383
```rust,ignore
84-
pub mod __test {
84+
#[main]
85+
pub fn main() {
8586
extern crate test;
86-
const TESTS: &'static [self::test::TestDescAndFn] = &[/*...*/];
87-
88-
#[main]
89-
pub fn main() {
90-
self::test::test_static_main(TESTS);
91-
}
87+
test::test_main_static(&[&path::to::test1, /*...*/]);
9288
}
9389
```
9490

91+
where `path::to::test1` is a constant of type `test::TestDescAndFn`.
92+
9593
While this transformation is simple, it gives us a lot of insight into how
9694
tests are actually run. The tests are aggregated into an array and passed to
97-
a test runner called `test_static_main`. We'll come back to exactly what
95+
a test runner called `test_main_static`. We'll come back to exactly what
9896
`TestDescAndFn` is, but for now, the key takeaway is that there is a crate
9997
called [`test`][test] that is part of Rust core, that implements all of the
10098
runtime for testing. `test`'s interface is unstable, so the only stable way
@@ -119,7 +117,7 @@ configuration information as well. `test` encodes this configuration data
119117
into a struct called [`TestDesc`][TestDesc]. For each test function in a
120118
crate, `libsyntax` will parse its attributes and generate a `TestDesc`
121119
instance. It then combines the `TestDesc` and test function into the
122-
predictably named `TestDescAndFn` struct, that `test_static_main` operates
120+
predictably named `TestDescAndFn` struct, that `test_main_static` operates
123121
on. For a given test, the generated `TestDescAndFn` instance looks like so:
124122

125123
```rust,ignore
@@ -151,4 +149,4 @@ $ rustc my_mod.rs -Z unpretty=hir
151149
[Symbol]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.Ident.html
152150
[Ident]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.Ident.html
153151
[eRFC]: https://github.com/rust-lang/rfcs/blob/master/text/2318-custom-test-frameworks.md
154-
[libsyntax]: https://github.com/rust-lang/rust/tree/master/src/libsyntax
152+
[libsyntax]: https://github.com/rust-lang/rust/tree/master/src/libsyntax

0 commit comments

Comments
 (0)