Skip to content

Commit

Permalink
test: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Mar 8, 2013
1 parent 9a17ef9 commit d661711
Show file tree
Hide file tree
Showing 104 changed files with 397 additions and 272 deletions.
8 changes: 8 additions & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Implicitly, all crates behave as if they included the following prologue:
#[deny(non_camel_case_types)];
#[allow(deprecated_mutable_fields)];

// On Linux, link to the runtime with -lrt.
#[cfg(target_os = "linux")]
pub mod linkhack {
#[link_args="-lrustrt -lrt"]
extern {
}
}

/* The Prelude. */

pub mod prelude;
Expand Down
15 changes: 10 additions & 5 deletions src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,22 @@ fn test_parse_bytes() {
fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
fail_unless!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) == Some(65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
Some(65535 as i32));
fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
fail_unless!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
fail_unless!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
fail_unless!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
fail_unless!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
fail_unless!(i32::parse_bytes(to_bytes(~"-123"), 16u) == Some(-291 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) == Some(-65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == Some(-65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
Some(-291 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
Some(-65535 as i32));
fail_unless!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
Some(-65535 as i32));
fail_unless!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
fail_unless!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/num/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ pub fn test_parse_bytes() {
fail_unless!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
fail_unless!(u16::parse_bytes(to_bytes(~"123"), 16u) == Some(291u as u16));
fail_unless!(u16::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535u as u16));
fail_unless!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
Some(291u as u16));
fail_unless!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535u as u16));
fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
fail_unless!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ pub fn waitpid(pid: pid_t) -> c_int {
use libc::funcs::posix01::wait::*;
let mut status = 0 as c_int;

fail_unless!((waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int)));
fail_unless!((waitpid(pid, &mut status, 0 as c_int) !=
(-1 as c_int)));
return status;
}
}
Expand Down Expand Up @@ -1309,7 +1310,8 @@ mod tests {
#[test]
fn path_exists() {
fail_unless!((os::path_exists(&Path("."))));
fail_unless!((!os::path_exists(&Path("test/nonexistent-bogus-path"))));
fail_unless!((!os::path_exists(&Path(
"test/nonexistent-bogus-path"))));
}
#[test]
Expand Down
15 changes: 10 additions & 5 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ pub fn test() {
fail_unless!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
copy_memory(vec::raw::to_mut_ptr(v1),
offset(vec::raw::to_ptr(v0), 2u), 1u);
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16));
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
v1[2] == 0u16));
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u),
vec::raw::to_ptr(v0), 1u);
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16));
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
v1[2] == 32000u16));
}
}

Expand All @@ -342,9 +344,12 @@ pub fn test_position() {

let s = ~"hello";
unsafe {
fail_unless!(2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char)));
fail_unless!(4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char)));
fail_unless!(5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char)));
fail_unless!(2u == as_c_str(s, |p| position(p,
|c| *c == 'l' as c_char)));
fail_unless!(4u == as_c_str(s, |p| position(p,
|c| *c == 'o' as c_char)));
fail_unless!(5u == as_c_str(s, |p| position(p,
|c| *c == 0 as c_char)));
}
}

