Closed mssun closed 4 years ago
Add smallvec 1.2.0
diff --git a/Cargo.toml b/Cargo.toml index b09d63f..a9126b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,17 +12,21 @@ readme = "README.md" documentation = "https://docs.rs/smallvec/" [features] -write = [] +write = ["sgx_tstd"] union = [] specialization = [] may_dangle = [] +enclave_unit_test = ["sgx_tunittest"] [lib] name = "smallvec" path = "lib.rs" [dependencies] -serde = { version = "1", optional = true } +serde = { git = "https://github.com/universal-secure-computing-community/crates-sgx.git", tag = "v0.2.1+sgx1.1.1", optional = true } + +sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk.git", tag = "v1.1.1", optional = true } +sgx_tunittest = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk.git", tag = "v1.1.1", optional = true } [dev_dependencies] bincode = "1.0.1" diff --git a/lib.rs b/lib.rs index 0c8243e..190e803 100644 --- a/lib.rs +++ b/lib.rs @@ -35,7 +35,8 @@ pub extern crate alloc; #[cfg(any(test, feature = "write"))] -extern crate std; +#[macro_use] +extern crate sgx_tstd as std; use alloc::boxed::Box; use alloc::{vec, vec::Vec}; @@ -1684,8 +1685,9 @@ impl_array!( 0x40000, 0x60000, 0x80000, 0x10_0000 ); -#[cfg(test)] -mod tests { +#[cfg(feature = "enclave_unit_test")] +#[allow(missing_docs)] +pub mod tests { use crate::SmallVec; use std::iter::FromIterator; @@ -1694,8 +1696,9 @@ mod tests { use alloc::boxed::Box; use alloc::rc::Rc; use alloc::{vec, vec::Vec}; + use std::prelude::v1::*; + - #[test] pub fn test_zero() { let mut v = SmallVec::<[_; 0]>::new(); assert!(!v.spilled()); @@ -1706,7 +1709,7 @@ mod tests { // We heap allocate all these strings so that double frees will show up under valgrind. - #[test] + pub fn test_inline() { let mut v = SmallVec::<[_; 16]>::new(); v.push("hello".to_owned()); @@ -1714,7 +1717,7 @@ mod tests { assert_eq!(&*v, &["hello".to_owned(), "there".to_owned(),][..]); } - #[test] + pub fn test_spill() { let mut v = SmallVec::<[_; 2]>::new(); v.push("hello".to_owned()); @@ -1734,7 +1737,7 @@ mod tests { ); } - #[test] + pub fn test_double_spill() { let mut v = SmallVec::<[_; 2]>::new(); v.push("hello".to_owned()); @@ -1761,18 +1764,18 @@ mod tests { } /// https://github.com/servo/rust-smallvec/issues/4 - #[test] + fn issue_4() { SmallVec::<[Box<u32>; 2]>::new(); } /// https://github.com/servo/rust-smallvec/issues/5 - #[test] + fn issue_5() { assert!(Some(SmallVec::<[&u32; 2]>::new()).is_some()); } - #[test] + fn test_with_capacity() { let v: SmallVec<[u8; 3]> = SmallVec::with_capacity(1); assert!(v.is_empty()); @@ -1785,7 +1788,7 @@ mod tests { assert_eq!(v.capacity(), 10); } - #[test] + fn drain() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(3); @@ -1801,7 +1804,7 @@ mod tests { assert_eq!(v.capacity(), old_capacity); } - #[test] + fn drain_rev() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(3); @@ -1814,14 +1817,14 @@ mod tests { assert_eq!(v.drain(..).rev().collect::<Vec<_>>(), &[5, 4, 3]); } - #[test] + fn drain_forget() { let mut v: SmallVec<[u8; 1]> = smallvec![0, 1, 2, 3, 4, 5, 6, 7]; std::mem::forget(v.drain(2..5)); assert_eq!(v.len(), 2); } - #[test] + fn into_iter() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(3); @@ -1835,7 +1838,7 @@ mod tests { assert_eq!(v.into_iter().collect::<Vec<_>>(), &[3, 4, 5]); } - #[test] + fn into_iter_rev() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(3); @@ -1849,7 +1852,7 @@ mod tests { assert_eq!(v.into_iter().rev().collect::<Vec<_>>(), &[5, 4, 3]); } - #[test] + fn into_iter_drop() { use std::cell::Cell; @@ -1902,7 +1905,7 @@ mod tests { } } - #[test] + fn test_capacity() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.reserve(1); @@ -1921,7 +1924,7 @@ mod tests { assert!(v.capacity() < 0x100); } - #[test] + fn test_truncate() { let mut v: SmallVec<[Box<u8>; 8]> = SmallVec::new(); @@ -1940,7 +1943,7 @@ mod tests { assert_eq!(&v.iter().map(|v| **v).collect::<Vec<_>>(), &[0, 3, 2]); } - #[test] + fn test_insert_many() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); for x in 0..4 { @@ -1968,7 +1971,7 @@ mod tests { } } - #[test] + fn test_insert_many_short_hint() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); for x in 0..4 { @@ -1988,7 +1991,7 @@ mod tests { ); } - #[test] + fn test_insert_many_long_hint() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); for x in 0..4 { @@ -2008,7 +2011,7 @@ mod tests { ); } - #[test] + // https://github.com/servo/rust-smallvec/issues/96 fn test_insert_many_panic() { struct PanicOnDoubleDrop { @@ -2048,7 +2051,7 @@ mod tests { assert!(result.is_err()); } - #[test] + #[should_panic] fn test_invalid_grow() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); @@ -2056,7 +2059,7 @@ mod tests { v.grow(5); } - #[test] + fn test_insert_from_slice() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); for x in 0..4 { @@ -2070,7 +2073,7 @@ mod tests { ); } - #[test] + fn test_extend_from_slice() { let mut v: SmallVec<[u8; 8]> = SmallVec::new(); for x in 0..4 { @@ -2084,7 +2087,7 @@ mod tests { ); } - #[test] + #[should_panic] fn test_drop_panic_smallvec() { // This test should only panic once, and not double panic, @@ -2101,7 +2104,7 @@ mod tests { v.push(DropPanic); } - #[test] + fn test_eq() { let mut a: SmallVec<[u32; 2]> = SmallVec::new(); let mut b: SmallVec<[u32; 2]> = SmallVec::new(); @@ -2120,7 +2123,7 @@ mod tests { assert!(a != c); } - #[test] + fn test_ord() { let mut a: SmallVec<[u32; 2]> = SmallVec::new(); let mut b: SmallVec<[u32; 2]> = SmallVec::new(); @@ -2140,7 +2143,7 @@ mod tests { assert!(c > b); } - #[test] + fn test_hash() { use std::collections::hash_map::DefaultHasher; use std::hash::Hash; @@ -2161,7 +2164,7 @@ mod tests { } } - #[test] + fn test_as_ref() { let mut a: SmallVec<[u32; 2]> = SmallVec::new(); a.push(1); @@ -2172,7 +2175,7 @@ mod tests { assert_eq!(a.as_ref(), [1, 2, 3]); } - #[test] + fn test_as_mut() { let mut a: SmallVec<[u32; 2]> = SmallVec::new(); a.push(1); @@ -2185,7 +2188,7 @@ mod tests { assert_eq!(a.as_mut(), [1, 4, 3]); } - #[test] + fn test_borrow() { use std::borrow::Borrow; @@ -2198,7 +2201,7 @@ mod tests { assert_eq!(a.borrow(), [1, 2, 3]); } - #[test] + fn test_borrow_mut() { use std::borrow::BorrowMut; @@ -2213,7 +2216,7 @@ mod tests { assert_eq!(a.borrow_mut(), [1, 4, 3]); } - #[test] + fn test_from() { assert_eq!(&SmallVec::<[u32; 2]>::from(&[1][..])[..], [1]); assert_eq!(&SmallVec::<[u32; 2]>::from(&[1, 2, 3][..])[..], [1, 2, 3]); @@ -2244,7 +2247,7 @@ mod tests { drop(small_vec); } - #[test] + fn test_from_slice() { assert_eq!(&SmallVec::<[u32; 2]>::from_slice(&[1][..])[..], [1]); assert_eq!( @@ -2253,7 +2256,7 @@ mod tests { ); } - #[test] + fn test_exact_size_iterator() { let mut vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]); assert_eq!(vec.clone().into_iter().len(), 3); @@ -2261,7 +2264,7 @@ mod tests { assert_eq!(vec.into_iter().len(), 1); } - #[test] + fn test_into_iter_as_slice() { let vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]); let mut iter = vec.clone().into_iter(); @@ -2275,7 +2278,7 @@ mod tests { assert_eq!(iter.as_mut_slice(), &[2]); } - #[test] + fn test_into_iter_clone() { // Test that the cloned iterator yields identical elements and that it owns its own copy // (i.e. no use after move errors). @@ -2287,7 +2290,7 @@ mod tests { assert_eq!(clone_iter.next(), None); } - #[test] + fn test_into_iter_clone_partially_consumed_iterator() { // Test that the cloned iterator only contains the remaining elements of the original iterator. let mut iter = SmallVec::<[u8; 2]>::from_iter(0..3).into_iter().skip(1); @@ -2298,7 +2301,7 @@ mod tests { assert_eq!(clone_iter.next(), None); } - #[test] + fn test_into_iter_clone_empty_smallvec() { let mut iter = SmallVec::<[u8; 2]>::new().into_iter(); let mut clone_iter = iter.clone(); @@ -2306,7 +2309,7 @@ mod tests { assert_eq!(clone_iter.next(), None); } - #[test] + fn shrink_to_fit_unspill() { let mut vec = SmallVec::<[u8; 2]>::from_iter(0..3); vec.pop(); @@ -2315,7 +2318,7 @@ mod tests { assert!(!vec.spilled(), "shrink_to_fit will un-spill if possible"); } - #[test] + fn test_into_vec() { let vec = SmallVec::<[u8; 2]>::from_iter(0..2); assert_eq!(vec.into_vec(), vec![0, 1]); @@ -2324,7 +2327,7 @@ mod tests { assert_eq!(vec.into_vec(), vec![0, 1, 2]); } - #[test] + fn test_into_inner() { let vec = SmallVec::<[u8; 2]>::from_iter(0..2); assert_eq!(vec.into_inner(), Ok([0, 1])); @@ -2336,7 +2339,7 @@ mod tests { assert_eq!(vec.clone().into_inner(), Err(vec)); } - #[test] + fn test_from_vec() { let vec = vec![]; let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec); @@ -2369,7 +2372,7 @@ mod tests { drop(small_vec); } - #[test] + fn test_retain() { // Test inline data storate let mut sv: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 2, 3, 3, 4]); @@ -2404,7 +2407,7 @@ mod tests { assert_eq!(Rc::strong_count(&one), 1); } - #[test] + fn test_dedup() { let mut dupes: SmallVec<[i32; 5]> = SmallVec::from_slice(&[1, 1, 2, 3, 3]); dupes.dedup(); @@ -2423,7 +2426,7 @@ mod tests { assert_eq!(no_dupes.len(), 5); } - #[test] + fn test_resize() { let mut v: SmallVec<[i32; 8]> = SmallVec::new(); v.push(1); @@ -2435,7 +2438,7 @@ mod tests { } #[cfg(feature = "write")] - #[test] + fn test_write() { use std::io::Write; @@ -2455,7 +2458,6 @@ mod tests { extern crate bincode; #[cfg(feature = "serde")] - #[test] fn test_serde() { use self::bincode::{config, deserialize}; let mut small_vec: SmallVec<[i32; 2]> = SmallVec::new(); @@ -2473,7 +2475,7 @@ mod tests { assert_eq!(small_vec, decoded); } - #[test] + fn grow_to_shrink() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(1); @@ -2490,7 +2492,7 @@ mod tests { assert_eq!(v[..], [4]); } - #[test] + fn resumable_extend() { let s = "a b c"; // This iterator yields: (Some('a'), None, Some('b'), None, Some('c')), None @@ -2503,13 +2505,13 @@ mod tests { } // #139 - #[test] + fn uninhabited() { enum Void {} let _sv = SmallVec::<[Void; 8]>::new(); } - #[test] + fn grow_spilled_same_size() { let mut v: SmallVec<[u8; 2]> = SmallVec::new(); v.push(0); @@ -2522,4 +2524,54 @@ mod tests { assert_eq!(v.capacity(), 4); assert_eq!(v[..], [0, 1, 2]); } + + pub fn run_tests() { + use sgx_tunittest::*; + rsgx_unit_tests!( + test_zero, + test_inline, + test_spill, + test_double_spill, + issue_4, + issue_5, + test_with_capacity, + drain, + drain_rev, + drain_forget, + into_iter, + into_iter_rev, + into_iter_drop, + test_capacity, + test_truncate, + test_insert_many, + test_insert_many_short_hint, + test_insert_many_long_hint, + test_ord, + test_hash, + test_as_ref, + test_as_mut, + test_borrow, + test_borrow_mut, + test_from, + test_from_slice, + test_exact_size_iterator, + test_into_iter_as_slice, + test_into_iter_clone, + test_into_iter_clone_partially_consumed_iterator, + test_into_iter_clone_empty_smallvec, + shrink_to_fit_unspill, + test_into_vec, + test_into_inner, + test_from_vec, + test_retain, + test_dedup, + test_resize, + test_write, + // test_serde, + grow_to_shrink, + resumable_extend, + uninhabited, + grow_spilled_same_size, + ); + } }
Add smallvec 1.2.0
Description
Add smallvec 1.2.0
Crate Meta
Diff of Changes