Clean up rustc warnings.

compiletest: compact "linux" "macos" etc.as "unix".
liballoc: remove a superfluous "use".
libcollections: remove invocations of deprecated methods in favor of
    their suggested replacements and use "_" for a loop counter.
libcoretest: remove invocations of deprecated methods;  also add
    "allow(deprecated)" for testing a deprecated method itself.
libglob: use "cfg_attr".
libgraphviz: add a test for one of data constructors.
libgreen: remove a superfluous "use".
libnum: "allow(type_overflow)" for type cast into u8 in a test code.
librustc: names of static variables should be in upper case.
libserialize: v[i] instead of get().
libstd/ascii: to_lowercase() instead of to_lower().
libstd/bitflags: modify AnotherSetOfFlags to use i8 as its backend.
    It will serve better for testing various aspects of bitflags!.
libstd/collections: "allow(deprecated)" for testing a deprecated
    method itself.
libstd/io: remove invocations of deprecated methods and superfluous "use".
    Also add #[test] where it was missing.
libstd/num: introduce a helper function to effectively remove
    invocations of a deprecated method.
libstd/path and rand: remove invocations of deprecated methods and
    superfluous "use".
libstd/task and libsync/comm: "allow(deprecated)" for testing
    a deprecated method itself.
libsync/deque: remove superfluous "unsafe".
libsync/mutex and once: names of static variables should be in upper case.
libterm: introduce a helper function to effectively remove
    invocations of a deprecated method.

We still see a few warnings about using obsoleted native::task::spawn()
in the test modules for libsync.  I'm not sure how I should replace them
with std::task::TaksBuilder and native::task::NativeTaskBuilder
(dependency to libstd?)

Signed-off-by: NODA, Kai <nodakai@gmail.com>
This commit is contained in:
NODA, Kai 2014-10-05 18:11:17 +08:00
parent a6e0c76ef4
commit f27ad3d3e9
40 changed files with 263 additions and 220 deletions

View File

