about summary refs log tree commit diff
path: root/library/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/any.rs1
-rw-r--r--library/core/tests/char.rs4
-rw-r--r--library/core/tests/lazy.rs6
-rw-r--r--library/core/tests/lib.rs13
-rw-r--r--library/core/tests/mem.rs1
-rw-r--r--library/core/tests/num/flt2dec/random.rs6
-rw-r--r--library/core/tests/ptr.rs20
-rw-r--r--library/core/tests/slice.rs9
-rw-r--r--library/core/tests/str.rs2
-rw-r--r--library/core/tests/task.rs8
10 files changed, 33 insertions, 37 deletions
diff --git a/library/core/tests/any.rs b/library/core/tests/any.rs
index e98dac8d12e..a8f6b7ebb92 100644
--- a/library/core/tests/any.rs
+++ b/library/core/tests/any.rs
@@ -131,7 +131,6 @@ fn distinct_type_names() {
     assert_ne!(type_name_of_val(Velocity), type_name_of_val(Velocity(0.0, -9.8)),);
 }
 
-#[cfg(not(bootstrap))]
 #[test]
 fn dyn_type_name() {
     trait Foo {
diff --git a/library/core/tests/char.rs b/library/core/tests/char.rs
index 8542e5c70d4..ac0b2ca168b 100644
--- a/library/core/tests/char.rs
+++ b/library/core/tests/char.rs
@@ -306,6 +306,10 @@ fn test_decode_utf16() {
     }
     check(&[0xD800, 0x41, 0x42], &[Err(0xD800), Ok('A'), Ok('B')]);
     check(&[0xD800, 0], &[Err(0xD800), Ok('\0')]);
+    check(&[0xD800], &[Err(0xD800)]);
+    check(&[0xD840, 0xDC00], &[Ok('\u{20000}')]);
+    check(&[0xD840, 0xD840, 0xDC00], &[Err(0xD840), Ok('\u{20000}')]);
+    check(&[0xDC00, 0xD840], &[Err(0xDC00), Err(0xD840)]);
 }
 
 #[test]
diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs
index 70fcc6d2d4b..c7c3c479b71 100644
--- a/library/core/tests/lazy.rs
+++ b/library/core/tests/lazy.rs
@@ -106,6 +106,12 @@ fn lazy_new() {
     assert_eq!(called.get(), 1);
 }
 
+// Check that we can infer `T` from closure's type.
+#[test]
+fn lazy_type_inference() {
+    let _ = LazyCell::new(|| ());
+}
+
 #[test]
 fn aliasing_in_get() {
     let x = OnceCell::new();
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 99d4a40c4c9..c910cb65c55 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -155,3 +155,16 @@ mod time;
 mod tuple;
 mod unicode;
 mod waker;
+
+/// Copied from `std::test_helpers::test_rng`, see that function for rationale.
+#[track_caller]
+#[allow(dead_code)] // Not used in all configurations.
+pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
+    use core::hash::{BuildHasher, Hash, Hasher};
+    let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
+    core::panic::Location::caller().hash(&mut hasher);
+    let hc64 = hasher.finish();
+    let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
+    let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
+    rand::SeedableRng::from_seed(seed)
+}
diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs
index 1cfb4fd9fd1..f7740a114e7 100644
--- a/library/core/tests/mem.rs
+++ b/library/core/tests/mem.rs
@@ -77,7 +77,6 @@ fn align_of_val_basic() {
 }
 
 #[test]
-#[cfg(not(bootstrap))] // stage 0 doesn't have the fix yet, so the test fails
 fn align_of_val_raw_packed() {
     #[repr(C, packed)]
     struct B {
diff --git a/library/core/tests/num/flt2dec/random.rs b/library/core/tests/num/flt2dec/random.rs
index d0950039314..0084c1c814e 100644
--- a/library/core/tests/num/flt2dec/random.rs
+++ b/library/core/tests/num/flt2dec/random.rs
@@ -9,8 +9,6 @@ use core::num::flt2dec::MAX_SIG_DIGITS;
 use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
 
 use rand::distributions::{Distribution, Uniform};
-use rand::rngs::StdRng;
-use rand::SeedableRng;
 
 pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
     match decode(v).1 {
@@ -92,7 +90,7 @@ where
     if cfg!(target_os = "emscripten") {
         return; // using rng pulls in i128 support, which doesn't work
     }
-    let mut rng = StdRng::from_entropy();
+    let mut rng = crate::test_rng();
     let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
     iterate("f32_random_equivalence_test", k, n, f, g, |_| {
         let x = f32::from_bits(f32_range.sample(&mut rng));
@@ -108,7 +106,7 @@ where
     if cfg!(target_os = "emscripten") {
         return; // using rng pulls in i128 support, which doesn't work
     }
-    let mut rng = StdRng::from_entropy();
+    let mut rng = crate::test_rng();
     let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
     iterate("f64_random_equivalence_test", k, n, f, g, |_| {
         let x = f64::from_bits(f64_range.sample(&mut rng));
diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs
index 90bc8351080..80d30f14c66 100644
--- a/library/core/tests/ptr.rs
+++ b/library/core/tests/ptr.rs
@@ -359,7 +359,6 @@ fn align_offset_zst() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn align_offset_zst_const() {
     const {
         // For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at
@@ -397,7 +396,6 @@ fn align_offset_stride_one() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn align_offset_stride_one_const() {
     const {
         // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to
@@ -493,7 +491,6 @@ fn align_offset_various_strides() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn align_offset_various_strides_const() {
     const unsafe fn test_stride<T>(ptr: *const T, numptr: usize, align: usize) {
         let mut expected = usize::MAX;
@@ -561,7 +558,6 @@ fn align_offset_various_strides_const() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn align_offset_with_provenance_const() {
     const {
         // On some platforms (e.g. msp430-none-elf), the alignment of `i32` is less than 4.
@@ -681,7 +677,6 @@ fn align_offset_issue_103361() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn align_offset_issue_103361_const() {
     #[cfg(target_pointer_width = "64")]
     const SIZE: usize = 1 << 47;
@@ -715,7 +710,6 @@ fn is_aligned() {
 }
 
 #[test]
-#[cfg(not(bootstrap))]
 fn is_aligned_const() {
     const {
         let data = 42;
@@ -735,18 +729,6 @@ fn is_aligned_const() {
 }
 
 #[test]
-#[cfg(bootstrap)]
-fn is_aligned_const() {
-    const {
-        let data = 42;
-        let ptr: *const i32 = &data;
-        // The bootstrap compiler always returns false for is_aligned.
-        assert!(!ptr.is_aligned());
-        assert!(!ptr.is_aligned_to(1));
-    }
-}
-
-#[test]
 fn offset_from() {
     let mut a = [0; 5];
     let ptr1: *mut i32 = &mut a[1];
@@ -825,7 +807,7 @@ fn ptr_metadata_bounds() {
     }
     // "Synthetic" trait impls generated by the compiler like those of `Pointee`
     // are not checked for bounds of associated type.
-    // So with a buggy libcore we could have both:
+    // So with a buggy core we could have both:
     // * `<dyn Display as Pointee>::Metadata == DynMetadata`
     // * `DynMetadata: !PartialEq`
     // … and cause an ICE here:
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index 4e06e0f4398..fd35d96c3fe 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -1805,7 +1805,7 @@ fn brute_force_rotate_test_1() {
 fn sort_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};
     use core::slice::heapsort;
-    use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};
+    use rand::{seq::SliceRandom, Rng};
 
     // Miri is too slow (but still need to `chain` to make the types match)
     let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) };
@@ -1813,7 +1813,7 @@ fn sort_unstable() {
 
     let mut v = [0; 600];
     let mut tmp = [0; 600];
-    let mut rng = StdRng::from_entropy();
+    let mut rng = crate::test_rng();
 
     for len in lens {
         let v = &mut v[0..len];
@@ -1879,11 +1879,10 @@ fn sort_unstable() {
 #[cfg_attr(miri, ignore)] // Miri is too slow
 fn select_nth_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};
-    use rand::rngs::StdRng;
     use rand::seq::SliceRandom;
-    use rand::{Rng, SeedableRng};
+    use rand::Rng;
 
-    let mut rng = StdRng::from_entropy();
+    let mut rng = crate::test_rng();
 
     for len in (2..21).chain(500..501) {
         let mut orig = vec![0; len];
diff --git a/library/core/tests/str.rs b/library/core/tests/str.rs
index ed939ca7139..f5066343af2 100644
--- a/library/core/tests/str.rs
+++ b/library/core/tests/str.rs
@@ -1 +1 @@
-// All `str` tests live in liballoc/tests
+// All `str` tests live in library/alloc/tests/str.rs
diff --git a/library/core/tests/task.rs b/library/core/tests/task.rs
index 56be30e9282..163b34c9648 100644
--- a/library/core/tests/task.rs
+++ b/library/core/tests/task.rs
@@ -1,4 +1,4 @@
-use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
+use core::task::{Poll, RawWaker, RawWakerVTable, Waker};
 
 #[test]
 fn poll_const() {
@@ -21,9 +21,5 @@ fn waker_const() {
 
     static WAKER: Waker = unsafe { Waker::from_raw(VOID_WAKER) };
 
-    static CONTEXT: Context<'static> = Context::from_waker(&WAKER);
-
-    static WAKER_REF: &'static Waker = CONTEXT.waker();
-
-    WAKER_REF.wake_by_ref();
+    WAKER.wake_by_ref();
 }