test: Fix a bunch of test cases. rs=burning

This commit is contained in:
Patrick Walton 2012-12-05 11:40:47 -08:00
parent b8cfd5c414
commit 3440482d8d
16 changed files with 33 additions and 27 deletions

View file

@ -1123,7 +1123,7 @@ mod tests {
log(debug, tmpfile); log(debug, tmpfile);
let frood: ~str = let frood: ~str =
~"A hoopy frood who really knows where his towel is."; ~"A hoopy frood who really knows where his towel is.";
log(debug, frood); log(debug, copy frood);
{ {
let out: io::Writer = let out: io::Writer =
result::get( result::get(
@ -1132,7 +1132,7 @@ mod tests {
} }
let inp: io::Reader = result::get(&io::file_reader(tmpfile)); let inp: io::Reader = result::get(&io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str(); let frood2: ~str = inp.read_c_str();
log(debug, frood2); log(debug, copy frood2);
assert frood == frood2; assert frood == frood2;
} }

View file

@ -946,7 +946,7 @@ mod tests {
while i < 100 { s += ~"aaaaaaaaaa"; i += 1; } while i < 100 { s += ~"aaaaaaaaaa"; i += 1; }
let n = make_rand_name(); let n = make_rand_name();
setenv(n, s); setenv(n, s);
log(debug, s); log(debug, copy s);
assert getenv(n) == option::Some(move s); assert getenv(n) == option::Some(move s);
} }
@ -955,7 +955,7 @@ mod tests {
let path = os::self_exe_path(); let path = os::self_exe_path();
assert path.is_some(); assert path.is_some();
let path = path.get(); let path = path.get();
log(debug, path); log(debug, copy path);
// Hard to test this function // Hard to test this function
assert path.is_absolute; assert path.is_absolute;

View file

@ -440,8 +440,8 @@ mod tests {
readclose(pipe_err.in); readclose(pipe_err.in);
os::waitpid(pid); os::waitpid(pid);
log(debug, expected); log(debug, copy expected);
log(debug, actual); log(debug, copy actual);
assert (expected == actual); assert (expected == actual);
} }

View file

@ -1,6 +1,6 @@
fn main() { fn main() {
let x = ~{mut a: ~10, b: ~20}; let x = ~{mut a: ~10, b: ~20};
match x { match x {
~{a, b} => { assert *a == 10; (*x).a = ~30; assert *a == 30; } ~{ref a, ref b} => { assert **a == 10; (*x).a = ~30; assert **a == 30; }
} }
} }

View file

@ -6,8 +6,8 @@ fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(*x); } }
fn main() { fn main() {
let v = ~[1, 2, 3, 4, 5]; let v = ~[1, 2, 3, 4, 5];
let mut sum = 0; let mut sum = 0;
iter_vec(v, |i| { iter_vec(copy v, |i| {
iter_vec(v, |j| { iter_vec(copy v, |j| {
log(error, i * j); log(error, i * j);
sum += i * j; sum += i * j;
}); });

View file

@ -5,6 +5,6 @@ fn main() {
vec::map2(~[1, 2, 3, 4, 5], vec::map2(~[1, 2, 3, 4, 5],
~[true, false, false, true, true], ~[true, false, false, true, true],
|i, b| if *b { -(*i) } else { *i } ); |i, b| if *b { -(*i) } else { *i } );
log(error, v); log(error, copy v);
assert (v == ~[-1, 2, 3, -4, -5]); assert (v == ~[-1, 2, 3, -4, -5]);
} }

View file

@ -76,8 +76,8 @@ fn annoy_neighbors<T: noisy>(critter: T) {
fn main() { fn main() {
let nyan : cat = cat(0u, 2, ~"nyan"); let nyan : cat = cat(0u, 2, ~"nyan");
let whitefang : dog = dog(); let whitefang : dog = dog();
annoy_neighbors(nyan as noisy); annoy_neighbors((copy nyan) as noisy);
annoy_neighbors(whitefang as noisy); annoy_neighbors((copy whitefang) as noisy);
assert(nyan.meow_count() == 10u); assert(nyan.meow_count() == 10u);
assert(*whitefang.volume == 1); assert(*whitefang.volume == 1);
} }

View file

@ -44,7 +44,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat { cat {
meows: in_x, meows: in_x,
how_hungry: in_y, how_hungry: in_y,
name: in_name name: copy in_name
} }
} }

View file

@ -60,7 +60,7 @@ fn main() {
assert x.quux() == 10; assert x.quux() == 10;
let y = ~thing({mut a: @10}); let y = ~thing({mut a: @10});
assert y.bar() == 10; assert (copy y).bar() == 10;
assert y.quux() == 10; assert y.quux() == 10;
let z = thing({mut a: @11}); let z = thing({mut a: @11});

View file

@ -4,7 +4,10 @@
type compare<T> = fn@(~T, ~T) -> bool; type compare<T> = fn@(~T, ~T) -> bool;
fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) { fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = match true { true => { expected }, _ => fail ~"wat" }; let actual: ~T = match true {
true => { copy expected },
_ => fail ~"wat"
};
assert (eq(expected, actual)); assert (eq(expected, actual));
} }

View file

@ -6,7 +6,10 @@
type compare<T> = fn@(T, T) -> bool; type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) { fn test_generic<T: Copy>(expected: T, eq: compare<T>) {
let actual: T = match true { true => expected, _ => fail ~"wat" }; let actual: T = match true {
true => copy expected,
_ => fail ~"wat"
};
assert (eq(expected, actual)); assert (eq(expected, actual));
} }

View file

@ -4,7 +4,7 @@
type compare<T> = fn@(~T, ~T) -> bool; type compare<T> = fn@(~T, ~T) -> bool;
fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) { fn test_generic<T: Copy>(expected: ~T, eq: compare<T>) {
let actual: ~T = { expected }; let actual: ~T = { copy expected };
assert (eq(expected, actual)); assert (eq(expected, actual));
} }

View file

@ -4,7 +4,7 @@ fn id<T: Copy Send>(t: T) -> T { return t; }
fn main() { fn main() {
let expected = ~100; let expected = ~100;
let actual = id::<~int>(expected); let actual = id::<~int>(copy expected);
log(debug, *actual); log(debug, *actual);
assert (*expected == *actual); assert (*expected == *actual);
} }

View file

@ -42,7 +42,7 @@ mod map_reduce {
fn emit(im: map::HashMap<~str, int>, ctrl: Chan<ctrl_proto>, key: ~str, fn emit(im: map::HashMap<~str, int>, ctrl: Chan<ctrl_proto>, key: ~str,
val: ~str) { val: ~str) {
let mut c; let mut c;
match im.find(key) { match im.find(copy key) {
Some(_c) => { c = _c } Some(_c) => { c = _c }
None => { None => {
let p = Port(); let p = Port();
@ -70,7 +70,7 @@ mod map_reduce {
reducers = map::HashMap(); reducers = map::HashMap();
start_mappers(Chan(&ctrl), inputs); start_mappers(Chan(&ctrl), copy inputs);
let mut num_mappers = vec::len(inputs) as int; let mut num_mappers = vec::len(inputs) as int;

View file

@ -207,8 +207,8 @@ mod pingpong {
enum pong = pipes::send_packet<ping>; enum pong = pipes::send_packet<ping>;
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe { fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
let addr : *pipes::send_packet<pong> = match p { let addr : *pipes::send_packet<pong> = match &p {
ping(x) => { cast::transmute(ptr::addr_of(&x)) } &ping(x) => { cast::transmute(ptr::addr_of(&x)) }
}; };
let liberated_value = move *addr; let liberated_value = move *addr;
cast::forget(move p); cast::forget(move p);
@ -216,8 +216,8 @@ mod pingpong {
} }
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe { fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
let addr : *pipes::send_packet<ping> = match p { let addr : *pipes::send_packet<ping> = match &p {
pong(x) => { cast::transmute(ptr::addr_of(&x)) } &pong(x) => { cast::transmute(ptr::addr_of(&x)) }
}; };
let liberated_value = move *addr; let liberated_value = move *addr;
cast::forget(move p); cast::forget(move p);

View file

@ -31,9 +31,9 @@ fn lookup(table: ~json::Object, key: ~str, default: ~str) -> ~str
fn add_interface(store: int, managed_ip: ~str, data: std::json::Json) -> (~str, object) fn add_interface(store: int, managed_ip: ~str, data: std::json::Json) -> (~str, object)
{ {
match data match &data
{ {
std::json::Object(interface) => &std::json::Object(interface) =>
{ {
let name = lookup(interface, ~"ifDescr", ~""); let name = lookup(interface, ~"ifDescr", ~"");
let label = fmt!("%s-%s", managed_ip, name); let label = fmt!("%s-%s", managed_ip, name);