@@ -24,6 +24,7 @@ Cargo will automatically generate a simple test when you make a new project.
2424Here's the contents of ` src/lib.rs ` :
2525
2626``` rust
27+ # fn main () {}
2728#[test]
2829fn it_works () {
2930}
@@ -75,6 +76,7 @@ So why does our do-nothing test pass? Any test which doesn't `panic!` passes,
7576and any test that does ` panic! ` fails. Let's make our test fail:
7677
7778``` rust
79+ # fn main () {}
7880#[test]
7981fn it_works () {
8082 assert! (false );
@@ -145,6 +147,7 @@ This is useful if you want to integrate `cargo test` into other tooling.
145147We can invert our test's failure with another attribute: ` should_panic ` :
146148
147149``` rust
150+ # fn main () {}
148151#[test]
149152#[should_panic]
150153fn it_works () {
@@ -175,6 +178,7 @@ Rust provides another macro, `assert_eq!`, that compares two arguments for
175178equality:
176179
177180``` rust
181+ # fn main () {}
178182#[test]
179183#[should_panic]
180184fn it_works () {
@@ -209,6 +213,7 @@ make sure that the failure message contains the provided text. A safer version
209213of the example above would be:
210214
211215``` rust
216+ # fn main () {}
212217#[test]
213218#[should_panic(expected = " assertion failed" )]
214219fn it_works () {
@@ -219,6 +224,7 @@ fn it_works() {
219224That's all there is to the basics! Let's write one 'real' test:
220225
221226``` rust,ignore
227+ # fn main() {}
222228pub 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
238244can be disabled by default by using the ` ignore ` attribute:
239245
240246``` rust
247+ # fn main () {}
241248#[test]
242249fn it_works () {
243250 assert_eq! (4 , add_two (2 ));
@@ -299,6 +306,7 @@ missing the `tests` module. The idiomatic way of writing our example
299306looks like this:
300307
301308``` rust,ignore
309+ # fn main() {}
302310pub 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() {}
330339pub 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
378387extern crate adder;
379388
389+ # fn main() {}
380390#[test]
381391fn 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
432442crates, 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