about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-01-10 22:36:54 -0800
committerPatrick Walton <pcwalton@mimiga.net>2013-01-10 22:36:54 -0800
commitc6fe93d9b5ac40cfacc8d8e8e55261d284de4829 (patch)
tree9f79cde303a50e15a47198dc9f7b4ff489a2422e /src/libcore
parent83675895af7c6af80cc8a4f5cec4e565dc829fca (diff)
downloadrust-c6fe93d9b5ac40cfacc8d8e8e55261d284de4829.tar.gz
rust-c6fe93d9b5ac40cfacc8d8e8e55261d284de4829.zip
libcore: Fix core test. rs=broken
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/os.rs60
-rw-r--r--src/libcore/str.rs16
-rw-r--r--src/libcore/task/mod.rs86
3 files changed, 85 insertions, 77 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index ec31cb5c46b..6ceb71d25ae 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -1233,34 +1233,36 @@ mod tests {
 
     #[test]
     fn copy_file_ok() {
-      let tempdir = getcwd(); // would like to use $TMPDIR,
-                              // doesn't seem to work on Linux
-      assert (str::len(tempdir.to_str()) > 0u);
-      let in = tempdir.push("in.txt");
-      let out = tempdir.push("out.txt");
-
-      /* Write the temp input file */
-        let ostream = do as_c_charp(in.to_str()) |fromp| {
-            do as_c_charp("w+b") |modebuf| {
-                libc::fopen(fromp, modebuf)
-            }
-      };
-      assert (ostream as uint != 0u);
-      let s = ~"hello";
-      let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]);
-      do vec::as_mut_buf(buf) |b, _len| {
-          assert (libc::fwrite(b as *c_void, 1u as size_t,
-                               (str::len(s) + 1u) as size_t, ostream)
-                  == buf.len() as size_t)};
-      assert (libc::fclose(ostream) == (0u as c_int));
-      let rs = os::copy_file(&in, &out);
-      if (!os::path_exists(&in)) {
-        fail (fmt!("%s doesn't exist", in.to_str()));
-      }
-      assert(rs);
-      let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
-      assert (rslt == 0);
-      assert (remove_file(&in));
-      assert (remove_file(&out));
+        unsafe {
+          let tempdir = getcwd(); // would like to use $TMPDIR,
+                                  // doesn't seem to work on Linux
+          assert (str::len(tempdir.to_str()) > 0u);
+          let in = tempdir.push("in.txt");
+          let out = tempdir.push("out.txt");
+
+          /* Write the temp input file */
+            let ostream = do as_c_charp(in.to_str()) |fromp| {
+                do as_c_charp("w+b") |modebuf| {
+                    libc::fopen(fromp, modebuf)
+                }
+          };
+          assert (ostream as uint != 0u);
+          let s = ~"hello";
+          let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]);
+          do vec::as_mut_buf(buf) |b, _len| {
+              assert (libc::fwrite(b as *c_void, 1u as size_t,
+                                   (str::len(s) + 1u) as size_t, ostream)
+                      == buf.len() as size_t)};
+          assert (libc::fclose(ostream) == (0u as c_int));
+          let rs = os::copy_file(&in, &out);
+          if (!os::path_exists(&in)) {
+            fail (fmt!("%s doesn't exist", in.to_str()));
+          }
+          assert(rs);
+          let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
+          assert (rslt == 0);
+          assert (remove_file(&in));
+          assert (remove_file(&out));
+        }
     }
 }
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 722d62626a6..0a5211137b3 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -2674,9 +2674,11 @@ mod tests {
 
     #[test]
     fn test_to_lower() {
-        assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char);
-        assert ~"ymca" == map(~"YMCA",
-                             |c| libc::tolower(c as c_char) as char);
+        unsafe {
+            assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char);
+            assert ~"ymca" == map(~"YMCA",
+                                 |c| libc::tolower(c as c_char) as char);
+        }
     }
 
     #[test]
@@ -3192,9 +3194,11 @@ mod tests {
 
     #[test]
     fn test_map() {
-        assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char);
-        assert ~"YMCA" == map(~"ymca",
-                              |c| libc::toupper(c as c_char) as char);
+        unsafe {
+            assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char);
+            assert ~"YMCA" == map(~"ymca",
+                                  |c| libc::toupper(c as c_char) as char);
+        }
     }
 
     #[test]
diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs
index 04ecf155362..501dd52f9ca 100644
--- a/src/libcore/task/mod.rs
+++ b/src/libcore/task/mod.rs
@@ -957,59 +957,61 @@ extern mod testrt {
 
 #[test]
 fn test_spawn_sched_blocking() {
+    unsafe {
 
-    // Testing that a task in one scheduler can block in foreign code
-    // without affecting other schedulers
-    for iter::repeat(20u) {
+        // Testing that a task in one scheduler can block in foreign code
+        // without affecting other schedulers
+        for iter::repeat(20u) {
 
-        let start_po = oldcomm::Port();
-        let start_ch = oldcomm::Chan(&start_po);
-        let fin_po = oldcomm::Port();
-        let fin_ch = oldcomm::Chan(&fin_po);
+            let start_po = oldcomm::Port();
+            let start_ch = oldcomm::Chan(&start_po);
+            let fin_po = oldcomm::Port();
+            let fin_ch = oldcomm::Chan(&fin_po);
 
-        let lock = testrt::rust_dbg_lock_create();
+            let lock = testrt::rust_dbg_lock_create();
 
-        do spawn_sched(SingleThreaded) {
-            testrt::rust_dbg_lock_lock(lock);
+            do spawn_sched(SingleThreaded) {
+                testrt::rust_dbg_lock_lock(lock);
 
-            oldcomm::send(start_ch, ());
+                oldcomm::send(start_ch, ());
 
-            // Block the scheduler thread
-            testrt::rust_dbg_lock_wait(lock);
-            testrt::rust_dbg_lock_unlock(lock);
+                // Block the scheduler thread
+                testrt::rust_dbg_lock_wait(lock);
+                testrt::rust_dbg_lock_unlock(lock);
 
-            oldcomm::send(fin_ch, ());
-        };
+                oldcomm::send(fin_ch, ());
+            };
 
-        // Wait until the other task has its lock
-        oldcomm::recv(start_po);
+            // Wait until the other task has its lock
+            oldcomm::recv(start_po);
 
-        fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
-            let mut val = 20;
-            while val > 0 {
-                val = oldcomm::recv(po);
-                oldcomm::send(ch, val - 1);
+            fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
+                let mut val = 20;
+                while val > 0 {
+                    val = oldcomm::recv(po);
+                    oldcomm::send(ch, val - 1);
+                }
             }
-        }
 
-        let setup_po = oldcomm::Port();
-        let setup_ch = oldcomm::Chan(&setup_po);
-        let parent_po = oldcomm::Port();
-        let parent_ch = oldcomm::Chan(&parent_po);
-        do spawn {
-            let child_po = oldcomm::Port();
-            oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
-            pingpong(child_po, parent_ch);
-        };
-
-        let child_ch = oldcomm::recv(setup_po);
-        oldcomm::send(child_ch, 20);
-        pingpong(parent_po, child_ch);
-        testrt::rust_dbg_lock_lock(lock);
-        testrt::rust_dbg_lock_signal(lock);
-        testrt::rust_dbg_lock_unlock(lock);
-        oldcomm::recv(fin_po);
-        testrt::rust_dbg_lock_destroy(lock);
+            let setup_po = oldcomm::Port();
+            let setup_ch = oldcomm::Chan(&setup_po);
+            let parent_po = oldcomm::Port();
+            let parent_ch = oldcomm::Chan(&parent_po);
+            do spawn {
+                let child_po = oldcomm::Port();
+                oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
+                pingpong(child_po, parent_ch);
+            };
+
+            let child_ch = oldcomm::recv(setup_po);
+            oldcomm::send(child_ch, 20);
+            pingpong(parent_po, child_ch);
+            testrt::rust_dbg_lock_lock(lock);
+            testrt::rust_dbg_lock_signal(lock);
+            testrt::rust_dbg_lock_unlock(lock);
+            oldcomm::recv(fin_po);
+            testrt::rust_dbg_lock_destroy(lock);
+        }
     }
 }