mirror of
https://github.com/rust-lang/book.git
synced 2026-05-17 15:30:43 -04:00
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:
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user