Skip to content

Commit c6fe93d

Browse files
committed
libcore: Fix core test. rs=broken
1 parent 8367589 commit c6fe93d

File tree

3 files changed

+85
-77
lines changed

3 files changed

+85
-77
lines changed

src/libcore/os.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,34 +1233,36 @@ mod tests {
12331233

12341234
#[test]
12351235
fn copy_file_ok() {
1236-
let tempdir = getcwd(); // would like to use $TMPDIR,
1237-
// doesn't seem to work on Linux
1238-
assert (str::len(tempdir.to_str()) > 0u);
1239-
let in = tempdir.push("in.txt");
1240-
let out = tempdir.push("out.txt");
1241-
1242-
/* Write the temp input file */
1243-
let ostream = do as_c_charp(in.to_str()) |fromp| {
1244-
do as_c_charp("w+b") |modebuf| {
1245-
libc::fopen(fromp, modebuf)
1246-
}
1247-
};
1248-
assert (ostream as uint != 0u);
1249-
let s = ~"hello";
1250-
let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]);
1251-
do vec::as_mut_buf(buf) |b, _len| {
1252-
assert (libc::fwrite(b as *c_void, 1u as size_t,
1253-
(str::len(s) + 1u) as size_t, ostream)
1254-
== buf.len() as size_t)};
1255-
assert (libc::fclose(ostream) == (0u as c_int));
1256-
let rs = os::copy_file(&in, &out);
1257-
if (!os::path_exists(&in)) {
1258-
fail (fmt!("%s doesn't exist", in.to_str()));
1259-
}
1260-
assert(rs);
1261-
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
1262-
assert (rslt == 0);
1263-
assert (remove_file(&in));
1264-
assert (remove_file(&out));
1236+
unsafe {
1237+
let tempdir = getcwd(); // would like to use $TMPDIR,
1238+
// doesn't seem to work on Linux
1239+
assert (str::len(tempdir.to_str()) > 0u);
1240+
let in = tempdir.push("in.txt");
1241+
let out = tempdir.push("out.txt");
1242+
1243+
/* Write the temp input file */
1244+
let ostream = do as_c_charp(in.to_str()) |fromp| {
1245+
do as_c_charp("w+b") |modebuf| {
1246+
libc::fopen(fromp, modebuf)
1247+
}
1248+
};
1249+
assert (ostream as uint != 0u);
1250+
let s = ~"hello";
1251+
let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]);
1252+
do vec::as_mut_buf(buf) |b, _len| {
1253+
assert (libc::fwrite(b as *c_void, 1u as size_t,
1254+
(str::len(s) + 1u) as size_t, ostream)
1255+
== buf.len() as size_t)};
1256+
assert (libc::fclose(ostream) == (0u as c_int));
1257+
let rs = os::copy_file(&in, &out);
1258+
if (!os::path_exists(&in)) {
1259+
fail (fmt!("%s doesn't exist", in.to_str()));
1260+
}
1261+
assert(rs);
1262+
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
1263+
assert (rslt == 0);
1264+
assert (remove_file(&in));
1265+
assert (remove_file(&out));
1266+
}
12651267
}
12661268
}

src/libcore/str.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,9 +2674,11 @@ mod tests {
26742674
26752675
#[test]
26762676
fn test_to_lower() {
2677-
assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char);
2678-
assert ~"ymca" == map(~"YMCA",
2679-
|c| libc::tolower(c as c_char) as char);
2677+
unsafe {
2678+
assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char);
2679+
assert ~"ymca" == map(~"YMCA",
2680+
|c| libc::tolower(c as c_char) as char);
2681+
}
26802682
}
26812683

26822684
#[test]
@@ -3192,9 +3194,11 @@ mod tests {
31923194

31933195
#[test]
31943196
fn test_map() {
3195-
assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char);
3196-
assert ~"YMCA" == map(~"ymca",
3197-
|c| libc::toupper(c as c_char) as char);
3197+
unsafe {
3198+
assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char);
3199+
assert ~"YMCA" == map(~"ymca",
3200+
|c| libc::toupper(c as c_char) as char);
3201+
}
31983202
}
31993203
32003204
#[test]

