Skip to content

Commit

Permalink
Propagate ch11 tech review edits to src
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Jun 3, 2022
1 parent 537905e commit 34314c1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Guess {

// ANCHOR: here
// --snip--

impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
Expand All @@ -27,7 +28,7 @@ mod tests {
use super::*;

#[test]
#[should_panic(expected = "Guess value must be less than or equal to 100")]
#[should_panic(expected = "less than or equal to 100")]
fn greater_than_100() {
Guess::new(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ thread 'main' panicked at 'Guess value must be greater than or equal to 1, got 2
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: panic did not contain expected string
panic message: `"Guess value must be greater than or equal to 1, got 200."`,
expected substring: `"Guess value must be less than or equal to 100"`
expected substring: `"less than or equal to 100"`

failures:
tests::greater_than_100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod tests {
use super::*;

#[test]
#[should_panic(expected = "Guess value must be less than or equal to 100")]
#[should_panic(expected = "less than or equal to 100")]
fn greater_than_100() {
Guess::new(200);
}
Expand Down
18 changes: 9 additions & 9 deletions src/ch11-01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ the result of running that test is `ok`. The overall summary `test result: ok.`
means that all the tests passed, and the portion that reads `1 passed; 0
failed` totals the number of tests that passed or failed.

It's possible to mark a test as ignored so it doesn't run in a particular
instance; we'll cover that in the [“Ignoring Some Tests Unless Specifically
Its possible to mark a test as ignored so it doesnt run in a particular
instance; well cover that in the [“Ignoring Some Tests Unless Specifically
Requested”][ignoring]<!-- ignore --> section later in this chapter. Because we
haven't done that here, the summary shows `0 ignored`. We can also pass an
havent done that here, the summary shows `0 ignored`. We can also pass an
argument to the `cargo test` command to run only tests whose name matches a
string; this is called filtering and we'll cover that in the [“Running a Subset
of Tests by Name”][subset]<!-- ignore --> section. We also haven’t filtered the
tests being run, so the end of the summary shows `0 filtered out`.
string; this is called *filtering* and well cover that in the [“Running a
Subset of Tests by Name”][subset]<!-- ignore --> section. We also haven’t
filtered the tests being run, so the end of the summary shows `0 filtered out`.

The `0 measured` statistic is for benchmark tests that measure performance.
Benchmark tests are, as of this writing, only available in nightly Rust. See
Expand Down Expand Up @@ -126,7 +126,7 @@ Then run `cargo test` again. The output now shows `exploration` instead of
{{#include ../listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/output.txt}}
```

Now we'll add another test, but this time we’ll make a test that fails! Tests
Now well add another test, but this time we’ll make a test that fails! Tests
fail when something in the test function panics. Each test is run in a new
thread, and when the main thread sees that a test thread has died, the test is
marked as failed. In Chapter 9, we talked about how the simplest way to panic
Expand Down Expand Up @@ -470,8 +470,8 @@ too large.
{{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs:here}}
```

<span class="caption">Listing 11-9: Testing for a `panic!` with a particular
panic message</span>
<span class="caption">Listing 11-9: Testing for a `panic!` with a panic message
containing a specified substring</span>

This test will pass because the value we put in the `should_panic` attribute’s
`expected` parameter is a substring of the message that the `Guess::new`
Expand Down
4 changes: 2 additions & 2 deletions src/ch11-02-running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ output from the test that failed, `I got the value 8`, appears in the section
of the test summary output, which also shows the cause of the test failure.

If we want to see printed values for passing tests as well, we can tell Rust
to also show the output of successful tests at the end with `--show-output`.
to also show the output of successful tests with `--show-output`.

```console
$ cargo test -- --show-output
Expand Down Expand Up @@ -127,7 +127,7 @@ We can pass the name of any test function to `cargo test` to run only that test:
```

Only the test with the name `one_hundred` ran; the other two tests didn’t match
that name. The test output lets us know we had more tests that didn't run by
that name. The test output lets us know we had more tests that didnt run by
displaying `2 filtered out` at the end.

We can’t specify the names of multiple tests in this way; only the first value
Expand Down

0 comments on commit 34314c1

Please sign in to comment.