From f84da3cf04e03659baa63a188c5ac3317f4a68c2 Mon Sep 17 00:00:00 2001 From: Chen Rotem Levy Date: Wed, 8 Nov 2017 22:48:16 +0200 Subject: [PATCH 1/2] the test generated by cargo new isn't empty The default test generated by `cargo new mylib` has an `assert_eq!(2 + 2, 4)` line. The text that describe this should be updated as well. --- second-edition/src/ch11-01-writing-tests.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/second-edition/src/ch11-01-writing-tests.md b/second-edition/src/ch11-01-writing-tests.md index c4697760e..05c3b3f1e 100644 --- a/second-edition/src/ch11-01-writing-tests.md +++ b/second-edition/src/ch11-01-writing-tests.md @@ -46,6 +46,7 @@ follows: mod tests { #[test] fn it_works() { + assert_eq!(2 + 2, 4); } } ``` @@ -60,9 +61,9 @@ function as a test. We could also have non-test functions in the `tests` module to help set up common scenarios or perform common operations, so we need to indicate which functions are tests with the `#[test]` attribute. -The function currently has no body, which means there is no code to fail the -test; an empty test is a passing test! Let’s run it and see that this test -passes. +The function boddy use the `assert_eq!` macro to assert that 2 + 2 equals 4. +This assersion serves as an example of the form for a typical test. +Let’s run it and see that this test passes. The `cargo test` command runs all tests we have in our project, as shown in Listing 11-2: From 25b233943be87cb7960c40af59d78ec16e2db4af Mon Sep 17 00:00:00 2001 From: Chen Rotem Levy Date: Fri, 10 Nov 2017 15:46:39 +0200 Subject: [PATCH 2/2] an-other auto-generated test to update The auto-generated test created by `cargo new` makes an other appearance in test organization. --- second-edition/src/ch11-03-test-organization.md | 1 + 1 file changed, 1 insertion(+) diff --git a/second-edition/src/ch11-03-test-organization.md b/second-edition/src/ch11-03-test-organization.md index a1fddad47..1f604bec7 100644 --- a/second-edition/src/ch11-03-test-organization.md +++ b/second-edition/src/ch11-03-test-organization.md @@ -42,6 +42,7 @@ this chapter, Cargo generated this code for us: mod tests { #[test] fn it_works() { + assert_eq!(2 + 2, 4); } } ```