Skip to content

Commit bb786c8

Browse files
authored
Merge pull request #4151 from rust-lang/super-unit-test
Add `use super::*;` to unit-test examples.
2 parents c4cede2 + fcfac81 commit bb786c8

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn add(left: usize, right: usize) -> usize {
1+
pub fn add(left: u64, right: u64) -> u64 {
22
left + right
33
}
44

listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn add(left: usize, right: usize) -> usize {
1+
pub fn add(left: u64, right: u64) -> u64 {
22
left + right
33
}
44

listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn add(left: usize, right: usize) -> usize {
1+
pub fn add(left: u64, right: u64) -> u64 {
22
left + right
33
}
44

listings/ch11-writing-automated-tests/no-listing-11-ignore-a-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub fn add(left: usize, right: usize) -> usize {
1+
pub fn add(left: u64, right: u64) -> u64 {
22
left + right
33
}
44

src/ch11-01-writing-tests.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,19 @@ cd ../../..
6262

6363
</Listing>
6464

65+
The file starts with an example `add` function, so that we have something
66+
to test.
67+
6568
For now, let’s focus solely on the `it_works` function. Note the `#[test]`
6669
annotation: this attribute indicates this is a test function, so the test
6770
runner knows to treat this function as a test. We might also have non-test
6871
functions in the `tests` module to help set up common scenarios or perform
6972
common operations, so we always need to indicate which functions are tests.
7073

7174
The example function body uses the `assert_eq!` macro to assert that `result`,
72-
which contains the result of adding 2 and 2, equals 4. This assertion serves as
73-
an example of the format for a typical test. Let’s run it to see that this test
74-
passes.
75+
which contains the result of calling `add` with 2 and 2, equals 4. This
76+
assertion serves as an example of the format for a typical test. Let’s run it
77+
to see that this test passes.
7578

7679
The `cargo test` command runs all tests in our project, as shown in Listing
7780
11-2.

0 commit comments

Comments
 (0)