Skip to content

Commit 2a832a0

Browse files
committed
Ignore tests failing due to lack of fn main
While the commit message on this one sounds terrible, it's really not so bad. The issue is that our test runner _expects_ a `fn main() {}` in code blocks that it'll test, but this code really shouldn't have them. If it did, then clicking the "play" link in the docs would result in play.rust-lang.org not treating this code as a test example to be run.
1 parent 4cf7644 commit 2a832a0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/doc/book/testing.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $ cd adder
2323
Cargo will automatically generate a simple test when you make a new project.
2424
Here's the contents of `src/lib.rs`:
2525

26-
```rust
26+
```rust,ignore
2727
# // The next line exists to trick play.rust-lang.org into running our code as a
2828
# // test:
2929
# // fn main
@@ -38,7 +38,7 @@ mod tests {
3838

3939
For now, let's remove the `mod` bit, and focus on just the function:
4040

41-
```rust
41+
```rust,ignore
4242
# // The next line exists to trick play.rust-lang.org into running our code as a
4343
# // test:
4444
# // fn main
@@ -81,8 +81,10 @@ test it_works ... ok
8181
Note the `it_works`. This comes from the name of our function:
8282

8383
```rust
84+
# fn main() {
8485
fn it_works() {
8586
}
87+
# }
8688
```
8789

8890
We also get a summary line:
@@ -94,7 +96,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
9496
So why does our do-nothing test pass? Any test which doesn't `panic!` passes,
9597
and any test that does `panic!` fails. Let's make our test fail:
9698

97-
```rust
99+
```rust,ignore
98100
# // The next line exists to trick play.rust-lang.org into running our code as a
99101
# // test:
100102
# // fn main
@@ -169,7 +171,7 @@ This is useful if you want to integrate `cargo test` into other tooling.
169171

170172
We can invert our test's failure with another attribute: `should_panic`:
171173

172-
```rust
174+
```rust,ignore
173175
# // The next line exists to trick play.rust-lang.org into running our code as a
174176
# // test:
175177
# // fn main
@@ -204,7 +206,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
204206
Rust provides another macro, `assert_eq!`, that compares two arguments for
205207
equality:
206208

207-
```rust
209+
```rust,ignore
208210
# // The next line exists to trick play.rust-lang.org into running our code as a
209211
# // test:
210212
# // fn main
@@ -243,7 +245,7 @@ parameter can be added to the `should_panic` attribute. The test harness will
243245
make sure that the failure message contains the provided text. A safer version
244246
of the example above would be:
245247

246-
```rust
248+
```rust,ignore
247249
# // The next line exists to trick play.rust-lang.org into running our code as a
248250
# // test:
249251
# // fn main
@@ -280,7 +282,7 @@ some known arguments and compare it to the expected output.
280282
Sometimes a few specific tests can be very time-consuming to execute. These
281283
can be disabled by default by using the `ignore` attribute:
282284

283-
```rust
285+
```rust,ignore
284286
# // The next line exists to trick play.rust-lang.org into running our code as a
285287
# // test:
286288
# // fn main

0 commit comments

Comments
 (0)