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