@ -947,15 +947,12 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
String::from_chars(c.as_slice()) String::from_chars(c.as_slice())
} }
#[cfg(target_os = "windows")] #[cfg(windows)]
fn prefix_matches( line : &str, prefix : &str ) -> bool { fn prefix_matches( line : &str, prefix : &str ) -> bool {
to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice()) to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice())
} }
#[cfg(any(target_os = "linux", #[cfg(unix)]
target_os = "macos",
target_os = "freebsd",
target_os = "dragonfly"))]
fn prefix_matches( line : &str, prefix : &str ) -> bool { fn prefix_matches( line : &str, prefix : &str ) -> bool {
line.starts_with( prefix ) line.starts_with( prefix )
} }
@ -1356,24 +1353,21 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
} }
// Linux and mac don't require adjusting the library search path // Linux and mac don't require adjusting the library search path
#[cfg(any(target_os = "linux", #[cfg(unix)]
target_os = "macos",
target_os = "freebsd",
target_os = "dragonfly"))]
fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String { fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String {
format!("{} {}", prog, args.connect(" ")) format!("{} {}", prog, args.connect(" "))
} }
#[cfg(target_os = "windows")] #[cfg(windows)]
fn make_cmdline(libpath: &str, prog: &str, args: &[String]) -> String { fn make_cmdline(libpath: &str, prog: &str, args: &[String]) -> String {
format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" "))
}
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line // Build the LD_LIBRARY_PATH variable as it would be seen on the command line
// for diagnostic purposes // for diagnostic purposes
#[cfg(target_os = "windows")] fn lib_path_cmd_prefix(path: &str) -> String {
fn lib_path_cmd_prefix(path: &str) -> String { format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path)) }
format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" "))
} }
fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) { fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) {

View File

@ -276,7 +276,6 @@ impl<T: Sync + Send> Drop for Weak<T> {
#[allow(experimental)] #[allow(experimental)]
mod tests { mod tests {
use std::clone::Clone; use std::clone::Clone;
use std::collections::MutableSeq;
use std::comm::channel; use std::comm::channel;
use std::mem::drop; use std::mem::drop;
use std::ops::Drop; use std::ops::Drop;

View File

@ -2659,7 +2659,7 @@ mod tests {
let mut r = rng(); let mut r = rng();
let mut bitv = Bitv::with_capacity(BENCH_BITS, false); let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
b.iter(|| { b.iter(|| {
for i in range(0u, 100) { for _ in range(0u, 100) {
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen()); bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
} }
&bitv &bitv

View File

@ -890,13 +890,13 @@ mod tests {
} }
let v = vec![1i,2,3,4,5]; let v = vec![1i,2,3,4,5];
let u = vec![9i,8,1,2,3,4,5]; let mut u = vec![9i,8,1,2,3,4,5];
let mut m = list_from(v.as_slice()); let mut m = list_from(v.as_slice());
m.prepend(list_from(u.as_slice())); m.prepend(list_from(u.as_slice()));
check_links(&m); check_links(&m);
let sum = u.append(v.as_slice()); u.extend(v.as_slice().iter().map(|&b| b));
assert_eq!(sum.len(), m.len()); assert_eq!(u.len(), m.len());
for elt in sum.into_iter() { for elt in u.into_iter() {
assert_eq!(m.pop_front(), Some(elt)) assert_eq!(m.pop_front(), Some(elt))
} }
} }

View File

@ -611,10 +611,10 @@ mod tests {
assert_eq!(deq.len(), 3); assert_eq!(deq.len(), 3);
deq.push_front(a.clone()); deq.push_front(a.clone());
assert_eq!(deq.len(), 4); assert_eq!(deq.len(), 4);
assert_eq!((*deq.get(0)).clone(), a.clone()); assert_eq!(deq[0].clone(), a.clone());
assert_eq!((*deq.get(1)).clone(), b.clone()); assert_eq!(deq[1].clone(), b.clone());
assert_eq!((*deq.get(2)).clone(), c.clone()); assert_eq!(deq[2].clone(), c.clone());
assert_eq!((*deq.get(3)).clone(), d.clone()); assert_eq!(deq[3].clone(), d.clone());
} }
#[test] #[test]
@ -626,7 +626,7 @@ mod tests {
assert_eq!(deq.len(), 66); assert_eq!(deq.len(), 66);
for i in range(0u, 66) { for i in range(0u, 66) {
assert_eq!(*deq.get(i), 65 - i); assert_eq!(deq[i], 65 - i);
} }
let mut deq = RingBuf::new(); let mut deq = RingBuf::new();
@ -635,7 +635,7 @@ mod tests {
} }
for i in range(0u, 66) { for i in range(0u, 66) {
assert_eq!(*deq.get(i), i); assert_eq!(deq[i], i);
} }
} }

View File

@ -883,6 +883,7 @@ mod tests {
use std::slice::{AsSlice, ImmutableSlice}; use std::slice::{AsSlice, ImmutableSlice};
use string::String; use string::String;
use vec::Vec; use vec::Vec;
use slice::CloneableVector;
use unicode::char::UnicodeChar; use unicode::char::UnicodeChar;
@ -1504,7 +1505,7 @@ mod tests {
fn vec_str_conversions() { fn vec_str_conversions() {
let s1: String = String::from_str("All mimsy were the borogoves"); let s1: String = String::from_str("All mimsy were the borogoves");
let v: Vec<u8> = Vec::from_slice(s1.as_bytes()); let v: Vec<u8> = s1.as_bytes().to_vec();
let s2: String = String::from_str(from_utf8(v.as_slice()).unwrap()); let s2: String = String::from_str(from_utf8(v.as_slice()).unwrap());
let mut i: uint = 0u; let mut i: uint = 0u;
let n1: uint = s1.len(); let n1: uint = s1.len();

View File

@ -1036,6 +1036,7 @@ mod tests {
use str::{Str, StrSlice, Owned}; use str::{Str, StrSlice, Owned};
use super::{as_string, String}; use super::{as_string, String};
use vec::Vec; use vec::Vec;
use slice::CloneableVector;
#[test] #[test]
fn test_as_string() { fn test_as_string() {
@ -1051,15 +1052,15 @@ mod tests {
#[test] #[test]
fn test_from_utf8() { fn test_from_utf8() {
let xs = Vec::from_slice(b"hello"); let xs = b"hello".to_vec();
assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello"))); assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello")));
let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes()); let xs = "ศไทย中华Việt Nam".as_bytes().to_vec();
assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam"))); assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam")));
let xs = Vec::from_slice(b"hello\xFF"); let xs = b"hello\xFF".to_vec();
assert_eq!(String::from_utf8(xs), assert_eq!(String::from_utf8(xs),
Err(Vec::from_slice(b"hello\xFF"))); Err(b"hello\xFF".to_vec()));
} }
#[test] #[test]
@ -1211,7 +1212,8 @@ mod tests {
fn test_push_bytes() { fn test_push_bytes() {
let mut s = String::from_str("ABC"); let mut s = String::from_str("ABC");
unsafe { unsafe {
s.push_bytes([b'D']); let mv = s.as_mut_vec();
mv.push_all([b'D']);
} }
assert_eq!(s.as_slice(), "ABCD"); assert_eq!(s.as_slice(), "ABCD");
} }
@ -1239,17 +1241,18 @@ mod tests {
} }
#[test] #[test]
fn test_pop_char() { fn test_pop() {
let mut data = String::from_str("ประเทศไทย中华b¢€𤭢"); let mut data = String::from_str("ประเทศไทย中华b¢€𤭢");
assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes assert_eq!(data.pop().unwrap(), '𤭢'); // 4 bytes
assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes assert_eq!(data.pop().unwrap(), '€'); // 3 bytes
assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes
assert_eq!(data.pop_char().unwrap(), 'b'); // 1 bytes assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes
assert_eq!(data.pop_char().unwrap(), '华'); assert_eq!(data.pop().unwrap(), '华');
assert_eq!(data.as_slice(), "ประเทศไทย中"); assert_eq!(data.as_slice(), "ประเทศไทย中");
} }
#[test] #[test]
#[allow(deprecated)] // use remove(0) instead
fn test_shift_char() { fn test_shift_char() {
let mut data = String::from_str("𤭢€¢b华ประเทศไทย中"); let mut data = String::from_str("𤭢€¢b华ประเทศไทย中");
assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes

View File

@ -2266,8 +2266,8 @@ mod tests {
} }
#[test] #[test]
fn test_mut_slice_from() { fn test_slice_from_mut() {
let mut values = Vec::from_slice([1u8,2,3,4,5]); let mut values = vec![1u8,2,3,4,5];
{ {
let slice = values.slice_from_mut(2); let slice = values.slice_from_mut(2);
assert!(slice == [3, 4, 5]); assert!(slice == [3, 4, 5]);
@ -2280,8 +2280,8 @@ mod tests {
} }
#[test] #[test]
fn test_mut_slice_to() { fn test_slice_to_mut() {
let mut values = Vec::from_slice([1u8,2,3,4,5]); let mut values = vec![1u8,2,3,4,5];
{ {
let slice = values.slice_to_mut(2); let slice = values.slice_to_mut(2);
assert!(slice == [1, 2]); assert!(slice == [1, 2]);
@ -2294,8 +2294,8 @@ mod tests {
} }
#[test] #[test]
fn test_mut_split_at() { fn test_split_at_mut() {
let mut values = Vec::from_slice([1u8,2,3,4,5]); let mut values = vec![1u8,2,3,4,5];
{ {
let (left, right) = values.split_at_mut(2); let (left, right) = values.split_at_mut(2);
{ {
@ -2315,7 +2315,7 @@ mod tests {
} }
} }
assert!(values == Vec::from_slice([2u8, 3, 5, 6, 7])); assert!(values == vec![2u8, 3, 5, 6, 7]);
} }
#[test] #[test]
@ -2355,16 +2355,16 @@ mod tests {
#[test] #[test]
fn test_grow_fn() { fn test_grow_fn() {
let mut v = Vec::from_slice([0u, 1]); let mut v = vec![0u, 1];
v.grow_fn(3, |i| i); v.grow_fn(3, |i| i);
assert!(v == Vec::from_slice([0u, 1, 0, 1, 2])); assert!(v == vec![0u, 1, 0, 1, 2]);
} }
#[test] #[test]
fn test_retain() { fn test_retain() {
let mut vec = Vec::from_slice([1u, 2, 3, 4]); let mut vec = vec![1u, 2, 3, 4];
vec.retain(|x| x%2 == 0); vec.retain(|x| x%2 == 0);
assert!(vec == Vec::from_slice([2u, 4])); assert!(vec == vec![2u, 4]);
} }
#[test] #[test]
@ -2567,32 +2567,32 @@ mod tests {
#[test] #[test]
fn test_move_items() { fn test_move_items() {
let mut vec = vec!(1i, 2, 3); let vec = vec![1, 2, 3];
let mut vec2 : Vec<int> = vec!(); let mut vec2 : Vec<i32> = vec![];
for i in vec.into_iter() { for i in vec.into_iter() {
vec2.push(i); vec2.push(i);
} }
assert!(vec2 == vec!(1i, 2, 3)); assert!(vec2 == vec![1, 2, 3]);
} }
#[test] #[test]
fn test_move_items_reverse() { fn test_move_items_reverse() {
let mut vec = vec!(1i, 2, 3); let vec = vec![1, 2, 3];
let mut vec2 : Vec<int> = vec!(); let mut vec2 : Vec<i32> = vec![];
for i in vec.into_iter().rev() { for i in vec.into_iter().rev() {
vec2.push(i); vec2.push(i);
} }
assert!(vec2 == vec!(3i, 2, 1)); assert!(vec2 == vec![3, 2, 1]);
} }
#[test] #[test]
fn test_move_items_zero_sized() { fn test_move_items_zero_sized() {
let mut vec = vec!((), (), ()); let vec = vec![(), (), ()];
let mut vec2 : Vec<()> = vec!(); let mut vec2 : Vec<()> = vec![];
for i in vec.into_iter() { for i in vec.into_iter() {
vec2.push(i); vec2.push(i);
} }
assert!(vec2 == vec!((), (), ())); assert!(vec2 == vec![(), (), ()]);
} }
#[test] #[test]
@ -2707,7 +2707,7 @@ mod tests {
b.bytes = src_len as u64; b.bytes = src_len as u64;
b.iter(|| { b.iter(|| {
let dst = Vec::from_slice(src.clone().as_slice()); let dst = src.clone().as_slice().to_vec();
assert_eq!(dst.len(), src_len); assert_eq!(dst.len(), src_len);
assert!(dst.iter().enumerate().all(|(i, x)| i == *x)); assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
}); });
@ -2871,7 +2871,7 @@ mod tests {
b.iter(|| { b.iter(|| {
let mut dst = dst.clone(); let mut dst = dst.clone();
dst.push_all_move(src.clone()); dst.extend(src.clone().into_iter());
assert_eq!(dst.len(), dst_len + src_len); assert_eq!(dst.len(), dst_len + src_len);
assert!(dst.iter().enumerate().all(|(i, x)| i == *x)); assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
}); });

View File

@ -117,7 +117,7 @@ fn test_is_digit() {
fn test_escape_default() { fn test_escape_default() {
fn string(c: char) -> String { fn string(c: char) -> String {
let mut result = String::new(); let mut result = String::new();
escape_default(c, |c| { result.push_char(c); }); escape_default(c, |c| { result.push(c); });
return result; return result;
} }
let s = string('\n'); let s = string('\n');
@ -152,7 +152,7 @@ fn test_escape_default() {
fn test_escape_unicode() { fn test_escape_unicode() {
fn string(c: char) -> String { fn string(c: char) -> String {
let mut result = String::new(); let mut result = String::new();
escape_unicode(c, |c| { result.push_char(c); }); escape_unicode(c, |c| { result.push(c); });
return result; return result;
} }
let s = string('\x00'); let s = string('\x00');

View File

@ -868,7 +868,7 @@ fn bench_multiple_take(b: &mut Bencher) {
let mut it = range(0u, 42).cycle(); let mut it = range(0u, 42).cycle();
b.iter(|| { b.iter(|| {
let n = it.next().unwrap(); let n = it.next().unwrap();
for m in range(0u, n) { for _ in range(0u, n) {
it.take(it.next().unwrap()).all(|_| true); it.take(it.next().unwrap()).all(|_| true);
} }
}); });

View File

@ -109,7 +109,7 @@ fn test_transmute() {
} }
unsafe { unsafe {
assert!(Vec::from_slice([76u8]) == transmute("L".to_string())); assert!(vec![76u8] == transmute("L".to_string()));
} }
} }

View File

@ -89,6 +89,7 @@ fn test_collect() {
} }
#[test] #[test]
#[allow(deprecated)] // we know fold_ is deprecated
fn test_fold() { fn test_fold() {
assert_eq!(fold_(range(0i, 0) assert_eq!(fold_(range(0i, 0)
.map(|_| Ok::<(), ()>(()))), .map(|_| Ok::<(), ()>(()))),

View File

@ -682,7 +682,7 @@ mod test {
} }
#[test] #[test]
#[ignore(cfg(windows))] // FIXME (#9406) #[cfg_attr(windows, ignore)] // FIXME (#9406)
fn test_lots_of_files() { fn test_lots_of_files() {
// this is a good test because it touches lots of differently named files // this is a good test because it touches lots of differently named files
glob("/*/*/*/*").skip(10000).next(); glob("/*/*/*/*").skip(10000).next();

View File

@ -735,6 +735,20 @@ r#"digraph single_edge {
"#); "#);
} }
#[test]
fn test_some_labelled() {
let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]);
let result = test_input(LabelledGraph::new("test_some_labelled", labels,
vec![edge(0, 1, "A-1")]));
assert_eq!(result.unwrap().as_slice(),
r#"digraph test_some_labelled {
N0[label="A"];
N1[label="N1"];
N0 -> N1[label="A-1"];
}
"#);
}
#[test] #[test]
fn single_cyclic_node() { fn single_cyclic_node() {
let labels : Trivial = UnlabelledNodes(1); let labels : Trivial = UnlabelledNodes(1);

View File

@ -1027,7 +1027,6 @@ mod test {
use std::rt::task::TaskOpts; use std::rt::task::TaskOpts;
use std::rt::task::Task; use std::rt::task::Task;
use std::rt::local::Local; use std::rt::local::Local;
use std::time::Duration;
use {TaskState, PoolConfig, SchedPool}; use {TaskState, PoolConfig, SchedPool};
use basic; use basic;

View File

@ -462,6 +462,7 @@ macro_rules! impl_integer_for_uint {
} }
#[test] #[test]
#[allow(type_overflow)]
fn test_lcm() { fn test_lcm() {
assert_eq!((1 as $T).lcm(&0), 0 as $T); assert_eq!((1 as $T).lcm(&0), 0 as $T);
assert_eq!((0 as $T).lcm(&1), 0 as $T); assert_eq!((0 as $T).lcm(&1), 0 as $T);

View File

@ -655,19 +655,19 @@ mod test {
#[test] #[test]
fn smoke_lock() { fn smoke_lock() {
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe { unsafe {
let _guard = lock.lock(); let _guard = LK.lock();
} }
} }
#[test] #[test]
fn smoke_cond() { fn smoke_cond() {
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe { unsafe {
let guard = lock.lock(); let guard = LK.lock();
let t = Thread::start(proc() { let t = Thread::start(proc() {
let guard = lock.lock(); let guard = LK.lock();
guard.signal(); guard.signal();
}); });
guard.wait(); guard.wait();
@ -679,25 +679,25 @@ mod test {
#[test] #[test]
fn smoke_lock_noguard() { fn smoke_lock_noguard() {
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe { unsafe {
lock.lock_noguard(); LK.lock_noguard();
lock.unlock_noguard(); LK.unlock_noguard();
} }
} }
#[test] #[test]
fn smoke_cond_noguard() { fn smoke_cond_noguard() {
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe { unsafe {
lock.lock_noguard(); LK.lock_noguard();
let t = Thread::start(proc() { let t = Thread::start(proc() {
lock.lock_noguard(); LK.lock_noguard();
lock.signal_noguard(); LK.signal_noguard();
lock.unlock_noguard(); LK.unlock_noguard();
}); });
lock.wait_noguard(); LK.wait_noguard();
lock.unlock_noguard(); LK.unlock_noguard();
t.join(); t.join();
} }

View File

@ -2964,8 +2964,8 @@ mod tests {
let s = "{\"f\":null,\"a\":[null,123]}"; let s = "{\"f\":null,\"a\":[null,123]}";
let obj: FloatStruct = super::decode(s).unwrap(); let obj: FloatStruct = super::decode(s).unwrap();
assert!(obj.f.is_nan()); assert!(obj.f.is_nan());
assert!(obj.a.get(0).is_nan()); assert!(obj.a[0].is_nan());
assert_eq!(obj.a.get(1), &123f64); assert_eq!(obj.a[1], 123f64);
} }
#[test] #[test]

View File

@ -582,15 +582,15 @@ mod tests {
assert_eq!('A'.to_ascii().to_char(), 'A'); assert_eq!('A'.to_ascii().to_char(), 'A');
assert_eq!('A'.to_ascii().to_byte(), 65u8); assert_eq!('A'.to_ascii().to_byte(), 65u8);
assert_eq!('A'.to_ascii().to_lower().to_char(), 'a'); assert_eq!('A'.to_ascii().to_lowercase().to_char(), 'a');
assert_eq!('Z'.to_ascii().to_lower().to_char(), 'z'); assert_eq!('Z'.to_ascii().to_lowercase().to_char(), 'z');
assert_eq!('a'.to_ascii().to_upper().to_char(), 'A'); assert_eq!('a'.to_ascii().to_uppercase().to_char(), 'A');
assert_eq!('z'.to_ascii().to_upper().to_char(), 'Z'); assert_eq!('z'.to_ascii().to_uppercase().to_char(), 'Z');
assert_eq!('@'.to_ascii().to_lower().to_char(), '@'); assert_eq!('@'.to_ascii().to_lowercase().to_char(), '@');
assert_eq!('['.to_ascii().to_lower().to_char(), '['); assert_eq!('['.to_ascii().to_lowercase().to_char(), '[');
assert_eq!('`'.to_ascii().to_upper().to_char(), '`'); assert_eq!('`'.to_ascii().to_uppercase().to_char(), '`');
assert_eq!('{'.to_ascii().to_upper().to_char(), '{'); assert_eq!('{'.to_ascii().to_uppercase().to_char(), '{');
assert!('0'.to_ascii().is_digit()); assert!('0'.to_ascii().is_digit());
assert!('9'.to_ascii().is_digit()); assert!('9'.to_ascii().is_digit());

View File

@ -273,8 +273,8 @@ mod tests {
} }
bitflags! { bitflags! {
flags AnotherSetOfFlags: uint { flags AnotherSetOfFlags: i8 {
const AnotherFlag = 1u, const AnotherFlag = -1_i8,
} }
} }
@ -283,6 +283,9 @@ mod tests {
assert_eq!(Flags::empty().bits(), 0x00000000); assert_eq!(Flags::empty().bits(), 0x00000000);
assert_eq!(FlagA.bits(), 0x00000001); assert_eq!(FlagA.bits(), 0x00000001);
assert_eq!(FlagABC.bits(), 0x00000111); assert_eq!(FlagABC.bits(), 0x00000111);
assert_eq!(AnotherSetOfFlags::empty().bits(), 0x00);
assert_eq!(AnotherFlag.bits(), !0_i8);
} }
#[test] #[test]
@ -292,6 +295,8 @@ mod tests {
assert!(Flags::from_bits(0x10) == Some(FlagB)); assert!(Flags::from_bits(0x10) == Some(FlagB));
assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB)); assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB));
assert!(Flags::from_bits(0x1000) == None); assert!(Flags::from_bits(0x1000) == None);
assert!(AnotherSetOfFlags::from_bits(!0_i8) == Some(AnotherFlag));
} }
#[test] #[test]
@ -302,6 +307,8 @@ mod tests {
assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB)); assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB));
assert!(Flags::from_bits_truncate(0x1000) == Flags::empty()); assert!(Flags::from_bits_truncate(0x1000) == Flags::empty());
assert!(Flags::from_bits_truncate(0x1001) == FlagA); assert!(Flags::from_bits_truncate(0x1001) == FlagA);
assert!(AnotherSetOfFlags::from_bits_truncate(0_i8) == AnotherSetOfFlags::empty());
} }
#[test] #[test]
@ -309,6 +316,8 @@ mod tests {
assert!(Flags::empty().is_empty()); assert!(Flags::empty().is_empty());
assert!(!FlagA.is_empty()); assert!(!FlagA.is_empty());
assert!(!FlagABC.is_empty()); assert!(!FlagABC.is_empty());
assert!(!AnotherFlag.is_empty());
} }
#[test] #[test]
@ -316,6 +325,8 @@ mod tests {
assert!(Flags::all().is_all()); assert!(Flags::all().is_all());
assert!(!FlagA.is_all()); assert!(!FlagA.is_all());
assert!(FlagABC.is_all()); assert!(FlagABC.is_all());
assert!(AnotherFlag.is_all());
} }
#[test] #[test]
@ -323,6 +334,8 @@ mod tests {
let e1 = Flags::empty(); let e1 = Flags::empty();
let e2 = Flags::empty(); let e2 = Flags::empty();
assert!(!e1.intersects(e2)); assert!(!e1.intersects(e2));
assert!(AnotherFlag.intersects(AnotherFlag));
} }
#[test] #[test]
@ -353,6 +366,8 @@ mod tests {
assert!(!e1.contains(e2)); assert!(!e1.contains(e2));
assert!(e2.contains(e1)); assert!(e2.contains(e1));
assert!(FlagABC.contains(e2)); assert!(FlagABC.contains(e2));
assert!(AnotherFlag.contains(AnotherFlag));
} }
#[test] #[test]
@ -361,6 +376,10 @@ mod tests {
let e2 = FlagA | FlagB; let e2 = FlagA | FlagB;
e1.insert(e2); e1.insert(e2);
assert!(e1 == e2); assert!(e1 == e2);
let mut e3 = AnotherSetOfFlags::empty();
e3.insert(AnotherFlag);
assert!(e3 == AnotherFlag);
} }
#[test] #[test]
@ -369,6 +388,10 @@ mod tests {
let e2 = FlagA | FlagC; let e2 = FlagA | FlagC;
e1.remove(e2); e1.remove(e2);
assert!(e1 == FlagB); assert!(e1 == FlagB);
let mut e3 = AnotherFlag;
e3.remove(AnotherFlag);
assert!(e3 == AnotherSetOfFlags::empty());
} }
#[test] #[test]
@ -383,6 +406,10 @@ mod tests {
let mut e3 = e1; let mut e3 = e1;
e3.toggle(e2); e3.toggle(e2);
assert!(e3 == FlagA | FlagB); assert!(e3 == FlagA | FlagB);
let mut m4 = AnotherSetOfFlags::empty();
m4.toggle(AnotherSetOfFlags::empty());
assert!(m4 == AnotherSetOfFlags::empty());
} }
#[test] #[test]

View File

@ -1930,6 +1930,7 @@ mod test_map {
} }
#[test] #[test]
#[allow(deprecated)] // insert_or_update_with
fn test_update_with() { fn test_update_with() {
let mut m = HashMap::with_capacity(4); let mut m = HashMap::with_capacity(4);
assert!(m.insert(1i, 2i)); assert!(m.insert(1i, 2i));

View File

@ -400,7 +400,7 @@ mod test {
impl Reader for ShortReader { impl Reader for ShortReader {
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> { fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
match self.lengths.shift() { match self.lengths.remove(0) {
Some(i) => Ok(i), Some(i) => Ok(i),
None => Err(io::standard_error(io::EndOfFile)) None => Err(io::standard_error(io::EndOfFile))
} }
@ -551,7 +551,7 @@ mod test {
#[test] #[test]
fn test_read_line() { fn test_read_line() {
let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc")); let in_buf = MemReader::new(b"a\nb\nc".to_vec());
let mut reader = BufferedReader::with_capacity(2, in_buf); let mut reader = BufferedReader::with_capacity(2, in_buf);
assert_eq!(reader.read_line(), Ok("a\n".to_string())); assert_eq!(reader.read_line(), Ok("a\n".to_string()));
assert_eq!(reader.read_line(), Ok("b\n".to_string())); assert_eq!(reader.read_line(), Ok("b\n".to_string()));
@ -561,7 +561,7 @@ mod test {
#[test] #[test]
fn test_lines() { fn test_lines() {
let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc")); let in_buf = MemReader::new(b"a\nb\nc".to_vec());
let mut reader = BufferedReader::with_capacity(2, in_buf); let mut reader = BufferedReader::with_capacity(2, in_buf);
let mut it = reader.lines(); let mut it = reader.lines();
assert_eq!(it.next(), Some(Ok("a\n".to_string()))); assert_eq!(it.next(), Some(Ok("a\n".to_string())));

View File

@ -1415,7 +1415,7 @@ mod test {
check!(copy(&input, &output)); check!(copy(&input, &output));
assert_eq!(check!(File::open(&output).read_to_end()), assert_eq!(check!(File::open(&output).read_to_end()),
(Vec::from_slice(b"foo"))); b"foo".to_vec());
} }
#[test] #[test]
@ -1459,7 +1459,7 @@ mod test {
} }
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size); assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
assert_eq!(check!(File::open(&out).read_to_end()), assert_eq!(check!(File::open(&out).read_to_end()),
(Vec::from_slice(b"foobar"))); b"foobar".to_vec());
} }
#[cfg(not(windows))] // apparently windows doesn't like symlinks #[cfg(not(windows))] // apparently windows doesn't like symlinks
@ -1497,7 +1497,7 @@ mod test {
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size); assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
assert_eq!(check!(stat(&out)).size, check!(input.stat()).size); assert_eq!(check!(stat(&out)).size, check!(input.stat()).size);
assert_eq!(check!(File::open(&out).read_to_end()), assert_eq!(check!(File::open(&out).read_to_end()),
(Vec::from_slice(b"foobar"))); b"foobar".to_vec());
// can't link to yourself // can't link to yourself
match link(&input, &input) { match link(&input, &input) {
@ -1560,7 +1560,7 @@ mod test {
check!(file.fsync()); check!(file.fsync());
assert_eq!(check!(file.stat()).size, 10); assert_eq!(check!(file.stat()).size, 10);
assert_eq!(check!(File::open(&path).read_to_end()), assert_eq!(check!(File::open(&path).read_to_end()),
(Vec::from_slice(b"foobar\0\0\0\0"))); b"foobar\0\0\0\0".to_vec());
// Truncate to a smaller length, don't seek, and then write something. // Truncate to a smaller length, don't seek, and then write something.
// Ensure that the intermediate zeroes are all filled in (we're seeked // Ensure that the intermediate zeroes are all filled in (we're seeked
@ -1571,7 +1571,7 @@ mod test {
check!(file.fsync()); check!(file.fsync());
assert_eq!(check!(file.stat()).size, 9); assert_eq!(check!(file.stat()).size, 9);
assert_eq!(check!(File::open(&path).read_to_end()), assert_eq!(check!(File::open(&path).read_to_end()),
(Vec::from_slice(b"fo\0\0\0\0wut"))); b"fo\0\0\0\0wut".to_vec());
drop(file); drop(file);
} }

View File

@ -617,7 +617,7 @@ mod test {
#[bench] #[bench]
fn bench_mem_reader(b: &mut Bencher) { fn bench_mem_reader(b: &mut Bencher) {
b.iter(|| { b.iter(|| {
let buf = Vec::from_slice([5 as u8, ..100]); let buf = [5 as u8, ..100].to_vec();
{ {
let mut rdr = MemReader::new(buf); let mut rdr = MemReader::new(buf);
for _i in range(0u, 10) { for _i in range(0u, 10) {

View File

@ -1949,62 +1949,62 @@ mod tests {
return Ok(0); return Ok(0);
} }
}; };
behavior.shift(); behavior.remove(0);
} }
} }
} }
#[test] #[test]
fn test_read_at_least() { fn test_read_at_least() {
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([GoodBehavior(uint::MAX)])); vec![GoodBehavior(uint::MAX)]);
let mut buf = [0u8, ..5]; let mut buf = [0u8, ..5];
assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1);
assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least
assert!(r.read_at_least(0, buf).is_ok()); assert!(r.read_at_least(0, buf).is_ok());
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)])); vec![BadBehavior(50), GoodBehavior(uint::MAX)]);
assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1);
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(1), GoodBehavior(1), vec![BadBehavior(1), GoodBehavior(1),
BadBehavior(50), GoodBehavior(uint::MAX)])); BadBehavior(50), GoodBehavior(uint::MAX)]);
assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1);
assert!(r.read_at_least(1, buf).unwrap() >= 1); assert!(r.read_at_least(1, buf).unwrap() >= 1);
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(uint::MAX)])); vec![BadBehavior(uint::MAX)]);
assert_eq!(r.read_at_least(1, buf).unwrap_err().kind, NoProgress); assert_eq!(r.read_at_least(1, buf).unwrap_err().kind, NoProgress);
let mut r = MemReader::new(Vec::from_slice(b"hello, world!")); let mut r = MemReader::new(b"hello, world!".to_vec());
assert_eq!(r.read_at_least(5, buf).unwrap(), 5); assert_eq!(r.read_at_least(5, buf).unwrap(), 5);
assert_eq!(r.read_at_least(6, buf).unwrap_err().kind, InvalidInput); assert_eq!(r.read_at_least(6, buf).unwrap_err().kind, InvalidInput);
} }
#[test] #[test]
fn test_push_at_least() { fn test_push_at_least() {
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([GoodBehavior(uint::MAX)])); vec![GoodBehavior(uint::MAX)]);
let mut buf = Vec::new(); let mut buf = Vec::new();
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
assert!(r.push_at_least(0, 5, &mut buf).is_ok()); assert!(r.push_at_least(0, 5, &mut buf).is_ok());
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)])); vec![BadBehavior(50), GoodBehavior(uint::MAX)]);
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(1), GoodBehavior(1), vec![BadBehavior(1), GoodBehavior(1),
BadBehavior(50), GoodBehavior(uint::MAX)])); BadBehavior(50), GoodBehavior(uint::MAX)]);
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1); assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")), let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
Vec::from_slice([BadBehavior(uint::MAX)])); vec![BadBehavior(uint::MAX)]);
assert_eq!(r.push_at_least(1, 5, &mut buf).unwrap_err().kind, NoProgress); assert_eq!(r.push_at_least(1, 5, &mut buf).unwrap_err().kind, NoProgress);
let mut r = MemReader::new(Vec::from_slice(b"hello, world!")); let mut r = MemReader::new(b"hello, world!".to_vec());
assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput); assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput);
} }

