Skip to content

Commit

Permalink
Merge pull request #4151 from rust-lang/super-unit-test
Browse files Browse the repository at this point in the history
Add `use super::*;` to unit-test examples.
  • Loading branch information
chriskrycho authored Dec 9, 2024
2 parents c4cede2 + fcfac81 commit bb786c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add(left: usize, right: usize) -> usize {
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add(left: usize, right: usize) -> usize {
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add(left: usize, right: usize) -> usize {
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add(left: usize, right: usize) -> usize {
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

Expand Down
9 changes: 6 additions & 3 deletions src/ch11-01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ cd ../../..

</Listing>

The file starts with an example `add` function, so that we have something
to test.

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
common operations, so we always need to indicate which functions are tests.

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

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

0 comments on commit bb786c8

Please sign in to comment.