Skip to content

Commit 196f72f

Browse files
authored
Merge pull request #3497 from regexident/swap-assert-eq-arg-order
Swap inconsistent `assert_eq!` argument order in testing chapter
2 parents 43d198b + 9a01b7c commit 196f72f

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ test tests::it_adds_two ... FAILED
99
failures:
1010

1111
---- tests::it_adds_two stdout ----
12-
thread 'tests::it_adds_two' panicked at src/lib.rs:11:9:
1312
assertion `left == right` failed
14-
left: 4
15-
right: 5
13+
left: 5
14+
right: 4
1615
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1716

1817

listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ mod tests {
1010

1111
#[test]
1212
fn it_adds_two() {
13-
assert_eq!(4, add_two(2));
13+
assert_eq!(add_two(2), 4);
1414
}
1515
}

src/ch11-01-writing-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ assertion functions are called `expected` and `actual`, and the order in which
317317
we specify the arguments matters. However, in Rust, they’re called `left` and
318318
`right`, and the order in which we specify the value we expect and the value
319319
the code produces doesn’t matter. We could write the assertion in this test as
320-
`assert_eq!(add_two(2), 4)`, which would result in the same failure message
320+
`assert_eq!(4, add_two(2))`, which would result in the same failure message
321321
that displays `` assertion failed: `(left == right)` ``.
322322

323323
The `assert_ne!` macro will pass if the two values we give it are not equal and

0 commit comments

Comments
 (0)