Skip to content

Commit 0657657

Browse files
committed
Add identifier syntax to attributes.testing
1 parent 8f980cb commit 0657657

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/attributes/testing.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
# Testing attributes
22

3+
r[attributes.testing]
4+
35
The following [attributes] are used for specifying functions for performing
46
tests. Compiling a crate in "test" mode enables building the test functions
57
along with a test harness for executing the tests. Enabling the test mode also
68
enables the [`test` conditional compilation option].
79

810
## The `test` attribute
911

10-
The *`test` attribute* marks a function to be executed as a test. These
11-
functions are only compiled when in test mode. Test functions must be free,
12-
monomorphic functions that take no arguments, and the return type must implement the [`Termination`] trait, for example:
12+
r[attributes.testing.test]
13+
14+
15+
r[attributes.testing.test.general]
16+
The *`test` attribute* marks a function to be executed as a test.
17+
18+
r[attributes.testing.test.enabled]
19+
These functions are only compiled when in test mode.
20+
21+
r[attributes.testing.test.restriction]
22+
Test functions must be free, monomorphic functions that take no arguments, and the return type must implement the [`Termination`] trait, for example:
1323

1424
* `()`
1525
* `Result<T, E> where T: Termination, E: Debug`
@@ -21,6 +31,7 @@ monomorphic functions that take no arguments, and the return type must implement
2131
> Note: The test mode is enabled by passing the `--test` argument to `rustc`
2232
> or using `cargo test`.
2333
34+
r[attributes.testing.success]
2435
The test harness calls the returned value's [`report`] method, and classifies the test as passed or failed depending on whether the resulting [`ExitCode`] represents successful termination.
2536
In particular:
2637
* Tests that return `()` pass as long as they terminate and do not panic.
@@ -42,10 +53,15 @@ fn test_the_thing() -> io::Result<()> {
4253

4354
## The `ignore` attribute
4455

56+
r[attributes.testing.ignore]
57+
58+
59+
r[attributes.testing.ignore.general]
4560
A function annotated with the `test` attribute can also be annotated with the
4661
`ignore` attribute. The *`ignore` attribute* tells the test harness to not
4762
execute that function as a test. It will still be compiled when in test mode.
4863

64+
r[attributes.testing.ignore.syntax]
4965
The `ignore` attribute may optionally be written with the [_MetaNameValueStr_]
5066
syntax to specify a reason why the test is ignored.
5167

@@ -62,10 +78,17 @@ fn mytest() {
6278
6379
## The `should_panic` attribute
6480

81+
r[attributes.testing.should_panic]
82+
83+
r[attributes.testing.should_panic.restriction]
6584
A function annotated with the `test` attribute that returns `()` can also be
66-
annotated with the `should_panic` attribute. The *`should_panic` attribute*
85+
annotated with the `should_panic` attribute.
86+
87+
r[attributes.testing.should_panic.behaviour]
88+
The *`should_panic` attribute*
6789
makes the test only pass if it actually panics.
6890

91+
r[attributes.testing.should_panic.syntax]
6992
The `should_panic` attribute may optionally take an input string that must
7093
appear within the panic message. If the string is not found in the message,
7194
then the test will fail. The string may be passed using the

0 commit comments

Comments
 (0)