Skip to content

Commit 5358bb1

Browse files
authored
Rollup merge of #59072 - RalfJung:miri-alloc-tests, r=kennytm
we can now skip should_panic tests with the libtest harness
2 parents 9fb05ce + 52d9fa8 commit 5358bb1

File tree

14 files changed

+3
-91
lines changed

14 files changed

+3
-91
lines changed

src/liballoc/tests/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn assert_covariance() {
282282
//
283283
// Destructors must be called exactly once per element.
284284
#[test]
285-
#[cfg(not(miri))] // Miri does not support panics
285+
#[cfg(not(miri))] // Miri does not support panics nor entropy
286286
fn panic_safe() {
287287
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
288288

src/liballoc/tests/btree/map.rs

-5
Original file line numberDiff line numberDiff line change
@@ -226,39 +226,34 @@ fn test_range_equal_empty_cases() {
226226

227227
#[test]
228228
#[should_panic]
229-
#[cfg(not(miri))] // Miri does not support panics
230229
fn test_range_equal_excluded() {
231230
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
232231
map.range((Excluded(2), Excluded(2)));
233232
}
234233

235234
#[test]
236235
#[should_panic]
237-
#[cfg(not(miri))] // Miri does not support panics
238236
fn test_range_backwards_1() {
239237
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
240238
map.range((Included(3), Included(2)));
241239
}
242240

243241
#[test]
244242
#[should_panic]
245-
#[cfg(not(miri))] // Miri does not support panics
246243
fn test_range_backwards_2() {
247244
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
248245
map.range((Included(3), Excluded(2)));
249246
}
250247

251248
#[test]
252249
#[should_panic]
253-
#[cfg(not(miri))] // Miri does not support panics
254250
fn test_range_backwards_3() {
255251
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
256252
map.range((Excluded(3), Included(2)));
257253
}
258254

259255
#[test]
260256
#[should_panic]
261-
#[cfg(not(miri))] // Miri does not support panics
262257
fn test_range_backwards_4() {
263258
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
264259
map.range((Excluded(3), Excluded(2)));

src/liballoc/tests/slice.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ fn test_swap_remove() {
258258

259259
#[test]
260260
#[should_panic]
261-
#[cfg(not(miri))] // Miri does not support panics
262261
fn test_swap_remove_fail() {
263262
let mut v = vec![1];
264263
let _ = v.swap_remove(0);
@@ -632,7 +631,6 @@ fn test_insert() {
632631

633632
#[test]
634633
#[should_panic]
635-
#[cfg(not(miri))] // Miri does not support panics
636634
fn test_insert_oob() {
637635
let mut a = vec![1, 2, 3];
638636
a.insert(4, 5);
@@ -657,7 +655,6 @@ fn test_remove() {
657655

658656
#[test]
659657
#[should_panic]
660-
#[cfg(not(miri))] // Miri does not support panics
661658
fn test_remove_fail() {
662659
let mut a = vec![1];
663660
let _ = a.remove(0);
@@ -939,7 +936,6 @@ fn test_windowsator() {
939936

940937
#[test]
941938
#[should_panic]
942-
#[cfg(not(miri))] // Miri does not support panics
943939
fn test_windowsator_0() {
944940
let v = &[1, 2, 3, 4];
945941
let _it = v.windows(0);
@@ -964,7 +960,6 @@ fn test_chunksator() {
964960

965961
#[test]
966962
#[should_panic]
967-
#[cfg(not(miri))] // Miri does not support panics
968963
fn test_chunksator_0() {
969964
let v = &[1, 2, 3, 4];
970965
let _it = v.chunks(0);
@@ -989,7 +984,6 @@ fn test_chunks_exactator() {
989984

990985
#[test]
991986
#[should_panic]
992-
#[cfg(not(miri))] // Miri does not support panics
993987
fn test_chunks_exactator_0() {
994988
let v = &[1, 2, 3, 4];
995989
let _it = v.chunks_exact(0);
@@ -1014,7 +1008,6 @@ fn test_rchunksator() {
10141008

10151009
#[test]
10161010
#[should_panic]
1017-
#[cfg(not(miri))] // Miri does not support panics
10181011
fn test_rchunksator_0() {
10191012
let v = &[1, 2, 3, 4];
10201013
let _it = v.rchunks(0);
@@ -1039,7 +1032,6 @@ fn test_rchunks_exactator() {
10391032

10401033
#[test]
10411034
#[should_panic]
1042-
#[cfg(not(miri))] // Miri does not support panics
10431035
fn test_rchunks_exactator_0() {
10441036
let v = &[1, 2, 3, 4];
10451037
let _it = v.rchunks_exact(0);
@@ -1092,7 +1084,6 @@ fn test_vec_default() {
10921084

10931085
#[test]
10941086
#[should_panic]
1095-
#[cfg(not(miri))] // Miri does not support panics
10961087
fn test_overflow_does_not_cause_segfault() {
10971088
let mut v = vec![];
10981089
v.reserve_exact(!0);
@@ -1102,7 +1093,6 @@ fn test_overflow_does_not_cause_segfault() {
11021093

11031094
#[test]
11041095
#[should_panic]
1105-
#[cfg(not(miri))] // Miri does not support panics
11061096
fn test_overflow_does_not_cause_segfault_managed() {
11071097
let mut v = vec![Rc::new(1)];
11081098
v.reserve_exact(!0);
@@ -1278,7 +1268,6 @@ fn test_mut_chunks_rev() {
12781268

12791269
#[test]
12801270
#[should_panic]
1281-
#[cfg(not(miri))] // Miri does not support panics
12821271
fn test_mut_chunks_0() {
12831272
let mut v = [1, 2, 3, 4];
12841273
let _it = v.chunks_mut(0);
@@ -1311,7 +1300,6 @@ fn test_mut_chunks_exact_rev() {
13111300

13121301
#[test]
13131302
#[should_panic]
1314-
#[cfg(not(miri))] // Miri does not support panics
13151303
fn test_mut_chunks_exact_0() {
13161304
let mut v = [1, 2, 3, 4];
13171305
let _it = v.chunks_exact_mut(0);
@@ -1344,7 +1332,6 @@ fn test_mut_rchunks_rev() {
13441332

13451333
#[test]
13461334
#[should_panic]
1347-
#[cfg(not(miri))] // Miri does not support panics
13481335
fn test_mut_rchunks_0() {
13491336
let mut v = [1, 2, 3, 4];
13501337
let _it = v.rchunks_mut(0);
@@ -1377,7 +1364,6 @@ fn test_mut_rchunks_exact_rev() {
13771364

13781365
#[test]
13791366
#[should_panic]
1380-
#[cfg(not(miri))] // Miri does not support panics
13811367
fn test_mut_rchunks_exact_0() {
13821368
let mut v = [1, 2, 3, 4];
13831369
let _it = v.rchunks_exact_mut(0);
@@ -1411,7 +1397,7 @@ fn test_box_slice_clone() {
14111397
#[test]
14121398
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
14131399
#[cfg_attr(target_os = "emscripten", ignore)]
1414-
#[cfg(not(miri))] // Miri does not support panics
1400+
#[cfg(not(miri))] // Miri does not support threads nor entropy
14151401
fn test_box_slice_clone_panics() {
14161402
use std::sync::Arc;
14171403
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -1476,7 +1462,6 @@ fn test_copy_from_slice() {
14761462

14771463
#[test]
14781464
#[should_panic(expected = "destination and source slices have different lengths")]
1479-
#[cfg(not(miri))] // Miri does not support panics
14801465
fn test_copy_from_slice_dst_longer() {
14811466
let src = [0, 1, 2, 3];
14821467
let mut dst = [0; 5];
@@ -1485,7 +1470,6 @@ fn test_copy_from_slice_dst_longer() {
14851470

14861471
#[test]
14871472
#[should_panic(expected = "destination and source slices have different lengths")]
1488-
#[cfg(not(miri))] // Miri does not support panics
14891473
fn test_copy_from_slice_dst_shorter() {
14901474
let src = [0, 1, 2, 3];
14911475
let mut dst = [0; 3];
@@ -1605,7 +1589,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
16051589

16061590
#[test]
16071591
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
1608-
#[cfg(not(miri))] // Miri does not support panics
1592+
#[cfg(not(miri))] // Miri does not support threads nor entropy
16091593
fn panic_safe() {
16101594
let prev = panic::take_hook();
16111595
panic::set_hook(Box::new(move |info| {

src/liballoc/tests/str.rs

-11
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ mod slice_index {
351351
// to be used in `should_panic`)
352352
#[test]
353353
#[should_panic(expected = "out of bounds")]
354-
#[cfg(not(miri))] // Miri does not support panics
355354
fn assert_range_eq_can_fail_by_panic() {
356355
assert_range_eq!("abc", 0..5, "abc");
357356
}
@@ -361,7 +360,6 @@ mod slice_index {
361360
// to be used in `should_panic`)
362361
#[test]
363362
#[should_panic(expected = "==")]
364-
#[cfg(not(miri))] // Miri does not support panics
365363
fn assert_range_eq_can_fail_by_inequality() {
366364
assert_range_eq!("abc", 0..2, "abc");
367365
}
@@ -409,7 +407,6 @@ mod slice_index {
409407

410408
#[test]
411409
#[should_panic(expected = $expect_msg)]
412-
#[cfg(not(miri))] // Miri does not support panics
413410
fn index_fail() {
414411
let v: String = $data.into();
415412
let v: &str = &v;
@@ -418,7 +415,6 @@ mod slice_index {
418415

419416
#[test]
420417
#[should_panic(expected = $expect_msg)]
421-
#[cfg(not(miri))] // Miri does not support panics
422418
fn index_mut_fail() {
423419
let mut v: String = $data.into();
424420
let v: &mut str = &mut v;
@@ -514,7 +510,6 @@ mod slice_index {
514510

515511
#[test]
516512
#[should_panic]
517-
#[cfg(not(miri))] // Miri does not support panics
518513
fn test_slice_fail() {
519514
&"中华Việt Nam"[0..2];
520515
}
@@ -666,14 +661,12 @@ mod slice_index {
666661
// check the panic includes the prefix of the sliced string
667662
#[test]
668663
#[should_panic(expected="byte index 1024 is out of bounds of `Lorem ipsum dolor sit amet")]
669-
#[cfg(not(miri))] // Miri does not support panics
670664
fn test_slice_fail_truncated_1() {
671665
&LOREM_PARAGRAPH[..1024];
672666
}
673667
// check the truncation in the panic message
674668
#[test]
675669
#[should_panic(expected="luctus, im`[...]")]
676-
#[cfg(not(miri))] // Miri does not support panics
677670
fn test_slice_fail_truncated_2() {
678671
&LOREM_PARAGRAPH[..1024];
679672
}
@@ -688,7 +681,6 @@ fn test_str_slice_rangetoinclusive_ok() {
688681

689682
#[test]
690683
#[should_panic]
691-
#[cfg(not(miri))] // Miri does not support panics
692684
fn test_str_slice_rangetoinclusive_notok() {
693685
let s = "abcαβγ";
694686
&s[..=3];
@@ -704,7 +696,6 @@ fn test_str_slicemut_rangetoinclusive_ok() {
704696

705697
#[test]
706698
#[should_panic]
707-
#[cfg(not(miri))] // Miri does not support panics
708699
fn test_str_slicemut_rangetoinclusive_notok() {
709700
let mut s = "abcαβγ".to_owned();
710701
let s: &mut str = &mut s;
@@ -894,7 +885,6 @@ fn test_as_bytes() {
894885

895886
#[test]
896887
#[should_panic]
897-
#[cfg(not(miri))] // Miri does not support panics
898888
fn test_as_bytes_fail() {
899889
// Don't double free. (I'm not sure if this exercises the
900890
// original problem code path anymore.)
@@ -984,7 +974,6 @@ fn test_split_at_mut() {
984974

985975
#[test]
986976
#[should_panic]
987-
#[cfg(not(miri))] // Miri does not support panics
988977
fn test_split_at_boundscheck() {
989978
let s = "ศไทย中华Việt Nam";
990979
s.split_at(1);

src/liballoc/tests/string.rs

-9
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ fn test_split_off_empty() {
231231

232232
#[test]
233233
#[should_panic]
234-
#[cfg(not(miri))] // Miri does not support panics
235234
fn test_split_off_past_end() {
236235
let orig = "Hello, world!";
237236
let mut split = String::from(orig);
@@ -240,7 +239,6 @@ fn test_split_off_past_end() {
240239

241240
#[test]
242241
#[should_panic]
243-
#[cfg(not(miri))] // Miri does not support panics
244242
fn test_split_off_mid_char() {
245243
let mut orig = String::from("山");
246244
orig.split_off(1);
@@ -289,7 +287,6 @@ fn test_str_truncate_invalid_len() {
289287

290288
#[test]
291289
#[should_panic]
292-
#[cfg(not(miri))] // Miri does not support panics
293290
fn test_str_truncate_split_codepoint() {
294291
let mut s = String::from("\u{FC}"); // ü
295292
s.truncate(1);
@@ -324,7 +321,6 @@ fn remove() {
324321

325322
#[test]
326323
#[should_panic]
327-
#[cfg(not(miri))] // Miri does not support panics
328324
fn remove_bad() {
329325
"ศ".to_string().remove(1);
330326
}
@@ -360,13 +356,11 @@ fn insert() {
360356

361357
#[test]
362358
#[should_panic]
363-
#[cfg(not(miri))] // Miri does not support panics
364359
fn insert_bad1() {
365360
"".to_string().insert(1, 't');
366361
}
367362
#[test]
368363
#[should_panic]
369-
#[cfg(not(miri))] // Miri does not support panics
370364
fn insert_bad2() {
371365
"ệ".to_string().insert(1, 't');
372366
}
@@ -447,7 +441,6 @@ fn test_replace_range() {
447441

448442
#[test]
449443
#[should_panic]
450-
#[cfg(not(miri))] // Miri does not support panics
451444
fn test_replace_range_char_boundary() {
452445
let mut s = "Hello, 世界!".to_owned();
453446
s.replace_range(..8, "");
@@ -464,15 +457,13 @@ fn test_replace_range_inclusive_range() {
464457

465458
#[test]
466459
#[should_panic]
467-
#[cfg(not(miri))] // Miri does not support panics
468460
fn test_replace_range_out_of_bounds() {
469461
let mut s = String::from("12345");
470462
s.replace_range(5..6, "789");
471463
}
472464

473465
#[test]
474466
#[should_panic]
475-
#[cfg(not(miri))] // Miri does not support panics
476467
fn test_replace_range_inclusive_out_of_bounds() {
477468
let mut s = String::from("12345");
478469
s.replace_range(5..=5, "789");

0 commit comments

Comments
 (0)