@@ -33,7 +33,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
33
33
# Unit testing in Rust
34
34
35
35
Rust has built in support for simple unit testing. Functions can be
36
- marked as unit tests using the ' test' attribute.
36
+ marked as unit tests using the ` test ` attribute.
37
37
38
38
~~~
39
39
#[test]
@@ -44,13 +44,13 @@ fn return_none_if_empty() {
44
44
45
45
A test function's signature must have no arguments and no return
46
46
value. To run the tests in a crate, it must be compiled with the
47
- ' --test' flag: ` rustc myprogram.rs --test -o myprogram-tests ` . Running
47
+ ` --test ` flag: ` rustc myprogram.rs --test -o myprogram-tests ` . Running
48
48
the resulting executable will run all the tests in the crate. A test
49
49
is considered successful if its function returns; if the task running
50
50
the test fails, through a call to ` fail! ` , a failed ` check ` or
51
51
` assert ` , or some other (` assert_eq ` , ...) means, then the test fails.
52
52
53
- When compiling a crate with the ' --test' flag ' --cfg test' is also
53
+ When compiling a crate with the ` --test ` flag ` --cfg test ` is also
54
54
implied, so that tests can be conditionally compiled.
55
55
56
56
~~~
@@ -64,17 +64,17 @@ mod tests {
64
64
~~~
65
65
66
66
Additionally ` #[test] ` items behave as if they also have the
67
- ` #[cfg(test)] ` attribute, and will not be compiled when the --test flag
67
+ ` #[cfg(test)] ` attribute, and will not be compiled when the ` --test ` flag
68
68
is not used.
69
69
70
- Tests that should not be run can be annotated with the ' ignore'
70
+ Tests that should not be run can be annotated with the ` ignore `
71
71
attribute. The existence of these tests will be noted in the test
72
72
runner output, but the test will not be run. Tests can also be ignored
73
73
by configuration so, for example, to ignore a test on windows you can
74
74
write ` #[ignore(cfg(target_os = "win32"))] ` .
75
75
76
76
Tests that are intended to fail can be annotated with the
77
- ' should_fail' attribute. The test will be run, and if it causes its
77
+ ` should_fail ` attribute. The test will be run, and if it causes its
78
78
task to fail then the test will be counted as successful; otherwise it
79
79
will be counted as a failure. For example:
80
80
@@ -87,11 +87,11 @@ fn test_out_of_bounds_failure() {
87
87
}
88
88
~~~
89
89
90
- A test runner built with the ' --test' flag supports a limited set of
90
+ A test runner built with the ` --test ` flag supports a limited set of
91
91
arguments to control which tests are run: the first free argument
92
92
passed to a test runner specifies a filter used to narrow down the set
93
- of tests being run; the ' --ignored' flag tells the test runner to run
94
- only tests with the ' ignore' attribute.
93
+ of tests being run; the ` --ignored ` flag tells the test runner to run
94
+ only tests with the ` ignore ` attribute.
95
95
96
96
## Parallelism
97
97
0 commit comments