@@ -115,40 +115,46 @@ is printed when the test that passes runs. That output has been captured. The
115
115
output from the test that failed, ` I got the value 8 ` , appears in the section
116
116
of the test summary output, which also shows the cause of the test failure.
117
117
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.
120
120
121
121
``` text
122
- $ cargo test -- --nocapture
122
+ $ cargo test -- --show-output
123
123
```
124
124
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
126
126
see the following output:
127
127
128
128
``` text
129
129
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 ----
130
136
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 ----
131
145
I got the value 8
132
- test tests::this_test_will_pass ... ok
133
146
thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)`
134
147
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.
138
150
139
- failures:
140
151
141
152
failures:
142
153
tests::this_test_will_fail
143
154
144
155
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
145
156
```
146
157
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
-
152
158
### Running a Subset of Tests by Name
153
159
154
160
Sometimes, running a full test suite can take a long time. If you’re working on
0 commit comments