mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
auto merge of #11082 : brson/rust/noat, r=alexcrichton
This commit is contained in:
commit
2e4cd83a0a
@ -353,56 +353,56 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_multitask() {
|
fn test_tls_multitask() {
|
||||||
static my_key: Key<@~str> = &Key;
|
static my_key: Key<~str> = &Key;
|
||||||
set(my_key, @~"parent data");
|
set(my_key, ~"parent data");
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
// TLS shouldn't carry over.
|
// TLS shouldn't carry over.
|
||||||
assert!(get(my_key, |k| k.map(|k| *k)).is_none());
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).is_none());
|
||||||
set(my_key, @~"child data");
|
set(my_key, ~"child data");
|
||||||
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) ==
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() ==
|
||||||
~"child data");
|
~"child data");
|
||||||
// should be cleaned up for us
|
// should be cleaned up for us
|
||||||
}
|
}
|
||||||
// Must work multiple times
|
// Must work multiple times
|
||||||
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
|
||||||
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
|
||||||
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data");
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_overwrite() {
|
fn test_tls_overwrite() {
|
||||||
static my_key: Key<@~str> = &Key;
|
static my_key: Key<~str> = &Key;
|
||||||
set(my_key, @~"first data");
|
set(my_key, ~"first data");
|
||||||
set(my_key, @~"next data"); // Shouldn't leak.
|
set(my_key, ~"next data"); // Shouldn't leak.
|
||||||
assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"next data");
|
assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"next data");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_pop() {
|
fn test_tls_pop() {
|
||||||
static my_key: Key<@~str> = &Key;
|
static my_key: Key<~str> = &Key;
|
||||||
set(my_key, @~"weasel");
|
set(my_key, ~"weasel");
|
||||||
assert!(*(pop(my_key).unwrap()) == ~"weasel");
|
assert!(pop(my_key).unwrap() == ~"weasel");
|
||||||
// Pop must remove the data from the map.
|
// Pop must remove the data from the map.
|
||||||
assert!(pop(my_key).is_none());
|
assert!(pop(my_key).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_modify() {
|
fn test_tls_modify() {
|
||||||
static my_key: Key<@~str> = &Key;
|
static my_key: Key<~str> = &Key;
|
||||||
modify(my_key, |data| {
|
modify(my_key, |data| {
|
||||||
match data {
|
match data {
|
||||||
Some(@ref val) => fail!("unwelcome value: {}", *val),
|
Some(ref val) => fail!("unwelcome value: {}", *val),
|
||||||
None => Some(@~"first data")
|
None => Some(~"first data")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
modify(my_key, |data| {
|
modify(my_key, |data| {
|
||||||
match data {
|
match data {
|
||||||
Some(@~"first data") => Some(@~"next data"),
|
Some(~"first data") => Some(~"next data"),
|
||||||
Some(@ref val) => fail!("wrong value: {}", *val),
|
Some(ref val) => fail!("wrong value: {}", *val),
|
||||||
None => fail!("missing value")
|
None => fail!("missing value")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert!(*(pop(my_key).unwrap()) == ~"next data");
|
assert!(pop(my_key).unwrap() == ~"next data");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -413,67 +413,67 @@ mod tests {
|
|||||||
// to get recorded as something within a rust stack segment. Then a
|
// to get recorded as something within a rust stack segment. Then a
|
||||||
// subsequent upcall (esp. for logging, think vsnprintf) would run on
|
// subsequent upcall (esp. for logging, think vsnprintf) would run on
|
||||||
// a stack smaller than 1 MB.
|
// a stack smaller than 1 MB.
|
||||||
static my_key: Key<@~str> = &Key;
|
static my_key: Key<~str> = &Key;
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
set(my_key, @~"hax");
|
set(my_key, ~"hax");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_multiple_types() {
|
fn test_tls_multiple_types() {
|
||||||
static str_key: Key<@~str> = &Key;
|
static str_key: Key<~str> = &Key;
|
||||||
static box_key: Key<@@()> = &Key;
|
static box_key: Key<@()> = &Key;
|
||||||
static int_key: Key<@int> = &Key;
|
static int_key: Key<int> = &Key;
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
set(str_key, @~"string data");
|
set(str_key, ~"string data");
|
||||||
set(box_key, @@());
|
set(box_key, @());
|
||||||
set(int_key, @42);
|
set(int_key, 42);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tls_overwrite_multiple_types() {
|
fn test_tls_overwrite_multiple_types() {
|
||||||
static str_key: Key<@~str> = &Key;
|
static str_key: Key<~str> = &Key;
|
||||||
static box_key: Key<@@()> = &Key;
|
static box_key: Key<@()> = &Key;
|
||||||
static int_key: Key<@int> = &Key;
|
static int_key: Key<int> = &Key;
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
set(str_key, @~"string data");
|
set(str_key, ~"string data");
|
||||||
set(str_key, @~"string data 2");
|
set(str_key, ~"string data 2");
|
||||||
set(box_key, @@());
|
set(box_key, @());
|
||||||
set(box_key, @@());
|
set(box_key, @());
|
||||||
set(int_key, @42);
|
set(int_key, 42);
|
||||||
// This could cause a segfault if overwriting-destruction is done
|
// This could cause a segfault if overwriting-destruction is done
|
||||||
// with the crazy polymorphic transmute rather than the provided
|
// with the crazy polymorphic transmute rather than the provided
|
||||||
// finaliser.
|
// finaliser.
|
||||||
set(int_key, @31337);
|
set(int_key, 31337);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_tls_cleanup_on_failure() {
|
fn test_tls_cleanup_on_failure() {
|
||||||
static str_key: Key<@~str> = &Key;
|
static str_key: Key<~str> = &Key;
|
||||||
static box_key: Key<@@()> = &Key;
|
static box_key: Key<@()> = &Key;
|
||||||
static int_key: Key<@int> = &Key;
|
static int_key: Key<int> = &Key;
|
||||||
set(str_key, @~"parent data");
|
set(str_key, ~"parent data");
|
||||||
set(box_key, @@());
|
set(box_key, @());
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
// spawn_linked
|
// spawn_linked
|
||||||
set(str_key, @~"string data");
|
set(str_key, ~"string data");
|
||||||
set(box_key, @@());
|
set(box_key, @());
|
||||||
set(int_key, @42);
|
set(int_key, 42);
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
// Not quite nondeterministic.
|
// Not quite nondeterministic.
|
||||||
set(int_key, @31337);
|
set(int_key, 31337);
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_static_pointer() {
|
fn test_static_pointer() {
|
||||||
static key: Key<@&'static int> = &Key;
|
static key: Key<&'static int> = &Key;
|
||||||
static VALUE: int = 0;
|
static VALUE: int = 0;
|
||||||
let v: @&'static int = @&VALUE;
|
let v: &'static int = &VALUE;
|
||||||
set(key, v);
|
set(key, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,28 +445,34 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_resource() {
|
fn test_get_resource() {
|
||||||
|
use rc::Rc;
|
||||||
|
use cell::RefCell;
|
||||||
|
|
||||||
struct R {
|
struct R {
|
||||||
i: @mut int,
|
i: Rc<RefCell<int>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
impl ::ops::Drop for R {
|
impl ::ops::Drop for R {
|
||||||
fn drop(&mut self) { *(self.i) += 1; }
|
fn drop(&mut self) {
|
||||||
|
let ii = self.i.borrow();
|
||||||
|
ii.set(ii.get() + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn R(i: @mut int) -> R {
|
fn R(i: Rc<RefCell<int>>) -> R {
|
||||||
R {
|
R {
|
||||||
i: i
|
i: i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let i = @mut 0;
|
let i = Rc::from_send(RefCell::new(0));
|
||||||
{
|
{
|
||||||
let x = R(i);
|
let x = R(i.clone());
|
||||||
let opt = Some(x);
|
let opt = Some(x);
|
||||||
let _y = opt.unwrap();
|
let _y = opt.unwrap();
|
||||||
}
|
}
|
||||||
assert_eq!(*i, 1);
|
assert_eq!(i.borrow().get(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -3254,7 +3254,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_truncate() {
|
fn test_truncate() {
|
||||||
let mut v = ~[@6,@5,@4];
|
let mut v = ~[~6,~5,~4];
|
||||||
v.truncate(1);
|
v.truncate(1);
|
||||||
assert_eq!(v.len(), 1);
|
assert_eq!(v.len(), 1);
|
||||||
assert_eq!(*(v[0]), 6);
|
assert_eq!(*(v[0]), 6);
|
||||||
@ -3263,7 +3263,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear() {
|
fn test_clear() {
|
||||||
let mut v = ~[@6,@5,@4];
|
let mut v = ~[~6,~5,~4];
|
||||||
v.clear();
|
v.clear();
|
||||||
assert_eq!(v.len(), 0);
|
assert_eq!(v.len(), 0);
|
||||||
// If the unsafe block didn't drop things properly, we blow up here.
|
// If the unsafe block didn't drop things properly, we blow up here.
|
||||||
@ -3302,14 +3302,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dedup_shared() {
|
fn test_dedup_shared() {
|
||||||
let mut v0 = ~[@1, @1, @2, @3];
|
let mut v0 = ~[~1, ~1, ~2, ~3];
|
||||||
v0.dedup();
|
v0.dedup();
|
||||||
let mut v1 = ~[@1, @2, @2, @3];
|
let mut v1 = ~[~1, ~2, ~2, ~3];
|
||||||
v1.dedup();
|
v1.dedup();
|
||||||
let mut v2 = ~[@1, @2, @3, @3];
|
let mut v2 = ~[~1, ~2, ~3, ~3];
|
||||||
v2.dedup();
|
v2.dedup();
|
||||||
/*
|
/*
|
||||||
* If the @pointers were leaked or otherwise misused, valgrind and/or
|
* If the pointers were leaked or otherwise misused, valgrind and/or
|
||||||
* rustrt should raise errors.
|
* rustrt should raise errors.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@ -3694,7 +3694,7 @@ mod tests {
|
|||||||
fn test_from_fn_fail() {
|
fn test_from_fn_fail() {
|
||||||
from_fn(100, |v| {
|
from_fn(100, |v| {
|
||||||
if v == 50 { fail!() }
|
if v == 50 { fail!() }
|
||||||
(~0, @0)
|
~0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3702,10 +3702,11 @@ mod tests {
|
|||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_from_elem_fail() {
|
fn test_from_elem_fail() {
|
||||||
use cast;
|
use cast;
|
||||||
|
use rc::Rc;
|
||||||
|
|
||||||
struct S {
|
struct S {
|
||||||
f: int,
|
f: int,
|
||||||
boxes: (~int, @int)
|
boxes: (~int, Rc<int>)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for S {
|
impl Clone for S {
|
||||||
@ -3717,18 +3718,19 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = S { f: 0, boxes: (~0, @0) };
|
let s = S { f: 0, boxes: (~0, Rc::new(0)) };
|
||||||
let _ = from_elem(100, s);
|
let _ = from_elem(100, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_build_fail() {
|
fn test_build_fail() {
|
||||||
|
use rc::Rc;
|
||||||
build(None, |push| {
|
build(None, |push| {
|
||||||
push((~0, @0));
|
push((~0, Rc::new(0)));
|
||||||
push((~0, @0));
|
push((~0, Rc::new(0)));
|
||||||
push((~0, @0));
|
push((~0, Rc::new(0)));
|
||||||
push((~0, @0));
|
push((~0, Rc::new(0)));
|
||||||
fail!();
|
fail!();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -3736,47 +3738,51 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_grow_fn_fail() {
|
fn test_grow_fn_fail() {
|
||||||
|
use rc::Rc;
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
v.grow_fn(100, |i| {
|
v.grow_fn(100, |i| {
|
||||||
if i == 50 {
|
if i == 50 {
|
||||||
fail!()
|
fail!()
|
||||||
}
|
}
|
||||||
(~0, @0)
|
(~0, Rc::new(0))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_map_fail() {
|
fn test_map_fail() {
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
use rc::Rc;
|
||||||
|
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
v.map(|_elt| {
|
v.map(|_elt| {
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
fail!()
|
fail!()
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
~[(~0, @0)]
|
~[(~0, Rc::new(0))]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_flat_map_fail() {
|
fn test_flat_map_fail() {
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
use rc::Rc;
|
||||||
|
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
flat_map(v, |_elt| {
|
flat_map(v, |_elt| {
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
fail!()
|
fail!()
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
~[(~0, @0)]
|
~[(~0, Rc::new(0))]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_permute_fail() {
|
fn test_permute_fail() {
|
||||||
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
|
use rc::Rc;
|
||||||
|
let v = [(~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0)), (~0, Rc::new(0))];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for _ in v.permutations() {
|
for _ in v.permutations() {
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
@ -4114,9 +4120,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_overflow_does_not_cause_segfault_managed() {
|
fn test_overflow_does_not_cause_segfault_managed() {
|
||||||
let mut v = ~[@1];
|
use rc::Rc;
|
||||||
|
let mut v = ~[Rc::new(1)];
|
||||||
v.reserve(-1);
|
v.reserve(-1);
|
||||||
v.push(@2);
|
v.push(Rc::new(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user