@@ -81,20 +81,18 @@ Now that our tests are accessible from the root of our crate, we need to do
81
81
something with them. ` libsyntax ` generates a module like so:
82
82
83
83
``` rust,ignore
84
- pub mod __test {
84
+ #[main]
85
+ pub fn main() {
85
86
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, /*...*/]);
92
88
}
93
89
```
94
90
91
+ where ` path::to::test1 ` is a constant of type ` test::TestDescAndFn ` .
92
+
95
93
While this transformation is simple, it gives us a lot of insight into how
96
94
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
98
96
` TestDescAndFn ` is, but for now, the key takeaway is that there is a crate
99
97
called [ ` test ` ] [ test ] that is part of Rust core, that implements all of the
100
98
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
119
117
into a struct called [ ` TestDesc ` ] [ TestDesc ] . For each test function in a
120
118
crate, ` libsyntax ` will parse its attributes and generate a ` TestDesc `
121
119
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
123
121
on. For a given test, the generated ` TestDescAndFn ` instance looks like so:
124
122
125
123
``` rust,ignore
@@ -151,4 +149,4 @@ $ rustc my_mod.rs -Z unpretty=hir
151
149
[ Symbol ] : https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.Ident.html
152
150
[ Ident ] : https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.Ident.html
153
151
[ 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