libcore: Fix tests.

This commit is contained in:
Patrick Walton
2013-05-07 17:57:58 -07:00
parent 49a66a5c5a
commit 16a0125e41
18 changed files with 135 additions and 113 deletions

View File

@@ -596,9 +596,10 @@ mod test {
c1.send(~"abc"); c1.send(~"abc");
match (p1, p2).select() { let mut tuple = (p1, p2);
Right(_) => fail!(), match tuple.select() {
_ => () Right(_) => fail!(),
_ => (),
} }
c2.send(123); c2.send(123);

View File

@@ -84,10 +84,11 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
#[test] #[test]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn test_flate_round_trip() { fn test_flate_round_trip() {
let r = rand::rng(); let mut r = rand::rng();
let mut words = ~[]; let mut words = ~[];
for 20.times { for 20.times {
words.push(r.gen_bytes(r.gen_uint_range(1, 10))); let range = r.gen_uint_range(1, 10);
words.push(r.gen_bytes(range));
} }
for 20.times { for 20.times {
let mut in = ~[]; let mut in = ~[];

View File

@@ -473,10 +473,10 @@ mod tests {
let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64;
let mut buf : ~[u8] = ~[]; let mut buf : ~[u8] = ~[];
let mut t = 0; let mut t = 0;
let stream_inc = &State(k0,k1); let mut stream_inc = SipState::new(k0, k1);
let stream_full = &State(k0,k1); let mut stream_full = SipState::new(k0, k1);
fn to_hex_str(r: &[u8, ..8]) -> ~str { fn to_hex_str(r: &[u8, ..8]) -> ~str {
let mut s = ~""; let mut s = ~"";
for vec::each(*r) |b| { for vec::each(*r) |b| {
s += uint::to_str_radix(*b as uint, 16u); s += uint::to_str_radix(*b as uint, 16u);

View File

@@ -1886,15 +1886,15 @@ mod tests {
fn bytes_buffer_overwrite() { fn bytes_buffer_overwrite() {
let wr = BytesWriter(); let wr = BytesWriter();
wr.write(~[0u8, 1u8, 2u8, 3u8]); wr.write(~[0u8, 1u8, 2u8, 3u8]);
assert!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]); assert!(*wr.bytes == ~[0u8, 1u8, 2u8, 3u8]);
wr.seek(-2, SeekCur); wr.seek(-2, SeekCur);
wr.write(~[4u8, 5u8, 6u8, 7u8]); wr.write(~[4u8, 5u8, 6u8, 7u8]);
assert!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]); assert!(*wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
wr.seek(-2, SeekEnd); wr.seek(-2, SeekEnd);
wr.write(~[8u8]); wr.write(~[8u8]);
wr.seek(1, SeekSet); wr.seek(1, SeekSet);
wr.write(~[9u8]); wr.write(~[9u8]);
assert!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]); assert!(*wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
} }
#[test] #[test]

View File

@@ -1435,7 +1435,7 @@ mod tests {
} }
fn make_rand_name() -> ~str { fn make_rand_name() -> ~str {
let rng = rand::rng(); let mut rng = rand::rng();
let n = ~"TEST" + rng.gen_str(10u); let n = ~"TEST" + rng.gen_str(10u);
assert!(getenv(n).is_none()); assert!(getenv(n).is_none());
n n

View File

@@ -894,9 +894,10 @@ mod test {
c1.send(~"abc"); c1.send(~"abc");
match (p1, p2).select() { let mut tuple = (p1, p2);
Right(_) => fail!(), match tuple.select() {
_ => () Right(_) => fail!(),
_ => (),
} }
c2.send(123); c2.send(123);

View File

@@ -879,8 +879,8 @@ mod tests {
#[test] #[test]
fn test_rng_seeded() { fn test_rng_seeded() {
let seed = seed(); let seed = seed();
let ra = IsaacRng::new_seeded(seed); let mut ra = IsaacRng::new_seeded(seed);
let rb = IsaacRng::new_seeded(seed); let mut rb = IsaacRng::new_seeded(seed);
assert!(ra.gen_str(100u) == rb.gen_str(100u)); assert!(ra.gen_str(100u) == rb.gen_str(100u));
} }
@@ -888,15 +888,15 @@ mod tests {
fn test_rng_seeded_custom_seed() { fn test_rng_seeded_custom_seed() {
// much shorter than generated seeds which are 1024 bytes // much shorter than generated seeds which are 1024 bytes
let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
let ra = IsaacRng::new_seeded(seed); let mut ra = IsaacRng::new_seeded(seed);
let rb = IsaacRng::new_seeded(seed); let mut rb = IsaacRng::new_seeded(seed);
assert!(ra.gen_str(100u) == rb.gen_str(100u)); assert!(ra.gen_str(100u) == rb.gen_str(100u));
} }
#[test] #[test]
fn test_rng_seeded_custom_seed2() { fn test_rng_seeded_custom_seed2() {
let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
let ra = IsaacRng::new_seeded(seed); let mut ra = IsaacRng::new_seeded(seed);
// Regression test that isaac is actually using the above vector // Regression test that isaac is actually using the above vector
let r = ra.next(); let r = ra.next();
error!("%?", r); error!("%?", r);
@@ -906,7 +906,7 @@ mod tests {
#[test] #[test]
fn test_gen_int_range() { fn test_gen_int_range() {
let r = rng(); let mut r = rng();
let a = r.gen_int_range(-3, 42); let a = r.gen_int_range(-3, 42);
assert!(a >= -3 && a < 42); assert!(a >= -3 && a < 42);
assert!(r.gen_int_range(0, 1) == 0); assert!(r.gen_int_range(0, 1) == 0);
@@ -917,12 +917,13 @@ mod tests {
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_gen_int_from_fail() { fn test_gen_int_from_fail() {
rng().gen_int_range(5, -2); let mut r = rng();
r.gen_int_range(5, -2);
} }
#[test] #[test]
fn test_gen_uint_range() { fn test_gen_uint_range() {
let r = rng(); let mut r = rng();
let a = r.gen_uint_range(3u, 42u); let a = r.gen_uint_range(3u, 42u);
assert!(a >= 3u && a < 42u); assert!(a >= 3u && a < 42u);
assert!(r.gen_uint_range(0u, 1u) == 0u); assert!(r.gen_uint_range(0u, 1u) == 0u);
@@ -933,12 +934,13 @@ mod tests {
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_gen_uint_range_fail() { fn test_gen_uint_range_fail() {
rng().gen_uint_range(5u, 2u); let mut r = rng();
r.gen_uint_range(5u, 2u);
} }
#[test] #[test]
fn test_gen_float() { fn test_gen_float() {
let r = rng(); let mut r = rng();
let a = r.gen::<float>(); let a = r.gen::<float>();
let b = r.gen::<float>(); let b = r.gen::<float>();
debug!((a, b)); debug!((a, b));
@@ -946,14 +948,14 @@ mod tests {
#[test] #[test]
fn test_gen_weighted_bool() { fn test_gen_weighted_bool() {
let r = rng(); let mut r = rng();
assert!(r.gen_weighted_bool(0u) == true); assert!(r.gen_weighted_bool(0u) == true);
assert!(r.gen_weighted_bool(1u) == true); assert!(r.gen_weighted_bool(1u) == true);
} }
#[test] #[test]
fn test_gen_str() { fn test_gen_str() {
let r = rng(); let mut r = rng();
debug!(r.gen_str(10u)); debug!(r.gen_str(10u));
debug!(r.gen_str(10u)); debug!(r.gen_str(10u));
debug!(r.gen_str(10u)); debug!(r.gen_str(10u));
@@ -964,7 +966,7 @@ mod tests {
#[test] #[test]
fn test_gen_bytes() { fn test_gen_bytes() {
let r = rng(); let mut r = rng();
assert!(r.gen_bytes(0u).len() == 0u); assert!(r.gen_bytes(0u).len() == 0u);
assert!(r.gen_bytes(10u).len() == 10u); assert!(r.gen_bytes(10u).len() == 10u);
assert!(r.gen_bytes(16u).len() == 16u); assert!(r.gen_bytes(16u).len() == 16u);
@@ -972,13 +974,13 @@ mod tests {
#[test] #[test]
fn test_choose() { fn test_choose() {
let r = rng(); let mut r = rng();
assert!(r.choose([1, 1, 1]) == 1); assert!(r.choose([1, 1, 1]) == 1);
} }
#[test] #[test]
fn test_choose_option() { fn test_choose_option() {
let r = rng(); let mut r = rng();
let x: Option<int> = r.choose_option([]); let x: Option<int> = r.choose_option([]);
assert!(x.is_none()); assert!(x.is_none());
assert!(r.choose_option([1, 1, 1]) == Some(1)); assert!(r.choose_option([1, 1, 1]) == Some(1));
@@ -986,7 +988,7 @@ mod tests {
#[test] #[test]
fn test_choose_weighted() { fn test_choose_weighted() {
let r = rng(); let mut r = rng();
assert!(r.choose_weighted(~[ assert!(r.choose_weighted(~[
Weighted { weight: 1u, item: 42 }, Weighted { weight: 1u, item: 42 },
]) == 42); ]) == 42);
@@ -998,7 +1000,7 @@ mod tests {
#[test] #[test]
fn test_choose_weighted_option() { fn test_choose_weighted_option() {
let r = rng(); let mut r = rng();
assert!(r.choose_weighted_option(~[ assert!(r.choose_weighted_option(~[
Weighted { weight: 1u, item: 42 }, Weighted { weight: 1u, item: 42 },
]) == Some(42)); ]) == Some(42));
@@ -1012,7 +1014,7 @@ mod tests {
#[test] #[test]
fn test_weighted_vec() { fn test_weighted_vec() {
let r = rng(); let mut r = rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert!(r.weighted_vec(~[]) == empty); assert!(r.weighted_vec(~[]) == empty);
assert!(r.weighted_vec(~[ assert!(r.weighted_vec(~[
@@ -1024,7 +1026,7 @@ mod tests {
#[test] #[test]
fn test_shuffle() { fn test_shuffle() {
let r = rng(); let mut r = rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert!(r.shuffle(~[]) == empty); assert!(r.shuffle(~[]) == empty);
assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
@@ -1032,7 +1034,7 @@ mod tests {
#[test] #[test]
fn test_task_rng() { fn test_task_rng() {
let r = task_rng(); let mut r = task_rng();
r.gen::<int>(); r.gen::<int>();
assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
assert!(r.gen_uint_range(0u, 1u) == 0u); assert!(r.gen_uint_range(0u, 1u) == 0u);
@@ -1079,7 +1081,7 @@ mod tests {
let rt_rng = do vec::as_imm_buf(seed) |p, sz| { let rt_rng = do vec::as_imm_buf(seed) |p, sz| {
rustrt::rand_new_seeded(p, sz as size_t) rustrt::rand_new_seeded(p, sz as size_t)
}; };
let rng = IsaacRng::new_seeded(seed); let mut rng = IsaacRng::new_seeded(seed);
for 10000.times { for 10000.times {
assert_eq!(rng.next(), rustrt::rand_next(rt_rng)); assert_eq!(rng.next(), rustrt::rand_next(rt_rng));

View File

@@ -597,12 +597,13 @@ pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_cant_dup_task_builder() { fn test_cant_dup_task_builder() {
let b = task().unlinked(); let mut builder = task();
do b.spawn { } builder.unlinked();
do builder.spawn {}
// FIXME(#3724): For now, this is a -runtime- failure, because we haven't // FIXME(#3724): For now, this is a -runtime- failure, because we haven't
// got move mode on self. When 3724 is fixed, this test should fail to // got move mode on self. When 3724 is fixed, this test should fail to
// compile instead, and should go in tests/compile-fail. // compile instead, and should go in tests/compile-fail.
do b.spawn { } // b should have been consumed by the previous call do builder.spawn {} // b should have been consumed by the previous call
} }
// The following 8 tests test the following 2^3 combinations: // The following 8 tests test the following 2^3 combinations:
@@ -645,43 +646,31 @@ fn test_spawn_unlinked_sup_fail_down() {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_sup_fail_up() { // child fails; parent fails fn test_spawn_linked_sup_fail_up() { // child fails; parent fails
let (po, _ch) = stream::<()>(); let (po, _ch) = stream::<()>();
// Unidirectional "parenting" shouldn't override bidirectional linked. // Unidirectional "parenting" shouldn't override bidirectional linked.
// We have to cheat with opts - the interface doesn't support them because // We have to cheat with opts - the interface doesn't support them because
// they don't make sense (redundant with task().supervised()). // they don't make sense (redundant with task().supervised()).
let opts = { let mut b0 = task();
let mut opts = default_task_opts(); b0.opts.linked = true;
opts.linked = true; b0.opts.supervised = true;
opts.supervised = true;
opts
};
let b0 = task(); do b0.spawn {
let b1 = TaskBuilder { fail!();
opts: opts, }
can_not_copy: None,
.. b0
};
do b1.spawn { fail!(); }
po.recv(); // We should get punted awake po.recv(); // We should get punted awake
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_sup_fail_down() { // parent fails; child fails fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
// We have to cheat with opts - the interface doesn't support them because // We have to cheat with opts - the interface doesn't support them because
// they don't make sense (redundant with task().supervised()). // they don't make sense (redundant with task().supervised()).
let opts = { let mut b0 = task();
let mut opts = default_task_opts(); b0.opts.linked = true;
opts.linked = true; b0.opts.supervised = true;
opts.supervised = true; do b0.spawn {
opts loop {
}; task::yield();
}
let b0 = task(); }
let b1 = TaskBuilder {
opts: opts,
can_not_copy: None,
.. b0
};
do b1.spawn { loop { task::yield(); } }
fail!(); // *both* mechanisms would be wrong if this didn't kill the child fail!(); // *both* mechanisms would be wrong if this didn't kill the child
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
@@ -700,7 +689,13 @@ fn test_spawn_linked_unsup_fail_down() { // parent fails; child fails
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_spawn_linked_unsup_default_opts() { // parent fails; child fails fn test_spawn_linked_unsup_default_opts() { // parent fails; child fails
// Make sure the above test is the same as this one. // Make sure the above test is the same as this one.
do task().linked().spawn { loop { task::yield(); } } let mut builder = task();
builder.linked();
do builder.spawn {
loop {
task::yield();
}
}
fail!(); fail!();
} }
@@ -758,7 +753,8 @@ fn test_spawn_linked_sup_propagate_sibling() {
#[test] #[test]
fn test_run_basic() { fn test_run_basic() {
let (po, ch) = stream::<()>(); let (po, ch) = stream::<()>();
do task().spawn { let mut builder = task();
do builder.spawn {
ch.send(()); ch.send(());
} }
po.recv(); po.recv();
@@ -772,18 +768,18 @@ struct Wrapper {
#[test] #[test]
fn test_add_wrapper() { fn test_add_wrapper() {
let (po, ch) = stream::<()>(); let (po, ch) = stream::<()>();
let b0 = task(); let mut b0 = task();
let ch = Wrapper { f: Some(ch) }; let ch = Cell(ch);
let b1 = do b0.add_wrapper |body| { do b0.add_wrapper |body| {
let ch = Wrapper { f: Some(ch.f.swap_unwrap()) }; let ch = Cell(ch.take());
let result: ~fn() = || { let result: ~fn() = || {
let ch = ch.f.swap_unwrap(); let mut ch = ch.take();
body(); body();
ch.send(()); ch.send(());
}; };
result result
}; };
do b1.spawn { } do b0.spawn { }
po.recv(); po.recv();
} }
@@ -791,12 +787,16 @@ fn test_add_wrapper() {
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_future_result() { fn test_future_result() {
let mut result = None; let mut result = None;
do task().future_result(|r| { result = Some(r); }).spawn { } let mut builder = task();
builder.future_result(|r| result = Some(r));
do builder.spawn {}
assert!(result.unwrap().recv() == Success); assert!(result.unwrap().recv() == Success);
result = None; result = None;
do task().future_result(|r| let mut builder = task();
{ result = Some(r); }).unlinked().spawn { builder.future_result(|r| result = Some(r));
builder.unlinked();
do builder.spawn {
fail!(); fail!();
} }
assert!(result.unwrap().recv() == Failure); assert!(result.unwrap().recv() == Failure);
@@ -804,7 +804,9 @@ fn test_future_result() {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_back_to_the_future_result() { fn test_back_to_the_future_result() {
let _ = task().future_result(util::ignore).future_result(util::ignore); let mut builder = task();
builder.future_result(util::ignore);
builder.future_result(util::ignore);
} }
#[test] #[test]
@@ -866,12 +868,12 @@ fn test_spawn_sched_childs_on_default_sched() {
// Assuming tests run on the default scheduler // Assuming tests run on the default scheduler
let default_id = unsafe { rt::rust_get_sched_id() }; let default_id = unsafe { rt::rust_get_sched_id() };
let ch = Wrapper { f: Some(ch) }; let ch = Cell(ch);
do spawn_sched(SingleThreaded) { do spawn_sched(SingleThreaded) {
let parent_sched_id = unsafe { rt::rust_get_sched_id() }; let parent_sched_id = unsafe { rt::rust_get_sched_id() };
let ch = Wrapper { f: Some(ch.f.swap_unwrap()) }; let ch = Cell(ch.take());
do spawn { do spawn {
let ch = ch.f.swap_unwrap(); let ch = ch.take();
let child_sched_id = unsafe { rt::rust_get_sched_id() }; let child_sched_id = unsafe { rt::rust_get_sched_id() };
assert!(parent_sched_id != child_sched_id); assert!(parent_sched_id != child_sched_id);
assert!(child_sched_id == default_id); assert!(child_sched_id == default_id);
@@ -979,7 +981,8 @@ fn test_avoid_copying_the_body_spawn() {
#[test] #[test]
fn test_avoid_copying_the_body_task_spawn() { fn test_avoid_copying_the_body_task_spawn() {
do avoid_copying_the_body |f| { do avoid_copying_the_body |f| {
do task().spawn || { let mut builder = task();
do builder.spawn || {
f(); f();
} }
} }
@@ -1006,7 +1009,9 @@ fn test_avoid_copying_the_body_unlinked() {
#[test] #[test]
fn test_platform_thread() { fn test_platform_thread() {
let (po, ch) = stream(); let (po, ch) = stream();
do task().sched_mode(PlatformThread).spawn { let mut builder = task();
builder.sched_mode(PlatformThread);
do builder.spawn {
ch.send(()); ch.send(());
} }
po.recv(); po.recv();

View File

@@ -191,12 +191,14 @@ fn test_select_stream_and_oneshot() {
use comm::select2i; use comm::select2i;
use either::{Left, Right}; use either::{Left, Right};
let (port, chan) = stream(); let mut (port, chan) = stream();
let port = Cell(port);
let (waitport, waitchan) = stream(); let (waitport, waitchan) = stream();
do spawn { do spawn {
unsafe { unsafe {
do weaken_task |signal| { do weaken_task |mut signal| {
match select2i(&port, &signal) { let mut port = port.take();
match select2i(&mut port, &mut signal) {
Left(*) => (), Left(*) => (),
Right(*) => fail!() Right(*) => fail!()
} }

View File

@@ -1237,7 +1237,7 @@ fn test_simplification() {
let ext_cx = mk_ctxt(); let ext_cx = mk_ctxt();
let item_in = ast::ii_item(quote_item!( let item_in = ast::ii_item(quote_item!(
fn new_int_alist<B:Copy>() -> alist<int, B> { fn new_int_alist<B:Copy>() -> alist<int, B> {
fn eq_int(&&a: int, &&b: int) -> bool { a == b } fn eq_int(a: int, b: int) -> bool { a == b }
return alist {eq_fn: eq_int, data: ~[]}; return alist {eq_fn: eq_int, data: ~[]};
} }
).get()); ).get());

View File

@@ -673,7 +673,9 @@ mod tests {
let mut children = ~[]; let mut children = ~[];
for 5.times { for 5.times {
let arc3 = (*arc).clone(); let arc3 = (*arc).clone();
do task::task().future_result(|r| children.push(r)).spawn { let mut builder = task::task();
builder.future_result(|r| children.push(r));
do builder.spawn {
do arc3.read |num| { do arc3.read |num| {
assert!(*num >= 0); assert!(*num >= 0);
} }
@@ -681,11 +683,15 @@ mod tests {
} }
// Wait for children to pass their asserts // Wait for children to pass their asserts
for vec::each(children) |r| { r.recv(); } for vec::each(children) |r| {
r.recv();
}
// Wait for writer to finish // Wait for writer to finish
p.recv(); p.recv();
do arc.read |num| { assert!(*num == 10); } do arc.read |num| {
assert!(*num == 10);
}
} }
#[test] #[test]
fn test_rw_downgrade() { fn test_rw_downgrade() {

View File

@@ -1426,7 +1426,7 @@ mod tests {
#[bench] #[bench]
fn bench_uint_small(b: &mut BenchHarness) { fn bench_uint_small(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = 0 as uint; let mut bitv = 0 as uint;
do b.iter { do b.iter {
bitv |= (1 << ((r.next() as uint) % uint::bits)); bitv |= (1 << ((r.next() as uint) % uint::bits));
@@ -1435,7 +1435,7 @@ mod tests {
#[bench] #[bench]
fn bench_small_bitv_small(b: &mut BenchHarness) { fn bench_small_bitv_small(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = SmallBitv::new(uint::bits); let mut bitv = SmallBitv::new(uint::bits);
do b.iter { do b.iter {
bitv.set((r.next() as uint) % uint::bits, true); bitv.set((r.next() as uint) % uint::bits, true);
@@ -1444,7 +1444,7 @@ mod tests {
#[bench] #[bench]
fn bench_big_bitv_small(b: &mut BenchHarness) { fn bench_big_bitv_small(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = BigBitv::new(~[0]); let mut bitv = BigBitv::new(~[0]);
do b.iter { do b.iter {
bitv.set((r.next() as uint) % uint::bits, true); bitv.set((r.next() as uint) % uint::bits, true);
@@ -1453,7 +1453,7 @@ mod tests {
#[bench] #[bench]
fn bench_big_bitv_big(b: &mut BenchHarness) { fn bench_big_bitv_big(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut storage = ~[]; let mut storage = ~[];
storage.grow(bench_bits / uint::bits, &0); storage.grow(bench_bits / uint::bits, &0);
let mut bitv = BigBitv::new(storage); let mut bitv = BigBitv::new(storage);
@@ -1464,7 +1464,7 @@ mod tests {
#[bench] #[bench]
fn bench_bitv_big(b: &mut BenchHarness) { fn bench_bitv_big(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = Bitv::new(bench_bits, false); let mut bitv = Bitv::new(bench_bits, false);
do b.iter { do b.iter {
bitv.set((r.next() as uint) % bench_bits, true); bitv.set((r.next() as uint) % bench_bits, true);
@@ -1473,7 +1473,7 @@ mod tests {
#[bench] #[bench]
fn bench_bitv_small(b: &mut BenchHarness) { fn bench_bitv_small(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = Bitv::new(uint::bits, false); let mut bitv = Bitv::new(uint::bits, false);
do b.iter { do b.iter {
bitv.set((r.next() as uint) % uint::bits, true); bitv.set((r.next() as uint) % uint::bits, true);
@@ -1482,7 +1482,7 @@ mod tests {
#[bench] #[bench]
fn bench_bitv_set_small(b: &mut BenchHarness) { fn bench_bitv_set_small(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = BitvSet::new(); let mut bitv = BitvSet::new();
do b.iter { do b.iter {
bitv.insert((r.next() as uint) % uint::bits); bitv.insert((r.next() as uint) % uint::bits);
@@ -1491,7 +1491,7 @@ mod tests {
#[bench] #[bench]
fn bench_bitv_set_big(b: &mut BenchHarness) { fn bench_bitv_set_big(b: &mut BenchHarness) {
let r = rng(); let mut r = rng();
let mut bitv = BitvSet::new(); let mut bitv = BitvSet::new();
do b.iter { do b.iter {
bitv.insert((r.next() as uint) % bench_bits); bitv.insert((r.next() as uint) % bench_bits);

View File

@@ -645,7 +645,7 @@ mod test {
chan.send(10); chan.send(10);
let bytes = copy chan.byte_chan.writer.bytes; let bytes = copy *chan.byte_chan.writer.bytes;
let reader = BufReader::new(bytes); let reader = BufReader::new(bytes);
let port = serial::reader_port(reader); let port = serial::reader_port(reader);
@@ -692,7 +692,7 @@ mod test {
chan.send(10); chan.send(10);
let bytes = copy chan.byte_chan.writer.bytes; let bytes = copy *chan.byte_chan.writer.bytes;
let reader = BufReader::new(bytes); let reader = BufReader::new(bytes);
let port = pod::reader_port(reader); let port = pod::reader_port(reader);

View File

@@ -184,9 +184,9 @@ pub fn spawn<A:Owned>(blk: ~fn() -> A) -> Future<A> {
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use future::*; use future::*;
use core::cell::Cell;
use core::comm::{oneshot, send_one}; use core::comm::{oneshot, send_one};
use core::task; use core::task;
@@ -239,8 +239,9 @@ mod test {
#[test] #[test]
fn test_sendable_future() { fn test_sendable_future() {
let expected = ~"schlorf"; let expected = ~"schlorf";
let mut f = do spawn { copy expected }; let f = Cell(do spawn { copy expected });
do task::spawn || { do task::spawn {
let mut f = f.take();
let actual = f.get(); let actual = f.get();
assert!(actual == expected); assert!(actual == expected);
} }

View File

@@ -1963,7 +1963,7 @@ mod test {
} }
fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) { fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) {
let write_result_future = sock.write_future(val); let mut write_result_future = sock.write_future(val);
let write_result = write_result_future.get(); let write_result = write_result_future.get();
if result::is_err(&write_result) { if result::is_err(&write_result) {
debug!("tcp_write_single: write failed!"); debug!("tcp_write_single: write failed!");

View File

@@ -946,8 +946,10 @@ mod test_tim_sort {
impl Ord for CVal { impl Ord for CVal {
fn lt(&self, other: &CVal) -> bool { fn lt(&self, other: &CVal) -> bool {
let rng = rand::rng(); let mut rng = rand::rng();
if rng.gen::<float>() > 0.995 { fail!(~"It's happening!!!"); } if rng.gen::<float>() > 0.995 {
fail!(~"It's happening!!!");
}
(*self).val < other.val (*self).val < other.val
} }
fn le(&self, other: &CVal) -> bool { (*self).val <= other.val } fn le(&self, other: &CVal) -> bool { (*self).val <= other.val }
@@ -995,7 +997,7 @@ mod test_tim_sort {
#[should_fail] #[should_fail]
#[cfg(unix)] #[cfg(unix)]
fn crash_test() { fn crash_test() {
let rng = rand::rng(); let mut rng = rand::rng();
let mut arr = do vec::from_fn(1000) |_i| { let mut arr = do vec::from_fn(1000) |_i| {
CVal { val: rng.gen() } CVal { val: rng.gen() }
}; };
@@ -1015,7 +1017,7 @@ mod test_tim_sort {
#[test] #[test]
fn test_bad_Ord_impl() { fn test_bad_Ord_impl() {
let rng = rand::rng(); let mut rng = rand::rng();
let mut arr = do vec::from_fn(500) |_i| { let mut arr = do vec::from_fn(500) |_i| {
DVal { val: rng.gen() } DVal { val: rng.gen() }
}; };
@@ -1067,7 +1069,7 @@ mod big_tests {
} }
} }
let rng = rand::rng(); let mut rng = rand::rng();
for uint::range(lo, hi) |i| { for uint::range(lo, hi) |i| {
let n = 1 << i; let n = 1 << i;
@@ -1138,7 +1140,7 @@ mod big_tests {
} }
} }
let rng = rand::rng(); let mut rng = rand::rng();
for uint::range(lo, hi) |i| { for uint::range(lo, hi) |i| {
let n = 1 << i; let n = 1 << i;

View File

@@ -219,7 +219,7 @@ mod test {
let hl_loop_clone = hl_loop.clone(); let hl_loop_clone = hl_loop.clone();
do task::spawn { do task::spawn {
use core::rand::*; use core::rand::*;
let rng = rng(); let mut rng = rng();
for old_iter::repeat(times) { for old_iter::repeat(times) {
sleep(&hl_loop_clone, rng.next() as uint % maxms); sleep(&hl_loop_clone, rng.next() as uint % maxms);
} }
@@ -276,7 +276,8 @@ mod test {
let hl_loop = uv::global_loop::get(); let hl_loop = uv::global_loop::get();
for old_iter::repeat(times as uint) { for old_iter::repeat(times as uint) {
let expected = rand::rng().gen_str(16u); let mut rng = rand::rng();
let expected = rng.gen_str(16u);
let (test_po, test_ch) = stream::<~str>(); let (test_po, test_ch) = stream::<~str>();
let hl_loop_clone = hl_loop.clone(); let hl_loop_clone = hl_loop.clone();
do task::spawn() { do task::spawn() {

View File

@@ -848,7 +848,7 @@ mod test_treemap {
check_equal(ctrl, &map); check_equal(ctrl, &map);
assert!(map.find(&5).is_none()); assert!(map.find(&5).is_none());
let rng = rand::IsaacRng::new_seeded(&[42]); let mut rng = rand::IsaacRng::new_seeded(&[42]);
for 3.times { for 3.times {
for 90.times { for 90.times {