Skip to content

Commit 5ad384e

Browse files
author
Paul Emmerich
committed
document new --show-output option in ch 11-2
--show-output is available in rust 1.39 or later
1 parent 7ddc464 commit 5ad384e

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/ch11-02-running-tests.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,40 +115,46 @@ is printed when the test that passes runs. That output has been captured. The
115115
output from the test that failed, `I got the value 8`, appears in the section
116116
of the test summary output, which also shows the cause of the test failure.
117117

118-
If we want to see printed values for passing tests as well, we can disable the
119-
output capture behavior by using the `--nocapture` flag:
118+
If we want to see printed values for passing tests as well, we can tell Rust
119+
to also show the output of successful tests at the end.
120120

121121
```text
122-
$ cargo test -- --nocapture
122+
$ cargo test -- --show-output
123123
```
124124

125-
When we run the tests in Listing 11-10 again with the `--nocapture` flag, we
125+
When we run the tests in Listing 11-10 again with the `--show-output` flag, we
126126
see the following output:
127127

128128
```text
129129
running 2 tests
130+
test tests::this_test_will_pass ... ok
131+
test tests::this_test_will_fail ... FAILED
132+
133+
successes:
134+
135+
---- tests::this_test_will_pass stdout ----
130136
I got the value 4
137+
138+
139+
successes:
140+
tests::this_test_will_pass
141+
142+
failures:
143+
144+
---- tests::this_test_will_fail stdout ----
131145
I got the value 8
132-
test tests::this_test_will_pass ... ok
133146
thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)`
134147
left: `5`,
135-
right: `10`', src/lib.rs:19:9
136-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
137-
test tests::this_test_will_fail ... FAILED
148+
right: `10`', src/main.rs:19:9
149+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
138150
139-
failures:
140151
141152
failures:
142153
tests::this_test_will_fail
143154
144155
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
145156
```
146157

147-
Note that the output for the tests and the test results are interleaved; the
148-
reason is that the tests are running in parallel, as we talked about in the
149-
previous section. Try using the `--test-threads=1` option and the `--nocapture`
150-
flag, and see what the output looks like then!
151-
152158
### Running a Subset of Tests by Name
153159

154160
Sometimes, running a full test suite can take a long time. If you’re working on

0 commit comments

Comments
 (0)