From 4ddb4f996b8a3b942403d35b0fa4449f64d40e6b Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:28:22 +0000 Subject: [PATCH 1/4] Update Listing 11-1 to reflect current contents --- .../ch11-writing-automated-tests/listing-11-01/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } From b2365a3f087681afb477b4af58dedc7474f5b4ca Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:43:38 +0000 Subject: [PATCH 2/4] Modify text to better refer to updated listing 11-1 --- src/ch11-01-writing-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..97f13f9de3 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -62,7 +62,7 @@ cd ../../.. Listing 11-1: The test module and function generated automatically by `cargo new` -For now, let’s ignore the top two lines and focus on the function. Note the +For now, let's focus solely on the `it_works()` function. Note the `#[test]` annotation: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform From bb7aa19d9dc6fd9c9a2128e9526ae861602651d9 Mon Sep 17 00:00:00 2001 From: Jon Earnshaw Date: Tue, 7 Feb 2023 04:49:10 +0000 Subject: [PATCH 3/4] Update listings subsequent to listing 11-1 to reflect current content --- .../listing-11-03/src/lib.rs | 11 +++++++++-- .../no-listing-01-changing-test-name/src/lib.rs | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index a9ec008919..67b6552c71 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,11 +1,18 @@ // ANCHOR: here +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs index 330bddf6ac..5be58b93fc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs @@ -1,7 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } } From a2c1496c9bd5ce4552a33b5047121323aeb1ae90 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 10 Apr 2024 13:13:44 -0600 Subject: [PATCH 4/4] Update src/ch11-01-writing-tests.md --- src/ch11-01-writing-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index 97f13f9de3..617b2dc5f3 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -62,7 +62,7 @@ cd ../../.. Listing 11-1: The test module and function generated automatically by `cargo new` -For now, let's focus solely on the `it_works()` function. Note the +For now, let’s focus solely on the `it_works()` function. Note the `#[test]` annotation: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform