@@ -81,20 +81,18 @@ Now that our tests are accessible from the root of our crate, we need to do
8181something 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+
9593While this transformation is simple, it gives us a lot of insight into how
9694tests 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
9997called [ ` test ` ] [ test ] that is part of Rust core, that implements all of the
10098runtime 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
119117into a struct called [ ` TestDesc ` ] [ TestDesc ] . For each test function in a
120118crate, ` libsyntax ` will parse its attributes and generate a ` TestDesc `
121119instance. 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
123121on. 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