Expand Down
29 changes: 19 additions & 10 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2807,9 +2807,10 @@ mod tests {
#[test]
fn test_to_lower() {
unsafe {
fail_unless!(~"" == map(~"", |c| libc::tolower(c as c_char) as char));
fail_unless!(~"" == map(~"",
|c| libc::tolower(c as c_char) as char));
fail_unless!(~"ymca" == map(~"YMCA",
|c| libc::tolower(c as c_char) as char));
|c| libc::tolower(c as c_char) as char));
}
}
Expand Down Expand Up @@ -2867,7 +2868,8 @@ mod tests {
fail_unless!(replace(~"a", a, ~"b") == ~"b");
fail_unless!(replace(~"ab", a, ~"b") == ~"bb");
let test = ~"test";
fail_unless!(replace(~" test test ", test, ~"toast") == ~" toast toast ");
fail_unless!(replace(~" test test ", test, ~"toast") ==
~" toast toast ");
fail_unless!(replace(~" test test ", test, ~"") == ~" ");
}
Expand Down Expand Up @@ -2977,18 +2979,24 @@ mod tests {
#[test]
fn test_trim_left_chars() {
fail_unless!(trim_left_chars(~" *** foo *** ", ~[]) == ~" *** foo *** ");
fail_unless!(trim_left_chars(~" *** foo *** ", ~['*', ' ']) == ~"foo *** ");
fail_unless!(trim_left_chars(~" *** foo *** ", ~[]) ==
~" *** foo *** ");
fail_unless!(trim_left_chars(~" *** foo *** ", ~['*', ' ']) ==
~"foo *** ");
fail_unless!(trim_left_chars(~" *** *** ", ~['*', ' ']) == ~"");
fail_unless!(trim_left_chars(~"foo *** ", ~['*', ' ']) == ~"foo *** ");
fail_unless!(trim_left_chars(~"foo *** ", ~['*', ' ']) ==
~"foo *** ");
}
#[test]
fn test_trim_right_chars() {
fail_unless!(trim_right_chars(~" *** foo *** ", ~[]) == ~" *** foo *** ");
fail_unless!(trim_right_chars(~" *** foo *** ", ~['*', ' ']) == ~" *** foo");
fail_unless!(trim_right_chars(~" *** foo *** ", ~[]) ==
~" *** foo *** ");
fail_unless!(trim_right_chars(~" *** foo *** ", ~['*', ' ']) ==
~" *** foo");
fail_unless!(trim_right_chars(~" *** *** ", ~['*', ' ']) == ~"");
fail_unless!(trim_right_chars(~" *** foo", ~['*', ' ']) == ~" *** foo");
fail_unless!(trim_right_chars(~" *** foo", ~['*', ' ']) ==
~" *** foo");
}
#[test]
Expand Down Expand Up @@ -3321,7 +3329,8 @@ mod tests {
#[test]
fn test_map() {
unsafe {
fail_unless!(~"" == map(~"", |c| libc::toupper(c as c_char) as char));
fail_unless!(~"" == map(~"", |c|
libc::toupper(c as c_char) as char));
fail_unless!(~"YMCA" == map(~"ymca",
|c| libc::toupper(c as c_char) as char));
}
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/task/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn test_tls_multitask() {
// TLS shouldn't carry over.
fail_unless!(local_data_get(my_key).is_none());
local_data_set(my_key, @~"child data");
fail_unless!(*(local_data_get(my_key).get()) == ~"child data");
fail_unless!(*(local_data_get(my_key).get()) ==
~"child data");
// should be cleaned up for us
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ fn test_spawn_sched_childs_on_default_sched() {

#[cfg(test)]
pub mod testrt {
use libc;

#[nolink]
pub extern {
unsafe fn rust_dbg_lock_create() -> *libc::c_void;
Expand Down
12 changes: 8 additions & 4 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3409,7 +3409,8 @@ mod tests {
fail_unless!(rsplit(~[], f) == ~[]);
fail_unless!(rsplit(~[1, 2], f) == ~[~[1, 2]]);
fail_unless!(rsplit(~[1, 2, 3], f) == ~[~[1, 2], ~[]]);
fail_unless!(rsplit(~[1, 2, 3, 4, 3, 5], f) == ~[~[1, 2], ~[4], ~[5]]);
fail_unless!(rsplit(~[1, 2, 3, 4, 3, 5], f) ==
~[~[1, 2], ~[4], ~[5]]);
}

#[test]
Expand All @@ -3427,9 +3428,12 @@ mod tests {
fn test_partition() {
// FIXME (#4355 maybe): using v.partition here crashes
fail_unless!(partition(~[], |x: &int| *x < 3) == (~[], ~[]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 4) == (~[1, 2, 3], ~[]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 2) == (~[1], ~[2, 3]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 0) == (~[], ~[1, 2, 3]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 4) ==
(~[1, 2, 3], ~[]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 2) ==
(~[1], ~[2, 3]));
fail_unless!(partition(~[1, 2, 3], |x: &int| *x < 0) ==
(~[], ~[1, 2, 3]));
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ pub fn trans_arg_expr(bcx: block,
// FIXME(#3548) use the adjustments table
match autoref_arg {
DoAutorefArg => {
fail_unless!(!bcx.ccx().maps.moves_map.contains_key(&arg_expr.id));
fail_unless!(!
bcx.ccx().maps.moves_map.contains_key(&arg_expr.id));
val = arg_datum.to_ref_llval(bcx);
}
DontAutorefArg => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/desc_to_brief_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ fn should_promote_desc() {
#[test]
fn should_promote_trait_method_desc() {
let doc = test::mk_doc(~"trait i { #[doc = \"desc\"] fn a(); }");
fail_unless!(doc.cratemod().traits()[0].methods[0].brief == Some(~"desc"));
fail_unless!(doc.cratemod().traits()[0].methods[0].brief ==
Some(~"desc"));
}
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ mod test {
#[test]
pub fn extract_mods_deep() {
let doc = mk_doc(~"mod a { mod b { mod c { } } }");
fail_unless!(doc.cratemod().mods()[0].mods()[0].mods()[0].name() == ~"c");
fail_unless!(doc.cratemod().mods()[0].mods()[0].mods()[0].name() ==
~"c");
}
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/markdown_index_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ fn pandoc_header_id(header: &str) -> ~str {

#[test]
fn should_remove_punctuation_from_headers() {
fail_unless!(pandoc_header_id(~"impl foo of bar<A>") == ~"impl-foo-of-bara");
fail_unless!(pandoc_header_id(~"impl foo of bar<A>") ==
~"impl-foo-of-bara");
fail_unless!(pandoc_header_id(~"impl of num::num for int")
== ~"impl-of-numnum-for-int");
fail_unless!(pandoc_header_id(~"impl of num::num for int/&")
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/markdown_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ fn should_write_impl_header() {
#[test]
fn should_write_impl_header_with_trait() {
let markdown = test::render(~"impl j for int { fn a() { } }");
fail_unless!(str::contains(markdown, ~"## Implementation of `j` for `int`"));
fail_unless!(str::contains(markdown,
~"## Implementation of `j` for `int`"));
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/text_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ fn should_execute_on_trait_method_section_bodies() {
# Header\n\
Body \"]\
fn a(); }");
fail_unless!(doc.cratemod().traits()[0].methods[0].sections[0].body == ~"Body");
fail_unless!(doc.cratemod().traits()[0].methods[0].sections[0].body ==
~"Body");
}
#[test]
Expand All @@ -288,7 +289,8 @@ fn should_execute_on_impl_method_section_bodies() {
# Header\n\
Body \"]\
fn a() { } }");
fail_unless!(doc.cratemod().impls()[0].methods[0].sections[0].body == ~"Body");
fail_unless!(doc.cratemod().impls()[0].methods[0].sections[0].body ==
~"Body");
}
#[cfg(test)]
Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/tystr_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ fn should_add_fn_sig() {
#[test]
fn should_add_foreign_fn_sig() {
let doc = test::mk_doc(~"extern mod a { fn a<T>() -> int; }");
fail_unless!(doc.cratemod().nmods()[0].fns[0].sig == Some(~"fn a<T>() -> int"));
fail_unless!(doc.cratemod().nmods()[0].fns[0].sig ==
Some(~"fn a<T>() -> int"));
}
fn fold_const(
Expand Down Expand Up @@ -165,7 +166,8 @@ fn fold_enum(
#[test]
fn should_add_variant_sigs() {
let doc = test::mk_doc(~"enum a { b(int) }");
fail_unless!(doc.cratemod().enums()[0].variants[0].sig == Some(~"b(int)"));
fail_unless!(doc.cratemod().enums()[0].variants[0].sig ==
Some(~"b(int)"));
}
fn fold_trait(
Expand Down Expand Up @@ -407,7 +409,8 @@ fn strip_struct_extra_stuff(item: @ast::item) -> @ast::item {
#[test]
fn should_add_struct_defs() {
let doc = test::mk_doc(~"struct S { field: () }");
fail_unless!((&doc.cratemod().structs()[0].sig).get().contains("struct S {"));
fail_unless!((&doc.cratemod().structs()[0].sig).get().contains(
"struct S {"));
}
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ mod tests {
let _ = p.recv();
do arc2.access_cond |one, cond| {
cond.signal();
fail_unless!(*one == 0); // Parent should fail when it wakes up.
// Parent should fail when it wakes up.
fail_unless!(*one == 0);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libstd/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,8 @@ mod tests {
#[test]
pub fn test_from_bools() {
fail_unless!(from_bools([true, false, true, true]).to_str() == ~"1011");
fail_unless!(from_bools([true, false, true, true]).to_str() ==
~"1011");
}
#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/md4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ fn test_md4() {
fail_unless!(md4_text(~"") == ~"31d6cfe0d16ae931b73c59d7e0c089c0");
fail_unless!(md4_text(~"a") == ~"bde52cb31de33e46245e05fbdbd6fb24");
fail_unless!(md4_text(~"abc") == ~"a448017aaf21d8525fc10ae87aa6729d");
fail_unless!(md4_text(~"message digest") == ~"d9130a8164549fe818874806e1c7014b");
fail_unless!(md4_text(~"message digest") ==
~"d9130a8164549fe818874806e1c7014b");
fail_unless!(md4_text(~"abcdefghijklmnopqrstuvwxyz") ==
~"d79e1c308aa5bbcdeea8ed63df412da9");
fail_unless!(md4_text(
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,8 @@ mod tests {
fail_unless!(encode_component("") == ~"");
fail_unless!(encode_component("http://example.com") ==
~"http%3A%2F%2Fexample.com");
fail_unless!(encode_component("foo bar% baz") == ~"foo%20bar%25%20baz");
fail_unless!(encode_component("foo bar% baz") ==
~"foo%20bar%25%20baz");
fail_unless!(encode_component(" ") == ~"%20");
fail_unless!(encode_component("!") == ~"%21");
fail_unless!(encode_component("#") == ~"%23");
Expand Down Expand Up @@ -1065,7 +1066,8 @@ mod tests {
let mut m = LinearMap::new();
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
fail_unless!(encode_form_urlencoded(&m) == ~"foo+bar=abc&foo+bar=12+%3D+34");
fail_unless!(encode_form_urlencoded(&m) ==
~"foo+bar=abc&foo+bar=12+%3D+34");
}
#[test]
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ mod tests {

for vec::each(pairs) |p| {
match *p {
(ref a, ref b) => { fail_unless!((*a == b.desc.name.to_str())); }
(ref a, ref b) => {
fail_unless!((*a == b.desc.name.to_str()));
}
}
}
}
Expand Down
Loading

0 comments on commit d661711

Please sign in to comment.