Skip to content

Commit 94aca98

Browse files
committed
Merge #397: Add Expected Should Panic Message to Tests
efd1c99 test: ignore ssl config test (Cameron Garnham) 089fb48 dev: add should_panic expected message to tracker tests (Cameron Garnham) 2fa3742 dev: add expected message to bencode panic tests (Cameron Garnham) Pull request description: closes #391 ACKs for top commit: da2ce7: ACK efd1c99 Tree-SHA512: 73681833ce4bbfcdbe68875835924d6102c380a502619eac941d46bf9f0e431364e0f129539883be4ebd420bd38fa7e1f3667dc7e3fd488f03f538b496ee8eb4
2 parents 8b48b0c + efd1c99 commit 94aca98

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

contrib/bencode/src/reference/decode.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,69 +329,68 @@ mod tests {
329329
}
330330

331331
#[test]
332-
#[should_panic]
332+
#[should_panic = "BencodeParseError(InvalidByte { pos: 0 }"]
333333
fn negative_decode_bytes_neg_len() {
334334
BencodeRef::decode(BYTES_NEG_LEN, BDecodeOpt::default()).unwrap();
335335
}
336336

337337
#[test]
338-
#[should_panic]
338+
#[should_panic = "BencodeParseError(BytesEmpty { pos: 20 }"]
339339
fn negative_decode_bytes_extra() {
340340
BencodeRef::decode(BYTES_EXTRA, BDecodeOpt::default()).unwrap();
341341
}
342342

343343
#[test]
344-
#[should_panic]
345344
fn negative_decode_bytes_not_utf8() {
346345
let bencode = BencodeRef::decode(BYTES_NOT_UTF8, BDecodeOpt::default()).unwrap();
347346

348-
bencode.str().unwrap();
347+
assert!(bencode.str().is_none());
349348
}
350349

351350
#[test]
352-
#[should_panic]
351+
#[should_panic = "BencodeParseError(InvalidIntParseError { pos: 1 }"]
353352
fn negative_decode_int_nan() {
354353
super::decode_int(INT_NAN, 1, crate::BEN_END).unwrap();
355354
}
356355

357356
#[test]
358-
#[should_panic]
357+
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
359358
fn negative_decode_int_leading_zero() {
360359
super::decode_int(INT_LEADING_ZERO, 1, crate::BEN_END).unwrap();
361360
}
362361

363362
#[test]
364-
#[should_panic]
363+
#[should_panic = "BencodeParseError(InvalidIntZeroPadding { pos: 1 }"]
365364
fn negative_decode_int_double_zero() {
366365
super::decode_int(INT_DOUBLE_ZERO, 1, crate::BEN_END).unwrap();
367366
}
368367

369368
#[test]
370-
#[should_panic]
369+
#[should_panic = "BencodeParseError(InvalidIntNegativeZero { pos: 1 }"]
371370
fn negative_decode_int_negative_zero() {
372371
super::decode_int(INT_NEGATIVE_ZERO, 1, crate::BEN_END).unwrap();
373372
}
374373

375374
#[test]
376-
#[should_panic]
375+
#[should_panic = " BencodeParseError(InvalidIntParseError { pos: 1 }"]
377376
fn negative_decode_int_double_negative() {
378377
super::decode_int(INT_DOUBLE_NEGATIVE, 1, crate::BEN_END).unwrap();
379378
}
380379

381380
#[test]
382-
#[should_panic]
381+
#[should_panic = "BencodeParseError(InvalidKeyOrdering { pos: 15, key: [97, 95, 107, 101, 121] }"]
383382
fn negative_decode_dict_unordered_keys() {
384383
BencodeRef::decode(DICT_UNORDERED_KEYS, BDecodeOpt::new(5, true, true)).unwrap();
385384
}
386385

