@@ -23,7 +23,7 @@ $ cd adder
23
23
Cargo will automatically generate a simple test when you make a new project.
24
24
Here's the contents of ` src/lib.rs ` :
25
25
26
- ``` rust
26
+ ``` rust,ignore
27
27
# // The next line exists to trick play.rust-lang.org into running our code as a
28
28
# // test:
29
29
# // fn main
@@ -38,7 +38,7 @@ mod tests {
38
38
39
39
For now, let's remove the ` mod ` bit, and focus on just the function:
40
40
41
- ``` rust
41
+ ``` rust,ignore
42
42
# // The next line exists to trick play.rust-lang.org into running our code as a
43
43
# // test:
44
44
# // fn main
@@ -81,8 +81,10 @@ test it_works ... ok
81
81
Note the ` it_works ` . This comes from the name of our function:
82
82
83
83
``` rust
84
+ # fn main () {
84
85
fn it_works () {
85
86
}
87
+ # }
86
88
```
87
89
88
90
We also get a summary line:
@@ -94,7 +96,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
94
96
So why does our do-nothing test pass? Any test which doesn't ` panic! ` passes,
95
97
and any test that does ` panic! ` fails. Let's make our test fail:
96
98
97
- ``` rust
99
+ ``` rust,ignore
98
100
# // The next line exists to trick play.rust-lang.org into running our code as a
99
101
# // test:
100
102
# // fn main
@@ -169,7 +171,7 @@ This is useful if you want to integrate `cargo test` into other tooling.
169
171
170
172
We can invert our test's failure with another attribute: ` should_panic ` :
171
173
172
- ``` rust
174
+ ``` rust,ignore
173
175
# // The next line exists to trick play.rust-lang.org into running our code as a
174
176
# // test:
175
177
# // fn main
@@ -204,7 +206,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
204
206
Rust provides another macro, ` assert_eq! ` , that compares two arguments for
205
207
equality:
206
208
207
- ``` rust
209
+ ``` rust,ignore
208
210
# // The next line exists to trick play.rust-lang.org into running our code as a
209
211
# // test:
210
212
# // fn main
@@ -243,7 +245,7 @@ parameter can be added to the `should_panic` attribute. The test harness will
243
245
make sure that the failure message contains the provided text. A safer version
244
246
of the example above would be:
245
247
246
- ``` rust
248
+ ``` rust,ignore
247
249
# // The next line exists to trick play.rust-lang.org into running our code as a
248
250
# // test:
249
251
# // fn main
@@ -280,7 +282,7 @@ some known arguments and compare it to the expected output.
280
282
Sometimes a few specific tests can be very time-consuming to execute. These
281
283
can be disabled by default by using the ` ignore ` attribute:
282
284
283
- ``` rust
285
+ ``` rust,ignore
284
286
# // The next line exists to trick play.rust-lang.org into running our code as a
285
287
# // test:
286
288
# // fn main
0 commit comments