@@ -119,14 +119,6 @@ names have meaning.
119
119
bar;` is equivalent to ` mod bar { /* contents of foo.rs * / }`. The path is
120
120
taken relative to the directory that the current module is in.
121
121
122
- ## Function-only attributes
123
-
124
- - ` test ` - indicates that this function is a test function, to only be compiled
125
- in case of ` --test ` .
126
- - ` ignore ` - indicates that this test function is disabled.
127
- - ` should_panic ` - indicates that this test function should panic, inverting the
128
- success condition.
129
-
130
122
## FFI attributes
131
123
132
124
On an ` extern ` block, the following attributes are interpreted:
@@ -228,6 +220,42 @@ are transformed into `doc` attributes.
228
220
229
221
See [ The Rustdoc Book] for reference material on this attribute.
230
222
223
+ ### Testing
224
+
225
+ The compiler comes with a default test framework. It works by attributing
226
+ functions with the ` test ` attribute. These functions are only compiled when
227
+ compiling with the test harness. Like [ main] , functions annotated with this
228
+ attribute must take no arguments, must not declare any
229
+ [ trait or lifetime bounds] , must not have any [ where clauses] , and its return
230
+ type must be one of the following:
231
+
232
+ * ` () `
233
+ <!-- * `!` -->
234
+ * ` Result<(), E> where E: Error `
235
+ <!-- * Result<!, E> where E: Error` -->
236
+
237
+ > Note: The implementation of which return types are allowed is determined by
238
+ > the unstable [ ` Termination ` ] trait.
239
+
240
+ <!-- If the previous section needs updating (from "must take no arguments"
241
+ onwards, also update it in the crates-and-source-files.md file -->
242
+
243
+ > Note: The test harness is ran by passing the ` --test ` argument to ` rustc ` or
244
+ > using ` cargo test ` .
245
+
246
+ Tests that return ` () ` pass as long as they terminate do not panic. Tests that
247
+ return a ` Result ` pass as long as they return ` Ok(()) ` . Tests that do not
248
+ terminate neither pass nor fail.
249
+
250
+ A function annotated with the ` test ` attribute can also be annotated with the
251
+ ` ignore ` attribute. The * ` ignore ` attribute* tells the test harness to not
252
+ execute that function as a test. It will still only be compiled when compiling
253
+ with the test harness.
254
+
255
+ A function annotated with the ` test ` attribute that returns ` () ` can also be
256
+ annotated with the ` should_panic ` attribute. The * ` should_panic ` attribute*
257
+ makes the test only pass if it actually panics.
258
+
231
259
### Conditional compilation
232
260
233
261
The ` cfg ` and ` cfg_attr ` attributes control conditional compilation of [ items]
@@ -499,4 +527,8 @@ You can implement `derive` for your own traits through [procedural macros].
499
527
[ external blocks ] : items/external-blocks.html
500
528
[ items ] : items.html
501
529
[ conditional compilation ] : conditional-compilation.html
502
- [ trait ] : items/traits.html
530
+ [ trait ] : items/traits.html
531
+ [ main ] : crates-and-source-files.html
532
+ [ `Termination` ] : ../std/process/trait.Termination.html
533
+ [ where clause ] : items/where-clauses.html
534
+ [ trait or lifetime bounds ] : trait-bounds.html
0 commit comments