View File

@ -126,9 +126,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option<Hint>)
#[cfg(all(test, not(target_os = "android")))] #[cfg(all(test, not(target_os = "android")))]
mod test { mod test {
use super::*; use super::*;
use io::net::tcp::*;
use io::net::ip::*; use io::net::ip::*;
use io::net::udp::*;
#[test] #[test]
fn dns_smoke_test() { fn dns_smoke_test() {

View File

@ -521,10 +521,8 @@ impl Clone for TcpAcceptor {
#[cfg(test)] #[cfg(test)]
#[allow(experimental)] #[allow(experimental)]
mod test { mod test {
use super::*;
use io::net::tcp::*; use io::net::tcp::*;
use io::net::ip::*; use io::net::ip::*;
use io::net::udp::*;
use io::*; use io::*;
use io::test::*; use io::test::*;
use prelude::*; use prelude::*;

View File

@ -118,7 +118,6 @@ impl Writer for PipeStream {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use prelude::*; use prelude::*;
#[test] #[test]

View File

@ -727,7 +727,7 @@ mod tests {
assert!(p.is_ok()); assert!(p.is_ok());
let mut p = p.unwrap(); let mut p = p.unwrap();
assert!(p.stdout.is_some()); assert!(p.stdout.is_some());
let ret = read_all(p.stdout.get_mut_ref() as &mut Reader); let ret = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
assert!(p.wait().unwrap().success()); assert!(p.wait().unwrap().success());
return ret; return ret;
} }
@ -758,9 +758,9 @@ mod tests {
.stdin(CreatePipe(true, false)) .stdin(CreatePipe(true, false))
.stdout(CreatePipe(false, true)) .stdout(CreatePipe(false, true))
.spawn().unwrap(); .spawn().unwrap();
p.stdin.get_mut_ref().write("foobar".as_bytes()).unwrap(); p.stdin.as_mut().unwrap().write("foobar".as_bytes()).unwrap();
drop(p.stdin.take()); drop(p.stdin.take());
let out = read_all(p.stdout.get_mut_ref() as &mut Reader); let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
assert!(p.wait().unwrap().success()); assert!(p.wait().unwrap().success());
assert_eq!(out, "foobar\n".to_string()); assert_eq!(out, "foobar\n".to_string());
} }
@ -1019,7 +1019,7 @@ mod tests {
fn test_add_to_env() { fn test_add_to_env() {
let prog = env_cmd().env("RUN_TEST_NEW_ENV", "123").spawn().unwrap(); let prog = env_cmd().env("RUN_TEST_NEW_ENV", "123").spawn().unwrap();
let result = prog.wait_with_output().unwrap(); let result = prog.wait_with_output().unwrap();
let output = str::from_utf8_lossy(result.output.as_slice()).into_string(); let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"),
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);

View File

@ -385,6 +385,7 @@ mod tests {
use super::*; use super::*;
use prelude::*; use prelude::*;
#[test]
fn smoke() { fn smoke() {
// Just make sure we can acquire handles // Just make sure we can acquire handles
stdin(); stdin();
@ -392,6 +393,7 @@ mod tests {
stderr(); stderr();
} }
#[test]
fn capture_stdout() { fn capture_stdout() {
use io::{ChanReader, ChanWriter}; use io::{ChanReader, ChanWriter};
@ -404,9 +406,10 @@ mod tests {
assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string());
} }
#[test]
fn capture_stderr() { fn capture_stderr() {
use realstd::comm::channel; use realstd::comm::channel;
use realstd::io::{Writer, ChanReader, ChanWriter, Reader}; use realstd::io::{ChanReader, ChanWriter, Reader};
let (tx, rx) = channel(); let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));

View File

@ -235,7 +235,6 @@ mod test {
use super::*; use super::*;
use time::Duration; use time::Duration;
use task::spawn; use task::spawn;
use io::*;
use prelude::*; use prelude::*;
#[test] #[test]

View File

@ -819,72 +819,82 @@ mod bench {
mod uint { mod uint {
use super::test::Bencher; use super::test::Bencher;
use rand::{weak_rng, Rng}; use rand::{weak_rng, Rng};
use num::ToStrRadix; use std::fmt;
#[inline]
fn to_string(x: uint, base: u8) {
format!("{}", fmt::radix(x, base));
}
#[bench] #[bench]
fn to_str_bin(b: &mut Bencher) { fn to_str_bin(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<uint>().to_str_radix(2); }) b.iter(|| { to_string(rng.gen::<uint>(), 2); })
} }
#[bench] #[bench]
fn to_str_oct(b: &mut Bencher) { fn to_str_oct(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<uint>().to_str_radix(8); }) b.iter(|| { to_string(rng.gen::<uint>(), 8); })
} }
#[bench] #[bench]
fn to_str_dec(b: &mut Bencher) { fn to_str_dec(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<uint>().to_str_radix(10); }) b.iter(|| { to_string(rng.gen::<uint>(), 10); })
} }
#[bench] #[bench]
fn to_str_hex(b: &mut Bencher) { fn to_str_hex(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<uint>().to_str_radix(16); }) b.iter(|| { to_string(rng.gen::<uint>(), 16); })
} }
#[bench] #[bench]
fn to_str_base_36(b: &mut Bencher) { fn to_str_base_36(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<uint>().to_str_radix(36); }) b.iter(|| { to_string(rng.gen::<uint>(), 36); })
} }
} }
mod int { mod int {
use super::test::Bencher; use super::test::Bencher;
use rand::{weak_rng, Rng}; use rand::{weak_rng, Rng};
use num::ToStrRadix; use std::fmt;
#[inline]
fn to_string(x: int, base: u8) {
format!("{}", fmt::radix(x, base));
}
#[bench] #[bench]
fn to_str_bin(b: &mut Bencher) { fn to_str_bin(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<int>().to_str_radix(2); }) b.iter(|| { to_string(rng.gen::<int>(), 2); })
} }
#[bench] #[bench]
fn to_str_oct(b: &mut Bencher) { fn to_str_oct(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<int>().to_str_radix(8); }) b.iter(|| { to_string(rng.gen::<int>(), 8); })
} }
#[bench] #[bench]
fn to_str_dec(b: &mut Bencher) { fn to_str_dec(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<int>().to_str_radix(10); }) b.iter(|| { to_string(rng.gen::<int>(), 10); })
} }
#[bench] #[bench]
fn to_str_hex(b: &mut Bencher) { fn to_str_hex(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<int>().to_str_radix(16); }) b.iter(|| { to_string(rng.gen::<int>(), 16); })
} }
#[bench] #[bench]
fn to_str_base_36(b: &mut Bencher) { fn to_str_base_36(b: &mut Bencher) {
let mut rng = weak_rng(); let mut rng = weak_rng();
b.iter(|| { rng.gen::<int>().to_str_radix(36); }) b.iter(|| { to_string(rng.gen::<int>(), 36); })
} }
} }

