You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -151,6 +151,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
151
151
running 0 tests
152
152
153
153
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
154
+
154
155
```
155
156
156
157
Listing 11-2: The output from running the automatically generated test
@@ -164,7 +165,7 @@ instance; we’ll cover that in the “Ignoring Some Tests Unless Specifically
164
165
Requested” section later in this chapter. Because we
165
166
haven’t done that here, the summary shows `0 ignored`. We can also pass an
166
167
argument to the `cargo test` command to run only tests whose name matches a
167
-
string; this is called *filtering* and we’ll cover that in the “Running a
168
+
string; this is called *filtering* and we’ll cover it in the “Running a
168
169
Subset of Tests by Name” section. Here we haven’t
169
170
filtered the tests being run, so the end of the summary shows `0 filtered out`.
170
171
@@ -274,6 +275,7 @@ test tests::exploration ... ok
274
275
failures:
275
276
276
277
---- tests::another stdout ----
278
+
277
279
thread 'tests::another' panicked at src/lib.rs:17:9:
278
280
Make this test fail
279
281
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@@ -297,12 +299,12 @@ check the line number of the panic matches the line number in the following para
297
299
Instead of `ok`, the line `test tests::another` shows `FAILED`. Two new
298
300
sections appear between the individual results and the summary: the first
299
301
displays the detailed reason for each test failure. In this case, we get the
300
-
details that `another` failed because it `panicked at 'Make this test fail'` on
301
-
line 17 in the *src/lib.rs* file. The next section lists just the names of all
302
-
the failing tests, which is useful when there are lots of tests and lots of
303
-
detailed failing test output. We can use the name of a failing test to run just
304
-
that test to more easily debug it; we’ll talk more about ways to run tests in
305
-
the “Controlling How Tests Are Run” section.
302
+
details that `tests::another` failed because it panicked with the message `Make this test fail` on line 17 in the *src/lib.rs* file. The next section lists
303
+
just the names of all the failing tests, which is useful when there are lots of
304
+
tests and lots of detailed failing test output. We can use the name of a
305
+
failing test to run just that test to more easily debug it; we’ll talk more
306
+
about ways to run tests in the “Controlling How Tests Are
307
+
Run” section.
306
308
307
309
The summary line displays at the end: overall, our test result is `FAILED`. We
308
310
had one test pass and one test fail.
@@ -489,6 +491,7 @@ test tests::smaller_cannot_hold_larger ... ok
489
491
failures:
490
492
491
493
---- tests::larger_can_hold_smaller stdout ----
494
+
492
495
thread 'tests::larger_can_hold_smaller' panicked at src/lib.rs:28:9:
493
496
assertion failed: larger.can_hold(&smaller)
494
497
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@@ -525,7 +528,7 @@ parameter, then we test this function using the `assert_eq!` macro.
525
528
src/lib.rs
526
529
527
530
```
528
-
pub fn add_two(a: usize) -> usize {
531
+
pub fn add_two(a: u64) -> u64 {
529
532
a + 2
530
533
}
531
534
@@ -565,15 +568,14 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
565
568
```
566
569
567
570
We create a variable named `result` that holds the result of calling
568
-
`add_two(2)`. Then we pass `result` and `4` as the arguments to `assert_eq!`.
569
-
The output line for this test is `test tests::it_adds_two ... ok`, and the `ok`
570
-
text indicates that our test passed!
571
+
`add_two(2)`. Then we pass `result` and `4` as the arguments to the
572
+
`assert_eq!` macro. The output line for this test is `test tests::it_adds_two ... ok`, and the `ok` text indicates that our test passed!
571
573
572
574
Let’s introduce a bug into our code to see what `assert_eq!` looks like when it
573
575
fails. Change the implementation of the `add_two` function to instead add `3`:
574
576
575
577
```
576
-
pub fn add_two(a: usize) -> usize {
578
+
pub fn add_two(a: u64) -> u64 {
577
579
a + 3
578
580
}
579
581
```
@@ -592,6 +594,7 @@ test tests::it_adds_two ... FAILED
592
594
failures:
593
595
594
596
---- tests::it_adds_two stdout ----
597
+
595
598
thread 'tests::it_adds_two' panicked at src/lib.rs:12:9:
0 commit comments