src/libcore/task/mod.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -957,59 +957,61 @@ extern mod testrt {
957957

958958
#[test]
959959
fn test_spawn_sched_blocking() {
960+
unsafe {
960961

961-
// Testing that a task in one scheduler can block in foreign code
962-
// without affecting other schedulers
963-
for iter::repeat(20u) {
962+
// Testing that a task in one scheduler can block in foreign code
963+
// without affecting other schedulers
964+
for iter::repeat(20u) {
964965

965-
let start_po = oldcomm::Port();
966-
let start_ch = oldcomm::Chan(&start_po);
967-
let fin_po = oldcomm::Port();
968-
let fin_ch = oldcomm::Chan(&fin_po);
966+
let start_po = oldcomm::Port();
967+
let start_ch = oldcomm::Chan(&start_po);
968+
let fin_po = oldcomm::Port();
969+
let fin_ch = oldcomm::Chan(&fin_po);
969970

970-
let lock = testrt::rust_dbg_lock_create();
971+
let lock = testrt::rust_dbg_lock_create();
971972

972-
do spawn_sched(SingleThreaded) {
973-
testrt::rust_dbg_lock_lock(lock);
973+
do spawn_sched(SingleThreaded) {
974+
testrt::rust_dbg_lock_lock(lock);
974975

975-
oldcomm::send(start_ch, ());
976+
oldcomm::send(start_ch, ());
976977

977-
// Block the scheduler thread
978-
testrt::rust_dbg_lock_wait(lock);
979-
testrt::rust_dbg_lock_unlock(lock);
978+
// Block the scheduler thread
979+
testrt::rust_dbg_lock_wait(lock);
980+
testrt::rust_dbg_lock_unlock(lock);
980981

981-
oldcomm::send(fin_ch, ());
982-
};
982+
oldcomm::send(fin_ch, ());
983+
};
983984

984-
// Wait until the other task has its lock
985-
oldcomm::recv(start_po);
985+
// Wait until the other task has its lock
986+
oldcomm::recv(start_po);
986987

987-
fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
988-
let mut val = 20;
989-
while val > 0 {
990-
val = oldcomm::recv(po);
991-
oldcomm::send(ch, val - 1);
988+
fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
989+
let mut val = 20;
990+
while val > 0 {
991+
val = oldcomm::recv(po);
992+
oldcomm::send(ch, val - 1);
993+
}
992994
}
993-
}
994995

995-
let setup_po = oldcomm::Port();
996-
let setup_ch = oldcomm::Chan(&setup_po);
997-
let parent_po = oldcomm::Port();
998-
let parent_ch = oldcomm::Chan(&parent_po);
999-
do spawn {
1000-
let child_po = oldcomm::Port();
1001-
oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
1002-
pingpong(child_po, parent_ch);
1003-
};
1004-
1005-
let child_ch = oldcomm::recv(setup_po);
1006-
oldcomm::send(child_ch, 20);
1007-
pingpong(parent_po, child_ch);
1008-
testrt::rust_dbg_lock_lock(lock);
1009-
testrt::rust_dbg_lock_signal(lock);
1010-
testrt::rust_dbg_lock_unlock(lock);
1011-
oldcomm::recv(fin_po);
1012-
testrt::rust_dbg_lock_destroy(lock);
996+
let setup_po = oldcomm::Port();
997+
let setup_ch = oldcomm::Chan(&setup_po);
998+
let parent_po = oldcomm::Port();
999+
let parent_ch = oldcomm::Chan(&parent_po);
1000+
do spawn {
1001+
let child_po = oldcomm::Port();
1002+
oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
1003+
pingpong(child_po, parent_ch);
1004+
};
1005+
1006+
let child_ch = oldcomm::recv(setup_po);
1007+
oldcomm::send(child_ch, 20);
1008+
pingpong(parent_po, child_ch);
1009+
testrt::rust_dbg_lock_lock(lock);
1010+
testrt::rust_dbg_lock_signal(lock);
1011+
testrt::rust_dbg_lock_unlock(lock);
1012+
oldcomm::recv(fin_po);
1013+
testrt::rust_dbg_lock_destroy(lock);
1014+
}
10131015
}
10141016
}
10151017

0 commit comments

Comments
 (0)