View File

@ -775,7 +775,7 @@ mod tests {
t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e"); t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e");
t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e"); t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e");
t!(v: b"a/b/c", [b"d", b"/e", b"f"], b"/e/f"); t!(v: b"a/b/c", [b"d", b"/e", b"f"], b"/e/f");
t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e"); t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e");
} }
#[test] #[test]
@ -879,7 +879,7 @@ mod tests {
t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f");
t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e"); t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e");
t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e"); t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e");
t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e"); t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e");
} }
#[test] #[test]

View File

@ -76,7 +76,6 @@ mod test {
use super::ReaderRng; use super::ReaderRng;
use io::MemReader; use io::MemReader;
use mem;
use rand::Rng; use rand::Rng;
#[test] #[test]
@ -87,25 +86,25 @@ mod test {
0, 0, 0, 0, 0, 0, 0, 3]; 0, 0, 0, 0, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v)); let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u64(), mem::to_be64(1)); assert_eq!(rng.next_u64(), 1_u64.to_be());
assert_eq!(rng.next_u64(), mem::to_be64(2)); assert_eq!(rng.next_u64(), 2_u64.to_be());
assert_eq!(rng.next_u64(), mem::to_be64(3)); assert_eq!(rng.next_u64(), 3_u64.to_be());
} }
#[test] #[test]
fn test_reader_rng_u32() { fn test_reader_rng_u32() {
let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]; let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3];
let mut rng = ReaderRng::new(MemReader::new(v)); let mut rng = ReaderRng::new(MemReader::new(v));
assert_eq!(rng.next_u32(), mem::to_be32(1)); assert_eq!(rng.next_u32(), 1_u32.to_be());
assert_eq!(rng.next_u32(), mem::to_be32(2)); assert_eq!(rng.next_u32(), 2_u32.to_be());
assert_eq!(rng.next_u32(), mem::to_be32(3)); assert_eq!(rng.next_u32(), 3_u32.to_be());
} }
#[test] #[test]
fn test_reader_rng_fill_bytes() { fn test_reader_rng_fill_bytes() {
let v = [1u8, 2, 3, 4, 5, 6, 7, 8]; let v = [1u8, 2, 3, 4, 5, 6, 7, 8];
let mut w = [0u8, .. 8]; let mut w = [0u8, .. 8];
let mut rng = ReaderRng::new(MemReader::new(Vec::from_slice(v))); let mut rng = ReaderRng::new(MemReader::new(v.as_slice().to_vec()));
rng.fill_bytes(w); rng.fill_bytes(w);
assert!(v == w); assert!(v == w);

View File

@ -447,6 +447,7 @@ mod test {
} }
#[test] #[test]
#[allow(deprecated)]
fn test_with_wrapper() { fn test_with_wrapper() {
let (tx, rx) = channel(); let (tx, rx) = channel();
TaskBuilder::new().with_wrapper(proc(body) { TaskBuilder::new().with_wrapper(proc(body) {

View File

@ -59,10 +59,11 @@ impl<S:Send,R:Send> DuplexStream<S, R> {
} }
} }
#[allow(deprecated)]
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::prelude::*; use std::prelude::*;
use comm::{duplex}; use comm::duplex;
#[test] #[test]
pub fn duplex_stream_1() { pub fn duplex_stream_1() {

View File

@ -553,14 +553,12 @@ mod tests {
let threads = range(0, NTHREADS).map(|_| { let threads = range(0, NTHREADS).map(|_| {
let s = s.clone(); let s = s.clone();
Thread::start(proc() { Thread::start(proc() {
unsafe { loop {
loop { match s.steal() {
match s.steal() { Data(2) => { HITS.fetch_add(1, SeqCst); }
Data(2) => { HITS.fetch_add(1, SeqCst); } Data(..) => fail!(),
Data(..) => fail!(), _ if DONE.load(SeqCst) => break,
_ if DONE.load(SeqCst) => break, _ => {}
_ => {}
}
} }
} }
}) })
@ -572,7 +570,7 @@ mod tests {
if rng.gen_range(0i, 3) == 2 { if rng.gen_range(0i, 3) == 2 {
match w.pop() { match w.pop() {
None => {} None => {}
Some(2) => unsafe { HITS.fetch_add(1, SeqCst); }, Some(2) => { HITS.fetch_add(1, SeqCst); },
Some(_) => fail!(), Some(_) => fail!(),
} }
} else { } else {
@ -581,22 +579,20 @@ mod tests {
} }
} }
unsafe { while HITS.load(SeqCst) < AMT as uint {
while HITS.load(SeqCst) < AMT as uint { match w.pop() {
match w.pop() { None => {}
None => {} Some(2) => { HITS.fetch_add(1, SeqCst); },
Some(2) => { HITS.fetch_add(1, SeqCst); }, Some(_) => fail!(),
Some(_) => fail!(),
}
} }
DONE.store(true, SeqCst);
} }
DONE.store(true, SeqCst);
for thread in threads.into_iter() { for thread in threads.into_iter() {
thread.join(); thread.join();
} }
assert_eq!(unsafe { HITS.load(SeqCst) }, expected as uint); assert_eq!(HITS.load(SeqCst), expected as uint);
} }
#[test] #[test]
@ -655,7 +651,7 @@ mod tests {
} }
} }
unsafe { DONE.store(true, SeqCst); } DONE.store(true, SeqCst);
for thread in threads.into_iter() { for thread in threads.into_iter() {
thread.join(); thread.join();

View File

@ -536,32 +536,32 @@ mod test {
#[test] #[test]
fn smoke_static() { fn smoke_static() {
static m: StaticMutex = MUTEX_INIT; static M: StaticMutex = MUTEX_INIT;
unsafe { unsafe {
drop(m.lock()); drop(M.lock());
drop(m.lock()); drop(M.lock());
m.destroy(); M.destroy();
} }
} }
#[test] #[test]
fn lots_and_lots() { fn lots_and_lots() {
static m: StaticMutex = MUTEX_INIT; static M: StaticMutex = MUTEX_INIT;
static mut CNT: uint = 0; static mut CNT: uint = 0;
static M: uint = 1000; static J: uint = 1000;
static N: uint = 3; static K: uint = 3;
fn inc() { fn inc() {
for _ in range(0, M) { for _ in range(0, J) {
unsafe { unsafe {
let _g = m.lock(); let _g = M.lock();
CNT += 1; CNT += 1;
} }
} }
} }
let (tx, rx) = channel(); let (tx, rx) = channel();
for _ in range(0, N) { for _ in range(0, K) {
let tx2 = tx.clone(); let tx2 = tx.clone();
native::task::spawn(proc() { inc(); tx2.send(()); }); native::task::spawn(proc() { inc(); tx2.send(()); });
let tx2 = tx.clone(); let tx2 = tx.clone();
@ -569,12 +569,12 @@ mod test {
} }
drop(tx); drop(tx);
for _ in range(0, 2 * N) { for _ in range(0, 2 * K) {
rx.recv(); rx.recv();
} }
assert_eq!(unsafe {CNT}, M * N * 2); assert_eq!(unsafe {CNT}, J * K * 2);
unsafe { unsafe {
m.destroy(); M.destroy();
} }
} }

View File

@ -126,17 +126,17 @@ mod test {
#[test] #[test]
fn smoke_once() { fn smoke_once() {
static o: Once = ONCE_INIT; static O: Once = ONCE_INIT;
let mut a = 0i; let mut a = 0i;
o.doit(|| a += 1); O.doit(|| a += 1);
assert_eq!(a, 1); assert_eq!(a, 1);
o.doit(|| a += 1); O.doit(|| a += 1);
assert_eq!(a, 1); assert_eq!(a, 1);
} }
#[test] #[test]
fn stampede_once() { fn stampede_once() {
static o: Once = ONCE_INIT; static O: Once = ONCE_INIT;
static mut run: bool = false; static mut run: bool = false;
let (tx, rx) = channel(); let (tx, rx) = channel();
@ -145,7 +145,7 @@ mod test {
spawn(proc() { spawn(proc() {
for _ in range(0u, 4) { task::deschedule() } for _ in range(0u, 4) { task::deschedule() }
unsafe { unsafe {
o.doit(|| { O.doit(|| {
assert!(!run); assert!(!run);
run = true; run = true;
}); });
@ -156,7 +156,7 @@ mod test {
} }
unsafe { unsafe {
o.doit(|| { O.doit(|| {
assert!(!run); assert!(!run);
run = true; run = true;
}); });

View File

@ -575,7 +575,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{expand,Words,Variables,Number}; use super::{expand,Param,Words,Variables,Number};
use std::result::Ok; use std::result::Ok;
#[test] #[test]
@ -605,40 +605,39 @@ mod test {
fn test_param_stack_failure_conditions() { fn test_param_stack_failure_conditions() {
let mut varstruct = Variables::new(); let mut varstruct = Variables::new();
let vars = &mut varstruct; let vars = &mut varstruct;
fn get_res(fmt: &str, cap: &str, params: &[Param], vars: &mut Variables) ->
Result<Vec<u8>, String>
{
let mut u8v: Vec<_> = fmt.bytes().collect();
u8v.extend(cap.as_bytes().iter().map(|&b| b));
expand(u8v.as_slice(), params, vars)
}
let caps = ["%d", "%c", "%s", "%Pa", "%l", "%!", "%~"]; let caps = ["%d", "%c", "%s", "%Pa", "%l", "%!", "%~"];
for cap in caps.iter() { for &cap in caps.iter() {
let res = expand(cap.as_bytes(), [], vars); let res = get_res("", cap, [], vars);
assert!(res.is_err(), assert!(res.is_err(),
"Op {} succeeded incorrectly with 0 stack entries", *cap); "Op {} succeeded incorrectly with 0 stack entries", cap);
let p = if *cap == "%s" || *cap == "%l" { let p = if cap == "%s" || cap == "%l" {
Words("foo".to_string()) Words("foo".to_string())
} else { } else {
Number(97) Number(97)
}; };
let res = expand("%p1".bytes().collect::<Vec<_>>() let res = get_res("%p1", cap, [p], vars);
.append(cap.as_bytes()).as_slice(),
[p],
vars);
assert!(res.is_ok(), assert!(res.is_ok(),
"Op {} failed with 1 stack entry: {}", *cap, res.unwrap_err()); "Op {} failed with 1 stack entry: {}", cap, res.unwrap_err());
} }
let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"]; let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"];
for cap in caps.iter() { for &cap in caps.iter() {
let res = expand(cap.as_bytes(), [], vars); let res = expand(cap.as_bytes(), [], vars);
assert!(res.is_err(), assert!(res.is_err(),
"Binop {} succeeded incorrectly with 0 stack entries", *cap); "Binop {} succeeded incorrectly with 0 stack entries", cap);
let res = expand("%{1}".bytes().collect::<Vec<_>>() let res = get_res("%{1}", cap, [], vars);
.append(cap.as_bytes()).as_slice(),
[],
vars);
assert!(res.is_err(), assert!(res.is_err(),
"Binop {} succeeded incorrectly with 1 stack entry", *cap); "Binop {} succeeded incorrectly with 1 stack entry", cap);
let res = expand("%{1}%{2}".bytes().collect::<Vec<_>>() let res = get_res("%{1}%{2}", cap, [], vars);
.append(cap.as_bytes()).as_slice(),
[],
vars);
assert!(res.is_ok(), assert!(res.is_ok(),
"Binop {} failed with 2 stack entries: {}", *cap, res.unwrap_err()); "Binop {} failed with 2 stack entries: {}", cap, res.unwrap_err());
} }
} }