From e5fd3152e218991afb4f93daae8be7ac2e0e105e Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Tue, 7 May 2024 13:14:19 +0100 Subject: [PATCH] test: fix some bad assert_matches (#1006) Turns out that `assert_matches!(subject, pattern => STMT)` executes STMT and drops the result.... We have several cases where STMT returns a bool and we were expecting this to be true, but in fact assert_matches doesn't check the bool. So, change these to `=> assert_eq!` Indeed, there was one case here where the bool was actually false - fix that assert.... --- hugr/src/hugr/rewrite/outline_cfg.rs | 4 ++-- hugr/src/hugr/rewrite/replace.rs | 2 +- hugr/src/hugr/validate/test.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hugr/src/hugr/rewrite/outline_cfg.rs b/hugr/src/hugr/rewrite/outline_cfg.rs index dc5ded05b..5cbe0f1b3 100644 --- a/hugr/src/hugr/rewrite/outline_cfg.rs +++ b/hugr/src/hugr/rewrite/outline_cfg.rs @@ -285,11 +285,11 @@ mod test { let [left, right]: [Node; 2] = h.output_neighbours(head).collect_vec().try_into().unwrap(); let r = h.apply_rewrite(OutlineCfg::new([left, right, head])); - assert_matches!(r, Err(OutlineCfgError::MultipleExitNodes(a,b)) => HashSet::from([a,b]) == HashSet::from_iter([left, right, head])); + assert_matches!(r, Err(OutlineCfgError::MultipleExitNodes(a,b)) => assert_eq!(HashSet::from([a,b]), HashSet::from_iter([left, right]))); assert_eq!(h, backup); let r = h.apply_rewrite(OutlineCfg::new([left, right, merge])); - assert_matches!(r, Err(OutlineCfgError::MultipleEntryNodes(a,b)) => HashSet::from([a,b]) == HashSet::from([left, right])); + assert_matches!(r, Err(OutlineCfgError::MultipleEntryNodes(a,b)) => assert_eq!(HashSet::from([a,b]), HashSet::from([left, right]))); assert_eq!(h, backup); } diff --git a/hugr/src/hugr/rewrite/replace.rs b/hugr/src/hugr/rewrite/replace.rs index ad51168be..b06fcfe62 100644 --- a/hugr/src/hugr/rewrite/replace.rs +++ b/hugr/src/hugr/rewrite/replace.rs @@ -803,7 +803,7 @@ mod test { mu_new: vec![bad_order_edge.clone()], ..rep.clone() }), - ReplaceError::BadEdgeKind(_, e) => e == bad_order_edge + ReplaceError::BadEdgeKind(_, e) => assert_eq!(e, bad_order_edge) ); let op = OutgoingPort::from(0); let (tgt, ip) = h.linked_inputs(cond.node(), op).next().unwrap(); diff --git a/hugr/src/hugr/validate/test.rs b/hugr/src/hugr/validate/test.rs index 8c1387dc0..424c86513 100644 --- a/hugr/src/hugr/validate/test.rs +++ b/hugr/src/hugr/validate/test.rs @@ -498,7 +498,7 @@ fn nested_typevars() -> Result<(), Box> { ); assert_matches!(build(Type::new_var_use(0, OUTER_BOUND)).unwrap_err(), BuildError::InvalidHUGR(ValidationError::SignatureError { cause: SignatureError::TypeVarDoesNotMatchDeclaration { actual, cached }, .. }) => - actual == INNER_BOUND.into() && cached == OUTER_BOUND.into()); + {assert_eq!(actual, INNER_BOUND.into()); assert_eq!(cached, OUTER_BOUND.into())}); Ok(()) }