Skip to content

Commit

Permalink
tests: Use unwrap instead of match (#119)
Browse files Browse the repository at this point in the history
Some of the test code here was "swallowing" error messages
making things unnecessarily hard to debug. Just use `unwrap()`
so we know what the real error is.
  • Loading branch information
cgwalters authored Feb 21, 2025
1 parent 70277eb commit eb3f275
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/dep_kinds_filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ mod tests {
false,
&serde_json::from_value(json!({ "keep-dep-kinds": "dev"})).unwrap(),
Some("x86_64-pc-windows-gnu"),
);
match rp {
Ok(rp) => assert_eq!(rp.len(), 3), // own package + once_cell + serial_test dev dependencies
Err(e) => panic!("Got error: {e:?}"),
}
)
.unwrap();
assert_eq!(rp.len(), 3); // own package + once_cell + serial_test dev dependencies
}

#[test]
Expand All @@ -191,11 +189,9 @@ mod tests {
&serde_json::from_value(json!({ "keep-dep-kinds": "all", "--all-features": true}))
.unwrap(),
None, // all platforms
);
match rp {
Ok(rp) => assert!(rp.len() > 90), // all features, all platforms list is long
Err(e) => panic!("Got error: {e:?}"),
}
)
.unwrap();
assert!(rp.len() > 90); // all features, all platforms list is long
}

#[test]
Expand All @@ -208,26 +204,25 @@ mod tests {
false,
&serde_json::from_value(json!({ "keep-dep-kinds": "normal"})).unwrap(),
Some("x86_64-pc-windows-gnu"),
);
)
.unwrap();

// no-build => normal + dev dependencies, so including once_call, serial_test...
let rp_no_build = get_required_packages(
&[Some(&own_cargo_toml)],
false,
&serde_json::from_value(json!({ "keep-dep-kinds": "no-build"})).unwrap(),
Some("x86_64-pc-windows-gnu"),
);
)
.unwrap();

// if once_cell is also a normal dependency, it is not removed from the list
match (rp_normal, rp_no_build) {
(Ok(rp_normal), Ok(rp_no_build)) => assert!(
rp_normal.len() < rp_no_build.len(),
"Filtering does not work. Got {} normal and {} no-build dependencies",
rp_normal.len(),
rp_no_build.len()
),
_ => panic!("One of get_required_packages() calls failed"),
}
assert!(
rp_normal.len() < rp_no_build.len(),
"Filtering does not work. Got {} normal and {} no-build dependencies",
rp_normal.len(),
rp_no_build.len()
);
}

#[test]
Expand All @@ -240,23 +235,22 @@ mod tests {
false,
&serde_json::from_value(json!({ "keep-dep-kinds": "build"})).unwrap(),
Some("x86_64-unknown-linux-gnu"),
);
)
.unwrap();

// no-dev => build + normal so the list shall be larger
let rp_no_dev = get_required_packages(
&[Some(&own_cargo_toml)],
false,
&serde_json::from_value(json!({ "keep-dep-kinds": "no-dev"})).unwrap(),
Some("x86_64-unknown-linux-gnu"),
)
.unwrap();
assert!(
rp_build.len() < rp_no_dev.len(),
"Filtering does not work. Got {} build and {} no-dev dependencies",
rp_build.len(),
rp_no_dev.len()
);
match (rp_build, rp_no_dev) {
(Ok(rp_build), Ok(rp_no_dev)) => assert!(
rp_build.len() < rp_no_dev.len(),
"Filtering does not work. Got {} build and {} no-dev dependencies",
rp_build.len(),
rp_no_dev.len()
),
_ => panic!("One of get_required_packages() calls failed"),
}
}
}

0 comments on commit eb3f275

Please sign in to comment.