Skip to content

Commit f66d3c5

Browse files
committed
Rollup merge of #31296 - steveklabnik:gh31249, r=alexcrichton
Rustdoc will automatically wrap things in main, but this doesn't work here. Fixes #31249
2 parents cf0f7a3 + 919ea47 commit f66d3c5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/doc/book/testing.md

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

2626
```rust
27+
# fn main() {}
2728
#[test]
2829
fn it_works() {
2930
}
@@ -75,6 +76,7 @@ So why does our do-nothing test pass? Any test which doesn't `panic!` passes,
7576
and any test that does `panic!` fails. Let's make our test fail:
7677

7778
```rust
79+
# fn main() {}
7880
#[test]
7981
fn it_works() {
8082
assert!(false);
@@ -145,6 +147,7 @@ This is useful if you want to integrate `cargo test` into other tooling.
145147
We can invert our test's failure with another attribute: `should_panic`:
146148

147149
```rust
150+
# fn main() {}
148151
#[test]
149152
#[should_panic]
150153
fn it_works() {
@@ -175,6 +178,7 @@ Rust provides another macro, `assert_eq!`, that compares two arguments for
175178
equality:
176179

177180
```rust
181+
# fn main() {}
178182
#[test]
179183
#[should_panic]
180184
fn it_works() {
@@ -209,6 +213,7 @@ make sure that the failure message contains the provided text. A safer version
209213
of the example above would be:
210214

211215
```rust
216+
# fn main() {}
212217
#[test]
213218
#[should_panic(expected = "assertion failed")]
214219
fn it_works() {
@@ -219,6 +224,7 @@ fn it_works() {
219224
That's all there is to the basics! Let's write one 'real' test:
220225

221226
```rust,ignore
227+
# fn main() {}
222228
pub fn add_two(a: i32) -> i32 {
223229
a + 2
224230
}
@@ -238,6 +244,7 @@ Sometimes a few specific tests can be very time-consuming to execute. These
238244
can be disabled by default by using the `ignore` attribute:
239245

240246
```rust
247+
# fn main() {}
241248
#[test]
242249
fn it_works() {
243250
assert_eq!(4, add_two(2));
@@ -299,6 +306,7 @@ missing the `tests` module. The idiomatic way of writing our example
299306
looks like this:
300307

301308
```rust,ignore
309+
# fn main() {}
302310
pub fn add_two(a: i32) -> i32 {
303311
a + 2
304312
}
@@ -327,6 +335,7 @@ a large module, and so this is a common use of globs. Let's change our
327335
`src/lib.rs` to make use of it:
328336

329337
```rust,ignore
338+
# fn main() {}
330339
pub fn add_two(a: i32) -> i32 {
331340
a + 2
332341
}
@@ -377,6 +386,7 @@ put a `tests/lib.rs` file inside, with this as its contents:
377386
```rust,ignore
378387
extern crate adder;
379388
389+
# fn main() {}
380390
#[test]
381391
fn it_works() {
382392
assert_eq!(4, adder::add_two(2));
@@ -432,6 +442,7 @@ running examples in your documentation (**note:** this only works in library
432442
crates, not binary crates). Here's a fleshed-out `src/lib.rs` with examples:
433443

434444
```rust,ignore
445+
# fn main() {}
435446
//! The `adder` crate provides functions that add numbers to other numbers.
436447
//!
437448
//! # Examples

0 commit comments

Comments
 (0)