Skip to content

Commit 7190ed7

Browse files
fix: make assertion assert something (#6768)
### Description `assert_matches!` is a very explicit macro that expands `assert_matches!(x, y)` to `match x { y => (), ref other => panic!("got {other:?"})`. The `y` branch will be taken every time in this example since`y` refers to a named variable and *not* a bound `y` that might exist. See [matching named variables](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#matching-named-variables) from the Rust book. We had `_expected` instead of `expected` because clippy would warn us that the variable was never used and it was right! The the `_expected` in the `assert_matches!` was referring to a different variable than the `_expected` defined above it. This PR changes the `assert_matches` to use an variant so the assertion is checking what we want. Now `assert_matches!` expands to ``` match state { ChildExit::KilledExternal => {} ref left_val => { $crate::panicking::assert_matches_failed( left_val, "ChildExit :: KilledExternal", $crate::option::Option::None, ); } } ``` ### Testing Instructions No unused code warnings anymore. 👀 Closes TURBO-1894 --------- Co-authored-by: Chris Olszewski <Chris Olszewski>
1 parent aa11b36 commit 7190ed7

File tree

1 file changed

+6
-5
lines changed
  • crates/turborepo-lib/src/process

1 file changed

+6
-5
lines changed

crates/turborepo-lib/src/process/child.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,14 @@ mod test {
659659

660660
let state = child.state.read().await;
661661

662-
let _expected = if cfg!(unix) {
663-
ChildExit::KilledExternal
664-
} else {
665-
ChildExit::Finished(Some(1))
662+
let ChildState::Exited(state) = &*state else {
663+
panic!("expected child to have exited after wait call");
666664
};
667665

668-
assert_matches!(&*state, ChildState::Exited(_expected));
666+
#[cfg(unix)]
667+
assert_matches!(state, ChildExit::KilledExternal);
668+
#[cfg(not(unix))]
669+
assert_matches!(state, ChildExit::Finished(Some(3)));
669670
}
670671

671672
#[tokio::test]

0 commit comments

Comments
 (0)