387386
#[test]
388-
#[should_panic]
387+
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
389388
fn negative_decode_dict_dup_keys_same_data() {
390389
BencodeRef::decode(DICT_DUP_KEYS_SAME_DATA, BDecodeOpt::default()).unwrap();
391390
}
392391

393392
#[test]
394-
#[should_panic]
393+
#[should_panic = "BencodeParseError(InvalidKeyDuplicates { pos: 18, key: [97, 95, 107, 101, 121] }"]
395394
fn negative_decode_dict_dup_keys_diff_data() {
396395
BencodeRef::decode(DICT_DUP_KEYS_DIFF_DATA, BDecodeOpt::default()).unwrap();
397396
}

src/servers/udp/connection_cookie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ mod tests {
314314
}
315315

316316
#[test]
317-
#[should_panic]
317+
#[should_panic = "InvalidConnectionId"]
318318
fn it_should_be_not_valid_after_their_last_time_extent() {
319319
let remote_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0);
320320

src/tracker/peer.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ impl Id {
150150
/// Will panic if byte slice does not contains the exact amount of bytes need for the `Id`.
151151
#[must_use]
152152
pub fn from_bytes(bytes: &[u8]) -> Self {
153-
assert_eq!(bytes.len(), PEER_ID_BYTES_LEN);
153+
assert_eq!(
154+
PEER_ID_BYTES_LEN,
155+
bytes.len(),
156+
"we are testing the equality of the constant: `PEER_ID_BYTES_LEN` ({}) and the supplied `bytes` length: {}",
157+
PEER_ID_BYTES_LEN,
158+
bytes.len(),
159+
);
154160
let mut ret = Self([0u8; PEER_ID_BYTES_LEN]);
155161
ret.0.clone_from_slice(bytes);
156162
ret
@@ -363,14 +369,14 @@ mod test {
363369
}
364370

365371
#[test]
366-
#[should_panic]
372+
#[should_panic = "we are testing the equality of the constant: `PEER_ID_BYTES_LEN` (20) and the supplied `bytes` length: 19"]
367373
fn should_fail_trying_to_instantiate_from_a_byte_slice_with_less_than_20_bytes() {
368374
let less_than_20_bytes = [0; 19];
369375
let _: peer::Id = peer::Id::from_bytes(&less_than_20_bytes);
370376
}
371377

372378
#[test]
373-
#[should_panic]
379+
#[should_panic = "we are testing the equality of the constant: `PEER_ID_BYTES_LEN` (20) and the supplied `bytes` length: 21"]
374380
fn should_fail_trying_to_instantiate_from_a_byte_slice_with_more_than_20_bytes() {
375381
let more_than_20_bytes = [0; 21];
376382
let _: peer::Id = peer::Id::from_bytes(&more_than_20_bytes);
@@ -418,13 +424,13 @@ mod test {
418424
}
419425

420426
#[test]
421-
#[should_panic]
427+
#[should_panic = "NotEnoughBytes"]
422428
fn should_fail_trying_to_convert_from_a_byte_vector_with_less_than_20_bytes() {
423429
let _: peer::Id = peer::Id::try_from([0; 19].to_vec()).unwrap();
424430
}
425431

426432
#[test]
427-
#[should_panic]
433+
#[should_panic = "TooManyBytes"]
428434
fn should_fail_trying_to_convert_from_a_byte_vector_with_more_than_20_bytes() {
429435
let _: peer::Id = peer::Id::try_from([0; 21].to_vec()).unwrap();
430436
}

tests/servers/api/v1/contract/configuration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use torrust_tracker_test_helpers::configuration;
33
use crate::servers::api::test_environment::stopped_test_environment;
44

55
#[tokio::test]
6-
#[should_panic]
6+
#[ignore]
7+
#[should_panic = "Could not receive bind_address."]
78
async fn should_fail_with_ssl_enabled_and_bad_ssl_config() {
89
let mut test_env = stopped_test_environment(configuration::ephemeral());
910

0 commit comments

Comments
 (0)