Skip to content

Commit eb3f275

Browse files
authored
tests: Use unwrap instead of match (#119)
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.
1 parent 70277eb commit eb3f275

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

src/dep_kinds_filtering.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,9 @@ mod tests {
174174
false,
175175
&serde_json::from_value(json!({ "keep-dep-kinds": "dev"})).unwrap(),
176176
Some("x86_64-pc-windows-gnu"),
177-
);
178-
match rp {
179-
Ok(rp) => assert_eq!(rp.len(), 3), // own package + once_cell + serial_test dev dependencies
180-
Err(e) => panic!("Got error: {e:?}"),
181-
}
177+
)
178+
.unwrap();
179+
assert_eq!(rp.len(), 3); // own package + once_cell + serial_test dev dependencies
182180
}
183181

184182
#[test]
@@ -191,11 +189,9 @@ mod tests {
191189
&serde_json::from_value(json!({ "keep-dep-kinds": "all", "--all-features": true}))
192190
.unwrap(),
193191
None, // all platforms
194-
);
195-
match rp {
196-
Ok(rp) => assert!(rp.len() > 90), // all features, all platforms list is long
197-
Err(e) => panic!("Got error: {e:?}"),
198-
}
192+
)
193+
.unwrap();
194+
assert!(rp.len() > 90); // all features, all platforms list is long
199195
}
200196

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

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

221219
// if once_cell is also a normal dependency, it is not removed from the list
222-
match (rp_normal, rp_no_build) {
223-
(Ok(rp_normal), Ok(rp_no_build)) => assert!(
224-
rp_normal.len() < rp_no_build.len(),
225-
"Filtering does not work. Got {} normal and {} no-build dependencies",
226-
rp_normal.len(),
227-
rp_no_build.len()
228-
),
229-
_ => panic!("One of get_required_packages() calls failed"),
230-
}
220+
assert!(
221+
rp_normal.len() < rp_no_build.len(),
222+
"Filtering does not work. Got {} normal and {} no-build dependencies",
223+
rp_normal.len(),
224+
rp_no_build.len()
225+
);
231226
}
232227

233228
#[test]
@@ -240,23 +235,22 @@ mod tests {
240235
false,
241236
&serde_json::from_value(json!({ "keep-dep-kinds": "build"})).unwrap(),
242237
Some("x86_64-unknown-linux-gnu"),
243-
);
238+
)
239+
.unwrap();
244240

245241
// no-dev => build + normal so the list shall be larger
246242
let rp_no_dev = get_required_packages(
247243
&[Some(&own_cargo_toml)],
248244
false,
249245
&serde_json::from_value(json!({ "keep-dep-kinds": "no-dev"})).unwrap(),
250246
Some("x86_64-unknown-linux-gnu"),
247+
)
248+
.unwrap();
249+
assert!(
250+
rp_build.len() < rp_no_dev.len(),
251+
"Filtering does not work. Got {} build and {} no-dev dependencies",
252+
rp_build.len(),
253+
rp_no_dev.len()
251254
);
252-
match (rp_build, rp_no_dev) {
253-
(Ok(rp_build), Ok(rp_no_dev)) => assert!(
254-
rp_build.len() < rp_no_dev.len(),
255-
"Filtering does not work. Got {} build and {} no-dev dependencies",
256-
rp_build.len(),
257-
rp_no_dev.len()
258-
),
259-
_ => panic!("One of get_required_packages() calls failed"),
260-
}
261255
}
262256
}

0 commit comments

Comments
 (0)