diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 09dd85fe0de46..c3b17fe996405 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -101,7 +101,7 @@ mod test { #[test] pub fn DuplexStream1() { - let (mut left, mut right) = DuplexStream::new(); + let (left, right) = DuplexStream::new(); left.send(~"abc"); right.send(123); @@ -112,10 +112,9 @@ mod test { #[test] pub fn basic_rendezvous_test() { - let (mut port, chan) = rendezvous(); + let (port, chan) = rendezvous(); do spawn { - let mut chan = chan; chan.send("abc"); } @@ -126,9 +125,8 @@ mod test { fn recv_a_lot() { // Rendezvous streams should be able to handle any number of messages being sent do run_in_uv_task { - let (mut port, chan) = rendezvous(); + let (port, chan) = rendezvous(); do spawn { - let mut chan = chan; 1000000.times(|| { chan.send(()) }) } 1000000.times(|| { port.recv() }) @@ -137,9 +135,8 @@ mod test { #[test] fn send_and_fail_and_try_recv() { - let (mut port, chan) = rendezvous(); + let (port, chan) = rendezvous(); do spawn { - let mut chan = chan; chan.duplex_stream.send(()); // Can't access this field outside this module fail!() } @@ -148,9 +145,8 @@ mod test { #[test] fn try_send_and_recv_then_fail_before_ack() { - let (port, mut chan) = rendezvous(); + let (port, chan) = rendezvous(); do spawn { - let mut port = port; port.duplex_stream.recv(); fail!() } @@ -160,9 +156,8 @@ mod test { #[test] #[should_fail] fn send_and_recv_then_fail_before_ack() { - let (port, mut chan) = rendezvous(); + let (port, chan) = rendezvous(); do spawn { - let mut port = port; port.duplex_stream.recv(); fail!() } diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 592efe6d981b1..38deaf2dbcbb8 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -377,7 +377,6 @@ mod tests { use libc; use ptr; use option::{Some, None}; - use vec; #[test] fn test_str_multistring_parsing() { @@ -440,7 +439,7 @@ mod tests { assert_eq!(*ptr::offset(buf, 0), 'f' as libc::c_char); assert_eq!(*ptr::offset(buf, 1), 'o' as libc::c_char); assert_eq!(*ptr::offset(buf, 2), 'o' as libc::c_char); - assert_eq!(*ptr::offset(buf, 3), 0xff); + assert_eq!(*ptr::offset(buf, 3), 0xff as i8); assert_eq!(*ptr::offset(buf, 4), 0); } }); diff --git a/src/libstd/io/native/file.rs b/src/libstd/io/native/file.rs index 74d18f11a1d60..de2655303d606 100644 --- a/src/libstd/io/native/file.rs +++ b/src/libstd/io/native/file.rs @@ -907,22 +907,14 @@ pub fn utime(p: &CString, atime: u64, mtime: u64) -> IoResult<()> { #[cfg(test)] mod tests { use io::native::file::{CFile, FileDesc}; - use io::fs; use io; use libc; use os; - use path::Path; - use rand; use result::Ok; use rt::rtio::RtioFileStream; - fn tmpdir() -> Path { - let ret = os::tmpdir().join(format!("rust-{}", rand::random::())); - fs::mkdir(&ret, io::UserRWX); - ret - } - #[ignore(cfg(target_os = "freebsd"))] // hmm, maybe pipes have a tiny buffer + #[test] fn test_file_desc() { // Run this test with some pipes so we don't have to mess around with // opening or closing files. @@ -949,6 +941,7 @@ mod tests { } #[ignore(cfg(windows))] // apparently windows doesn't like tmpfile + #[test] fn test_cfile() { unsafe { let f = libc::tmpfile(); diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 75be56113e930..4803054333607 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -220,7 +220,7 @@ mod test { #[test] fn test_null_writer() { let mut s = NullWriter; - let mut buf = ~[0, 0, 0]; + let buf = ~[0, 0, 0]; s.write(buf); s.flush(); } @@ -248,7 +248,7 @@ mod test { struct TestWriter; impl Writer for TestWriter { - fn write(&mut self, buf: &[u8]) { + fn write(&mut self, _buf: &[u8]) { unsafe { writes += 1 } } diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 87fe5ac6f220b..ad624f71d0c7a 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -438,6 +438,9 @@ mod tests { static int_key: Key<@int> = &Key; do task::spawn { set(str_key, @~"string data"); + set(str_key, @~"string data 2"); + set(box_key, @@()); + set(box_key, @@()); set(int_key, @42); // This could cause a segfault if overwriting-destruction is done // with the crazy polymorphic transmute rather than the provided diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 070884c078c47..9cf36adc36f23 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -557,8 +557,6 @@ pub mod ptr_tests { #[test] fn test_ptr_addition() { - use vec::raw::*; - unsafe { let xs = ~[5, ..16]; let mut ptr = xs.as_ptr(); diff --git a/src/libstd/rand/rand_impls.rs b/src/libstd/rand/rand_impls.rs index ff722b739a86a..360f16971acad 100644 --- a/src/libstd/rand/rand_impls.rs +++ b/src/libstd/rand/rand_impls.rs @@ -240,12 +240,14 @@ mod tests { } } + #[test] fn floating_point_edge_cases() { // the test for exact equality is correct here. assert!(ConstantRng(0xffff_ffff).gen::() != 1.0) assert!(ConstantRng(0xffff_ffff_ffff_ffff).gen::() != 1.0) } + #[test] fn rand_open() { // this is unlikely to catch an incorrect implementation that // generates exactly 0 or 1, but it keeps it sane. @@ -260,6 +262,7 @@ mod tests { } } + #[test] fn rand_closed() { let mut rng = task_rng(); for _ in range(0, 1_000) { diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 7b27161ab5d7c..a767af4cc0ebe 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -64,23 +64,25 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } #[cfg(target_os = "freebsd")] mod imp { use cast; - use libc; + #[cfg(not(test))] use libc; use option::{Option, Some, None}; use iter::Iterator; - use str; + #[cfg(not(test))] use str; use unstable::finally::Finally; use unstable::mutex::{Mutex, MUTEX_INIT}; use util; - use vec; + #[cfg(not(test))] use vec; static mut global_args_ptr: uint = 0; static mut lock: Mutex = MUTEX_INIT; + #[cfg(not(test))] pub unsafe fn init(argc: int, argv: **u8) { let args = load_argc_and_argv(argc, argv); put(args); } + #[cfg(not(test))] pub unsafe fn cleanup() { rtassert!(take().is_some()); lock.destroy(); @@ -127,6 +129,7 @@ mod imp { } // Copied from `os`. + #[cfg(not(test))] unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] { vec::from_fn(argc as uint, |i| { str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int)) @@ -163,8 +166,8 @@ mod imp { } } -#[cfg(target_os = "macos")] -#[cfg(target_os = "win32")] +#[cfg(target_os = "macos", not(test))] +#[cfg(target_os = "win32", not(test))] mod imp { use option::Option; diff --git a/src/libstd/rt/context.rs b/src/libstd/rt/context.rs index 418557f659b00..31cf069688168 100644 --- a/src/libstd/rt/context.rs +++ b/src/libstd/rt/context.rs @@ -395,6 +395,9 @@ pub unsafe fn record_sp_limit(limit: uint) { /// As with the setter, this function does not have a __morestack header and can /// therefore be called in a "we're out of stack" situation. #[inline(always)] +// currently only called by `rust_stack_exhausted`, which doesn't +// exist in a test build. +#[cfg(not(test))] pub unsafe fn get_sp_limit() -> uint { return target_get_sp_limit(); diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index cd21cdeb711b7..15aa1602cd0e0 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -1341,6 +1341,8 @@ mod test { } // FIXME: #9407: xfail-test + #[ignore] + #[test] fn dont_starve_1() { stress_factor().times(|| { do run_in_mt_newsched_task { diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 62e012f9f4120..3299caa089aba 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -26,7 +26,6 @@ use local_data; use option::{Option, Some, None}; use rt::borrowck::BorrowRecord; use rt::borrowck; -use rt::context; use rt::context::Context; use rt::env; use rt::kill::Death; @@ -511,6 +510,7 @@ impl Unwinder { // irrelevant for documentation purposes. #[cfg(not(test))] // in testing, use the original libstd's version pub extern "C" fn rust_stack_exhausted() { + use rt::context; use rt::in_green_task_context; use rt::task::Task; use rt::local::Local; diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 85b57fdbc351c..d92291bbfbd06 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -339,7 +339,7 @@ mod tests { use task::spawn; use unstable::running_on_valgrind; use io::native::file; - use io::{FileNotFound, OtherIoError, Reader, Writer, io_error}; + use io::{FileNotFound, Reader, Writer, io_error}; #[test] #[cfg(not(target_os="android"))] // FIXME(#10380) diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 7225a1ab6cbe5..5f98a34520c09 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2734,7 +2734,6 @@ mod tests { use option::{None, Some, Option}; use ptr; use str::*; - use vec; use vec::{Vector, ImmutableVector, CopyableVector}; use cmp::{TotalOrd, Less, Equal, Greater}; use send_str::{SendStrOwned, SendStrStatic}; diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 0e56f42f5b9c0..3310dddc3276a 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -437,9 +437,6 @@ pub fn failing() -> bool { // !!! These tests are dangerous. If Something is buggy, they will hang, !!! // !!! instead of exiting cleanly. This might wedge the buildbots. !!! -#[cfg(test)] -fn block_forever() { let (po, _ch) = Chan::<()>::new(); po.recv(); } - #[test] fn test_unnamed_task() { use rt::test::run_in_uv_task; @@ -507,11 +504,6 @@ fn test_run_basic() { po.recv(); } -#[cfg(test)] -struct Wrapper { - f: Option> -} - #[test] fn test_add_wrapper() { let (po, ch) = Chan::new(); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index ad0d8861ee9c4..3fa41711d2b0a 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2678,7 +2678,7 @@ impl Extendable for ~[A] { #[cfg(test)] mod tests { - use option::{None, Option, Some}; + use option::{None, Some}; use mem; use vec::*; use cmp::*; @@ -2688,22 +2688,8 @@ mod tests { fn square_ref(n: &uint) -> uint { square(*n) } - fn is_three(n: &uint) -> bool { *n == 3u } - fn is_odd(n: &uint) -> bool { *n % 2u == 1u } - fn is_equal(x: &uint, y:&uint) -> bool { *x == *y } - - fn square_if_odd_r(n: &uint) -> Option { - if *n % 2u == 1u { Some(*n * *n) } else { None } - } - - fn square_if_odd_v(n: uint) -> Option { - if n % 2u == 1u { Some(n * n) } else { None } - } - - fn add(x: uint, y: &uint) -> uint { x + *y } - #[test] fn test_unsafe_ptrs() { unsafe { @@ -2982,6 +2968,7 @@ mod tests { assert_eq!(g, None); } + #[test] fn test_swap_remove() { let mut v = ~[1, 2, 3, 4, 5]; let mut e = v.swap_remove(0);