Skip to content

Commit

Permalink
Merge pull request #3533 from jpearnshaw/patch-2
Browse files Browse the repository at this point in the history
Update listings in ch 11-01 to reflect current output from cargo new
  • Loading branch information
chriskrycho authored Apr 10, 2024
2 parents db29c74 + a2c1496 commit 93293f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/ch11-01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ cd ../../..
<span class="caption">Listing 11-1: The test module and function generated
automatically by `cargo new`</span>

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
Expand Down

0 comments on commit 93293f0

Please sign in to comment.