From 2a832a03c5a3efd6388e4eb5c5b5b4568bcd80f6 Mon Sep 17 00:00:00 2001 From: Trotter Cashion Date: Thu, 10 Nov 2016 19:08:45 -0800 Subject: [PATCH] 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. --- src/doc/book/testing.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/doc/book/testing.md b/src/doc/book/testing.md index 4fd73e4854bc4..ed916fd798bb6 100644 --- a/src/doc/book/testing.md +++ b/src/doc/book/testing.md @@ -23,7 +23,7 @@ $ cd adder Cargo will automatically generate a simple test when you make a new project. Here's the contents of `src/lib.rs`: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -38,7 +38,7 @@ mod tests { For now, let's remove the `mod` bit, and focus on just the function: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -81,8 +81,10 @@ test it_works ... ok Note the `it_works`. This comes from the name of our function: ```rust +# fn main() { fn it_works() { } +# } ``` We also get a summary line: @@ -94,7 +96,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured So why does our do-nothing test pass? Any test which doesn't `panic!` passes, and any test that does `panic!` fails. Let's make our test fail: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -169,7 +171,7 @@ This is useful if you want to integrate `cargo test` into other tooling. We can invert our test's failure with another attribute: `should_panic`: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -204,7 +206,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured Rust provides another macro, `assert_eq!`, that compares two arguments for equality: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -243,7 +245,7 @@ parameter can be added to the `should_panic` attribute. The test harness will make sure that the failure message contains the provided text. A safer version of the example above would be: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main @@ -280,7 +282,7 @@ some known arguments and compare it to the expected output. Sometimes a few specific tests can be very time-consuming to execute. These can be disabled by default by using the `ignore` attribute: -```rust +```rust,ignore # // The next line exists to trick play.rust-lang.org into running our code as a # // test: # // fn main