]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/book/2018-edition/src/ch11-01-writing-tests.md
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / doc / book / 2018-edition / src / ch11-01-writing-tests.md
index 840b2bd7424f91f07e1e2172fc9ffef8ab6add8c..e111466233c3665e2b8261d1d7f32d97debcb17f 100644 (file)
@@ -157,7 +157,7 @@ which is to call the `panic!` macro. Enter the new test, `another`, so your
 
 <span class="filename">Filename: src/lib.rs</span>
 
-```rust
+```rust,panics
 # fn main() {}
 #[cfg(test)]
 mod tests {
@@ -340,7 +340,7 @@ introduce a bug in our code. Let’s change the implementation of the `can_hold`
 method by replacing the greater-than sign with a less-than sign when it
 compares the lengths:
 
-```rust
+```rust,not_desired_behavior
 # fn main() {}
 # #[derive(Debug)]
 # pub struct Rectangle {
@@ -436,7 +436,7 @@ Let’s introduce a bug into our code to see what it looks like when a test that
 uses `assert_eq!` fails. Change the implementation of the `add_two` function to
 instead add `3`:
 
-```rust
+```rust,not_desired_behavior
 # fn main() {}
 pub fn add_two(a: i32) -> i32 {
     a + 3
@@ -544,7 +544,7 @@ input parameter.
 Let’s introduce a bug into this code by changing `greeting` to not include
 `name` to see what this test failure looks like:
 
-```rust
+```rust,not_desired_behavior
 # fn main() {}
 pub fn greeting(name: &str) -> String {
     String::from("Hello!")
@@ -602,7 +602,7 @@ debug what happened instead of what we were expecting to happen.
 In addition to checking that our code returns the correct values we expect,
 it’s also important to check that our code handles error conditions as we
 expect. For example, consider the `Guess` type that we created in Chapter 9,
-Listing 9-9. Other code that uses `Guess` depends on the guarantee that `Guess`
+Listing 9-10. Other code that uses `Guess` depends on the guarantee that `Guess`
 instances will contain only values between 1 and 100. We can write a test that
 ensures that attempting to create a `Guess` instance with a value outside that
 range panics.
@@ -663,7 +663,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
 Looks good! Now let’s introduce a bug in our code by removing the condition
 that the `new` function will panic if the value is greater than 100:
 
-```rust
+```rust,not_desired_behavior
 # fn main() {}
 # pub struct Guess {
 #     value: i32,
@@ -766,7 +766,7 @@ To see what happens when a `should_panic` test with an `expected` message
 fails, let’s again introduce a bug into our code by swapping the bodies of the
 `if value < 1` and the `else if value > 100` blocks:
 
-```rust,ignore
+```rust,ignore,not_desired_behavior
 if value < 1 {
     panic!("Guess value must be less than or equal to 100, got {}.", value);
 } else if value > 100 {