]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/book/src/ch11-01-writing-tests.md
New upstream version 1.61.0+dfsg1
[rustc.git] / src / doc / book / src / ch11-01-writing-tests.md
index 0c41f4a1c1cee60cca14a139ae7c63c64d3dd79a..b60b7c1988a781356988abfd0db09b0af4c6c32e 100644 (file)
@@ -46,6 +46,16 @@ Listing 11-1.
 
 <span class="filename">Filename: src/lib.rs</span>
 
+<!-- manual-regeneration
+cd listings/ch11-writing-automated-tests
+rm -rf listing-11-01
+cargo new --lib listing-11-01 --name adder
+cd listing-11-01
+cargo test
+git co output.txt
+cd ../../..
+-->
+
 ```rust,noplayground
 {{#rustdoc_include ../listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs}}
 ```
@@ -520,8 +530,9 @@ mark operator in the body of tests, which can be a convenient way to write
 tests that should fail if any operation within them returns an `Err` variant.
 
 You can’t use the `#[should_panic]` annotation on tests that use `Result<T,
-E>`. Instead, you should return an `Err` value directly when the test should
-fail.
+E>`. To assert that an operation returns an `Err` variant, *don’t* use the
+question mark operator on the `Result<T, E>` value. Instead, use
+`assert!(value.is_err())`.
 
 Now that you know several ways to write tests, let’s look at what is happening
 when we run our tests and explore the different options we can use with `cargo