Merge pull request #3533 from jpearnshaw/patch-2

Update listings in ch 11-01 to reflect current output from cargo new
This commit is contained in:
Chris Krycho
2024-04-10 13:23:34 -06:00
committed by GitHub
3 changed files with 18 additions and 4 deletions

View File

@@ -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");

View File

@@ -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);
}
}

View File

@@ -62,7 +62,7 @@ cd ../../..
<span class="caption">Listing 11-1: The test module and function generated
automatically by `cargo new`</span>
For now, lets ignore the top two lines and focus on the function. Note the
For now, lets 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