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

@@ -673,7 +673,9 @@ mod tests {
let mut children = ~[];
for 5.times {
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| {
assert!(*num >= 0);
}
@@ -681,11 +683,15 @@ mod tests {
}
// 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
p.recv();
do arc.read |num| { assert!(*num == 10); }
do arc.read |num| {
assert!(*num == 10);
}
}
#[test]
fn test_rw_downgrade() {

View File

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

View File

@@ -645,7 +645,7 @@ mod test {
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 port = serial::reader_port(reader);
@@ -692,7 +692,7 @@ mod test {
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 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)]
#[cfg(test)]
mod test {
use future::*;
use core::cell::Cell;
use core::comm::{oneshot, send_one};
use core::task;
@@ -239,8 +239,9 @@ mod test {
#[test]
fn test_sendable_future() {
let expected = ~"schlorf";
let mut f = do spawn { copy expected };
do task::spawn || {
let f = Cell(do spawn { copy expected });
do task::spawn {
let mut f = f.take();
let actual = f.get();
assert!(actual == expected);
}

View File

@@ -1963,7 +1963,7 @@ mod test {
}
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();
if result::is_err(&write_result) {
debug!("tcp_write_single: write failed!");

View File

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

View File

@@ -219,7 +219,7 @@ mod test {
let hl_loop_clone = hl_loop.clone();
do task::spawn {
use core::rand::*;
let rng = rng();
let mut rng = rng();
for old_iter::repeat(times) {
sleep(&hl_loop_clone, rng.next() as uint % maxms);
}
@@ -276,7 +276,8 @@ mod test {
let hl_loop = uv::global_loop::get();
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 hl_loop_clone = hl_loop.clone();
do task::spawn() {

View File

@@ -848,7 +848,7 @@ mod test_treemap {
check_equal(ctrl, &map);
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 90.times {