From 15966c3c1f99810ac81053769651776a67181dae Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Tue, 30 Sep 2014 21:42:55 -0700 Subject: [PATCH] Remove iotest macro This commit removes the `iotest!` macro from `std::io`. The macro was primarily used to ensure that all io-related tests were run on both libnative and libgreen/librustuv. However, now that the librustuv stack is being removed, the macro is no longer needed. See the [runtime removal RFC](https://github.com/rust-lang/rfcs/pull/230) for more context. [breaking-change] --- src/libstd/io/fs.rs | 194 ++++++++++++-------- src/libstd/io/mod.rs | 4 +- src/libstd/io/net/addrinfo.rs | 16 +- src/libstd/io/net/pipe.rs | 140 ++++++++------ src/libstd/io/net/tcp.rs | 211 +++++++++++++--------- src/libstd/io/net/udp.rs | 66 ++++--- src/libstd/io/pipe.rs | 8 +- src/libstd/io/process.rs | 173 +++++++++++------- src/libstd/io/stdio.rs | 15 +- src/libstd/io/test.rs | 36 ---- src/libstd/io/timer.rs | 151 ++++++++++------ src/test/run-pass/core-run-destroy.rs | 4 - src/test/run-pass/issue-12684.rs | 2 +- src/test/run-pass/process-detach.rs | 5 +- src/test/run-pass/tcp-connect-timeouts.rs | 6 +- 15 files changed, 604 insertions(+), 427 deletions(-) diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index b8e18fc44cbc6..f777460e66a45 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -948,9 +948,7 @@ mod test { use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite}; use io; use str; - use io::fs::{File, rmdir, mkdir, readdir, rmdir_recursive, - mkdir_recursive, copy, unlink, stat, symlink, link, - readlink, chmod, lstat, change_file_times}; + use io::fs::*; use path::Path; use io; use ops::Drop; @@ -1002,7 +1000,8 @@ mod test { TempDir(ret) } - iotest!(fn file_test_io_smoke_test() { + #[test] + fn file_test_io_smoke_test() { let message = "it's alright. have a good time"; let tmpdir = tmpdir(); let filename = &tmpdir.join("file_rt_io_file_test.txt"); @@ -1020,9 +1019,10 @@ mod test { assert_eq!(read_str.as_slice(), message); } check!(unlink(filename)); - }) + } - iotest!(fn invalid_path_raises() { + #[test] + fn invalid_path_raises() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_that_does_not_exist.txt"); let result = File::open_mode(filename, Open, Read); @@ -1032,9 +1032,10 @@ mod test { error!(result, "no such file or directory"); } error!(result, format!("path={}; mode=open; access=read", filename.display())); - }) + } - iotest!(fn file_test_iounlinking_invalid_path_should_raise_condition() { + #[test] + fn file_test_iounlinking_invalid_path_should_raise_condition() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_another_file_that_does_not_exist.txt"); @@ -1045,9 +1046,10 @@ mod test { error!(result, "no such file or directory"); } error!(result, format!("path={}", filename.display())); - }) + } - iotest!(fn file_test_io_non_positional_read() { + #[test] + fn file_test_io_non_positional_read() { let message: &str = "ten-four"; let mut read_mem = [0, .. 8]; let tmpdir = tmpdir(); @@ -1070,9 +1072,10 @@ mod test { check!(unlink(filename)); let read_str = str::from_utf8(read_mem).unwrap(); assert_eq!(read_str, message); - }) + } - iotest!(fn file_test_io_seek_and_tell_smoke_test() { + #[test] + fn file_test_io_seek_and_tell_smoke_test() { let message = "ten-four"; let mut read_mem = [0, .. 4]; let set_cursor = 4 as u64; @@ -1096,9 +1099,10 @@ mod test { assert_eq!(read_str, message.slice(4, 8)); assert_eq!(tell_pos_pre_read, set_cursor); assert_eq!(tell_pos_post_read, message.len() as u64); - }) + } - iotest!(fn file_test_io_seek_and_write() { + #[test] + fn file_test_io_seek_and_write() { let initial_msg = "food-is-yummy"; let overwrite_msg = "-the-bar!!"; let final_msg = "foo-the-bar!!"; @@ -1119,9 +1123,10 @@ mod test { check!(unlink(filename)); let read_str = str::from_utf8(read_mem).unwrap(); assert!(read_str.as_slice() == final_msg.as_slice()); - }) + } - iotest!(fn file_test_io_seek_shakedown() { + #[test] + fn file_test_io_seek_shakedown() { use str; // 01234567890123 let initial_msg = "qwer-asdf-zxcv"; let chunk_one: &str = "qwer"; @@ -1150,9 +1155,10 @@ mod test { assert_eq!(str::from_utf8(read_mem).unwrap(), chunk_one); } check!(unlink(filename)); - }) + } - iotest!(fn file_test_stat_is_correct_on_is_file() { + #[test] + fn file_test_stat_is_correct_on_is_file() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_file.txt"); { @@ -1168,9 +1174,10 @@ mod test { let stat_res_meth = check!(filename.stat()); assert_eq!(stat_res_meth.kind, io::TypeFile); check!(unlink(filename)); - }) + } - iotest!(fn file_test_stat_is_correct_on_is_dir() { + #[test] + fn file_test_stat_is_correct_on_is_dir() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_dir"); check!(mkdir(filename, io::UserRWX)); @@ -1179,26 +1186,29 @@ mod test { let stat_res_meth = check!(filename.stat()); assert!(stat_res_meth.kind == io::TypeDirectory); check!(rmdir(filename)); - }) + } - iotest!(fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() { + #[test] + fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() { let tmpdir = tmpdir(); let dir = &tmpdir.join("fileinfo_false_on_dir"); check!(mkdir(dir, io::UserRWX)); assert!(dir.is_file() == false); check!(rmdir(dir)); - }) + } - iotest!(fn file_test_fileinfo_check_exists_before_and_after_file_creation() { + #[test] + fn file_test_fileinfo_check_exists_before_and_after_file_creation() { let tmpdir = tmpdir(); let file = &tmpdir.join("fileinfo_check_exists_b_and_a.txt"); check!(File::create(file).write(b"foo")); assert!(file.exists()); check!(unlink(file)); assert!(!file.exists()); - }) + } - iotest!(fn file_test_directoryinfo_check_exists_before_and_after_mkdir() { + #[test] + fn file_test_directoryinfo_check_exists_before_and_after_mkdir() { let tmpdir = tmpdir(); let dir = &tmpdir.join("before_and_after_dir"); assert!(!dir.exists()); @@ -1207,9 +1217,10 @@ mod test { assert!(dir.is_dir()); check!(rmdir(dir)); assert!(!dir.exists()); - }) + } - iotest!(fn file_test_directoryinfo_readdir() { + #[test] + fn file_test_directoryinfo_readdir() { use str; let tmpdir = tmpdir(); let dir = &tmpdir.join("di_readdir"); @@ -1238,9 +1249,10 @@ mod test { check!(unlink(f)); } check!(rmdir(dir)); - }) + } - iotest!(fn file_test_walk_dir() { + #[test] + fn file_test_walk_dir() { let tmpdir = tmpdir(); let dir = &tmpdir.join("walk_dir"); check!(mkdir(dir, io::UserRWX)); @@ -1264,16 +1276,18 @@ mod test { } check!(rmdir_recursive(dir)); - }) + } - iotest!(fn recursive_mkdir() { + #[test] + fn recursive_mkdir() { let tmpdir = tmpdir(); let dir = tmpdir.join("d1/d2"); check!(mkdir_recursive(&dir, io::UserRWX)); assert!(dir.is_dir()) - }) + } - iotest!(fn recursive_mkdir_failure() { + #[test] + fn recursive_mkdir_failure() { let tmpdir = tmpdir(); let dir = tmpdir.join("d1"); let file = dir.join("f1"); @@ -1287,15 +1301,17 @@ mod test { error!(result, "couldn't create directory"); error!(result, "mode=0700"); error!(result, format!("path={}", file.display())); - }) + } - iotest!(fn recursive_mkdir_slash() { + #[test] + fn recursive_mkdir_slash() { check!(mkdir_recursive(&Path::new("/"), io::UserRWX)); - }) + } // FIXME(#12795) depends on lstat to work on windows #[cfg(not(windows))] - iotest!(fn recursive_rmdir() { + #[test] + fn recursive_rmdir() { let tmpdir = tmpdir(); let d1 = tmpdir.join("d1"); let dt = d1.join("t"); @@ -1310,9 +1326,10 @@ mod test { assert!(!d1.is_dir()); assert!(canary.exists()); - }) + } - iotest!(fn unicode_path_is_dir() { + #[test] + fn unicode_path_is_dir() { assert!(Path::new(".").is_dir()); assert!(!Path::new("test/stdtest/fs.rs").is_dir()); @@ -1328,9 +1345,10 @@ mod test { check!(File::create(&filepath)); // ignore return; touch only assert!(!filepath.is_dir()); assert!(filepath.exists()); - }) + } - iotest!(fn unicode_path_exists() { + #[test] + fn unicode_path_exists() { assert!(Path::new(".").exists()); assert!(!Path::new("test/nonexistent-bogus-path").exists()); @@ -1340,9 +1358,10 @@ mod test { check!(mkdir(&unicode, io::UserRWX)); assert!(unicode.exists()); assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists()); - }) + } - iotest!(fn copy_file_does_not_exist() { + #[test] + fn copy_file_does_not_exist() { let from = Path::new("test/nonexistent-bogus-path"); let to = Path::new("test/other-bogus-path"); @@ -1358,9 +1377,10 @@ mod test { assert!(!to.exists()); } } - }) + } - iotest!(fn copy_file_ok() { + #[test] + fn copy_file_ok() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); let out = tmpdir.join("out.txt"); @@ -1371,9 +1391,10 @@ mod test { assert_eq!(contents.as_slice(), b"hello"); assert_eq!(check!(input.stat()).perm, check!(out.stat()).perm); - }) + } - iotest!(fn copy_file_dst_dir() { + #[test] + fn copy_file_dst_dir() { let tmpdir = tmpdir(); let out = tmpdir.join("out"); @@ -1381,9 +1402,10 @@ mod test { match copy(&out, tmpdir.path()) { Ok(..) => fail!(), Err(..) => {} } - }) + } - iotest!(fn copy_file_dst_exists() { + #[test] + fn copy_file_dst_exists() { let tmpdir = tmpdir(); let input = tmpdir.join("in"); let output = tmpdir.join("out"); @@ -1394,9 +1416,10 @@ mod test { assert_eq!(check!(File::open(&output).read_to_end()), (Vec::from_slice(b"foo"))); - }) + } - iotest!(fn copy_file_src_dir() { + #[test] + fn copy_file_src_dir() { let tmpdir = tmpdir(); let out = tmpdir.join("out"); @@ -1404,9 +1427,10 @@ mod test { Ok(..) => fail!(), Err(..) => {} } assert!(!out.exists()); - }) + } - iotest!(fn copy_file_preserves_perm_bits() { + #[test] + fn copy_file_preserves_perm_bits() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); let out = tmpdir.join("out.txt"); @@ -1418,10 +1442,11 @@ mod test { check!(chmod(&input, io::UserFile)); check!(chmod(&out, io::UserFile)); - }) + } #[cfg(not(windows))] // FIXME(#10264) operation not permitted? - iotest!(fn symlinks_work() { + #[test] + fn symlinks_work() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); let out = tmpdir.join("out.txt"); @@ -1435,25 +1460,28 @@ mod test { assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size); assert_eq!(check!(File::open(&out).read_to_end()), (Vec::from_slice(b"foobar"))); - }) + } #[cfg(not(windows))] // apparently windows doesn't like symlinks - iotest!(fn symlink_noexist() { + #[test] + fn symlink_noexist() { let tmpdir = tmpdir(); // symlinks can point to things that don't exist check!(symlink(&tmpdir.join("foo"), &tmpdir.join("bar"))); assert!(check!(readlink(&tmpdir.join("bar"))) == tmpdir.join("foo")); - }) + } - iotest!(fn readlink_not_symlink() { + #[test] + fn readlink_not_symlink() { let tmpdir = tmpdir(); match readlink(tmpdir.path()) { Ok(..) => fail!("wanted a failure"), Err(..) => {} } - }) + } - iotest!(fn links_work() { + #[test] + fn links_work() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); let out = tmpdir.join("out.txt"); @@ -1481,9 +1509,10 @@ mod test { Ok(..) => fail!("wanted a failure"), Err(..) => {} } - }) + } - iotest!(fn chmod_works() { + #[test] + fn chmod_works() { let tmpdir = tmpdir(); let file = tmpdir.join("in.txt"); @@ -1498,9 +1527,10 @@ mod test { } check!(chmod(&file, io::UserFile)); - }) + } - iotest!(fn sync_doesnt_kill_anything() { + #[test] + fn sync_doesnt_kill_anything() { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); @@ -1511,9 +1541,10 @@ mod test { check!(file.fsync()); check!(file.datasync()); drop(file); - }) + } - iotest!(fn truncate_works() { + #[test] + fn truncate_works() { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); @@ -1542,9 +1573,10 @@ mod test { assert_eq!(check!(File::open(&path).read_to_end()), (Vec::from_slice(b"fo\0\0\0\0wut"))); drop(file); - }) + } - iotest!(fn open_flavors() { + #[test] + fn open_flavors() { let tmpdir = tmpdir(); match File::open_mode(&tmpdir.join("a"), io::Open, io::Read) { @@ -1602,9 +1634,10 @@ mod test { } assert!(check!(stat(&tmpdir.join("h"))).size == 3, "truncate didn't truncate"); - }) + } - iotest!(fn utime() { + #[test] + fn utime() { let tmpdir = tmpdir(); let path = tmpdir.join("a"); check!(File::create(&path)); @@ -1613,18 +1646,20 @@ mod test { check!(change_file_times(&path, 100000, 200000)); assert_eq!(check!(path.stat()).accessed, 100000); assert_eq!(check!(path.stat()).modified, 200000); - }) + } - iotest!(fn utime_noexist() { + #[test] + fn utime_noexist() { let tmpdir = tmpdir(); match change_file_times(&tmpdir.join("a"), 100, 200) { Ok(..) => fail!(), Err(..) => {} } - }) + } - iotest!(fn binary_file() { + #[test] + fn binary_file() { use rand::{StdRng, Rng}; let mut bytes = [0, ..1024]; @@ -1635,13 +1670,14 @@ mod test { check!(File::create(&tmpdir.join("test")).write(bytes)); let actual = check!(File::open(&tmpdir.join("test")).read_to_end()); assert!(actual.as_slice() == bytes); - }) + } - iotest!(fn unlink_readonly() { + #[test] + fn unlink_readonly() { let tmpdir = tmpdir(); let path = tmpdir.join("file"); check!(File::create(&path)); check!(chmod(&path, io::UserRead)); check!(unlink(&path)); - }) + } } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 444372e3c4f04..2191a682d3641 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -265,9 +265,6 @@ pub use self::buffered::{BufferedReader, BufferedWriter, BufferedStream, LineBufferedWriter}; pub use self::comm_adapters::{ChanReader, ChanWriter}; -// this comes first to get the iotest! macro -pub mod test; - mod buffered; mod comm_adapters; mod mem; @@ -280,6 +277,7 @@ pub mod pipe; pub mod process; pub mod signal; pub mod stdio; +pub mod test; pub mod timer; pub mod util; diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index ea1dd12f323a7..27241f9bfa559 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -125,7 +125,13 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option) // permission without help of apk #[cfg(all(test, not(target_os = "android")))] mod test { - iotest!(fn dns_smoke_test() { + use super::*; + use io::net::tcp::*; + use io::net::ip::*; + use io::net::udp::*; + + #[test] + fn dns_smoke_test() { let ipaddrs = get_host_addresses("localhost").unwrap(); let mut found_local = false; let local_addr = &Ipv4Addr(127, 0, 0, 1); @@ -133,11 +139,13 @@ mod test { found_local = found_local || addr == local_addr; } assert!(found_local); - }) + } - iotest!(fn issue_10663() { + #[ignore] + #[test] + fn issue_10663() { // Something should happen here, but this certainly shouldn't cause // everything to die. The actual outcome we don't care too much about. get_host_addresses("example.com").unwrap(); - } #[ignore]) + } } diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index a7ce18c40ef19..3f8069468f653 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -257,6 +257,8 @@ mod tests { use super::*; use io::*; use io::test::*; + use io::fs::PathExtensions; + use time::Duration; pub fn smalltest(server: proc(UnixStream):Send, client: proc(UnixStream):Send) { let path1 = next_test_unix(); @@ -277,7 +279,8 @@ mod tests { } } - iotest!(fn bind_error() { + #[test] + fn bind_error() { let path = "path/to/nowhere"; match UnixListener::bind(&path) { Ok(..) => fail!(), @@ -286,9 +289,10 @@ mod tests { e.kind == InvalidInput); } } - }) + } - iotest!(fn connect_error() { + #[test] + fn connect_error() { let path = if cfg!(windows) { r"\\.\pipe\this_should_not_exist_ever" } else { @@ -300,9 +304,10 @@ mod tests { assert!(e.kind == FileNotFound || e.kind == OtherIoError); } } - }) + } - iotest!(fn smoke() { + #[test] + fn smoke() { smalltest(proc(mut server) { let mut buf = [0]; server.read(buf).unwrap(); @@ -310,9 +315,11 @@ mod tests { }, proc(mut client) { client.write([99]).unwrap(); }) - }) + } - iotest!(fn read_eof() { + #[cfg_attr(windows, ignore)] // FIXME(#12516) + #[test] + fn read_eof() { smalltest(proc(mut server) { let mut buf = [0]; assert!(server.read(buf).is_err()); @@ -320,9 +327,10 @@ mod tests { }, proc(_client) { // drop the client }) - } #[cfg_attr(windows, ignore)]) // FIXME(#12516) + } - iotest!(fn write_begone() { + #[test] + fn write_begone() { smalltest(proc(mut server) { let buf = [0]; loop { @@ -340,9 +348,10 @@ mod tests { }, proc(_client) { // drop the client }) - }) + } - iotest!(fn accept_lots() { + #[test] + fn accept_lots() { let times = 10; let path1 = next_test_unix(); let path2 = path1.clone(); @@ -371,16 +380,18 @@ mod tests { } assert_eq!(buf[0], 100); } - }) + } #[cfg(unix)] - iotest!(fn path_exists() { + #[test] + fn path_exists() { let path = next_test_unix(); let _acceptor = UnixListener::bind(&path).listen(); assert!(path.exists()); - }) + } - iotest!(fn unix_clone_smoke() { + #[test] + fn unix_clone_smoke() { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); @@ -414,9 +425,10 @@ mod tests { assert_eq!(s1.read(buf), Ok(1)); debug!("reader done"); rx2.recv(); - }) + } - iotest!(fn unix_clone_two_read() { + #[test] + fn unix_clone_two_read() { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); let (tx1, rx) = channel(); @@ -446,9 +458,10 @@ mod tests { tx1.send(()); rx.recv(); - }) + } - iotest!(fn unix_clone_two_write() { + #[test] + fn unix_clone_two_write() { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); @@ -471,25 +484,30 @@ mod tests { s1.write([2]).unwrap(); rx.recv(); - }) + } - iotest!(fn drop_removes_listener_path() { + #[cfg(not(windows))] + #[test] + fn drop_removes_listener_path() { let path = next_test_unix(); let l = UnixListener::bind(&path).unwrap(); assert!(path.exists()); drop(l); assert!(!path.exists()); - } #[cfg(not(windows))]) + } - iotest!(fn drop_removes_acceptor_path() { + #[cfg(not(windows))] + #[test] + fn drop_removes_acceptor_path() { let path = next_test_unix(); let l = UnixListener::bind(&path).unwrap(); assert!(path.exists()); drop(l.listen().unwrap()); assert!(!path.exists()); - } #[cfg(not(windows))]) + } - iotest!(fn accept_timeout() { + #[test] + fn accept_timeout() { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).unwrap().listen().unwrap(); @@ -527,32 +545,37 @@ mod tests { drop(UnixStream::connect(&addr2).unwrap()); }); a.accept().unwrap(); - }) + } - iotest!(fn connect_timeout_error() { + #[test] + fn connect_timeout_error() { let addr = next_test_unix(); assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(100)).is_err()); - }) + } - iotest!(fn connect_timeout_success() { + #[test] + fn connect_timeout_success() { let addr = next_test_unix(); let _a = UnixListener::bind(&addr).unwrap().listen().unwrap(); assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(100)).is_ok()); - }) + } - iotest!(fn connect_timeout_zero() { + #[test] + fn connect_timeout_zero() { let addr = next_test_unix(); let _a = UnixListener::bind(&addr).unwrap().listen().unwrap(); assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(0)).is_err()); - }) + } - iotest!(fn connect_timeout_negative() { + #[test] + fn connect_timeout_negative() { let addr = next_test_unix(); let _a = UnixListener::bind(&addr).unwrap().listen().unwrap(); assert!(UnixStream::connect_timeout(&addr, Duration::milliseconds(-1)).is_err()); - }) + } - iotest!(fn close_readwrite_smoke() { + #[test] + fn close_readwrite_smoke() { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); @@ -586,9 +609,10 @@ mod tests { let _ = s2.close_write(); let _ = s3.close_read(); let _ = s3.close_write(); - }) + } - iotest!(fn close_read_wakes_up() { + #[test] + fn close_read_wakes_up() { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); @@ -611,9 +635,10 @@ mod tests { // this test will never finish if the child doesn't wake up rx.recv(); - }) + } - iotest!(fn readwrite_timeouts() { + #[test] + fn readwrite_timeouts() { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); @@ -648,9 +673,10 @@ mod tests { tx.send(()); s.set_timeout(None); assert_eq!(s.read([0, 0]), Ok(1)); - }) + } - iotest!(fn read_timeouts() { + #[test] + fn read_timeouts() { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); @@ -676,9 +702,10 @@ mod tests { for _ in range(0u, 100) { assert!(s.write([0, ..128 * 1024]).is_ok()); } - }) + } - iotest!(fn write_timeouts() { + #[test] + fn write_timeouts() { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); @@ -702,9 +729,10 @@ mod tests { tx.send(()); assert!(s.read([0]).is_ok()); - }) + } - iotest!(fn timeout_concurrent_read() { + #[test] + fn timeout_concurrent_read() { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); @@ -729,10 +757,11 @@ mod tests { tx.send(()); rx2.recv(); - }) + } #[cfg(not(windows))] - iotest!(fn clone_accept_smoke() { + #[test] + fn clone_accept_smoke() { let addr = next_test_unix(); let l = UnixListener::bind(&addr); let mut a = l.listen().unwrap(); @@ -749,10 +778,11 @@ mod tests { assert!(a.accept().is_ok()); drop(a); assert!(a2.accept().is_ok()); - }) + } #[cfg(not(windows))] // FIXME #17553 - iotest!(fn clone_accept_concurrent() { + #[test] + fn clone_accept_concurrent() { let addr = next_test_unix(); let l = UnixListener::bind(&addr); let a = l.listen().unwrap(); @@ -774,18 +804,20 @@ mod tests { assert!(rx.recv().is_ok()); assert!(rx.recv().is_ok()); - }) + } - iotest!(fn close_accept_smoke() { + #[test] + fn close_accept_smoke() { let addr = next_test_unix(); let l = UnixListener::bind(&addr); let mut a = l.listen().unwrap(); a.close_accept().unwrap(); assert_eq!(a.accept().err().unwrap().kind, EndOfFile); - }) + } - iotest!(fn close_accept_concurrent() { + #[test] + fn close_accept_concurrent() { let addr = next_test_unix(); let l = UnixListener::bind(&addr); let a = l.listen().unwrap(); @@ -799,5 +831,5 @@ mod tests { a2.close_accept().unwrap(); assert_eq!(rx.recv().err().unwrap().kind, EndOfFile); - }) + } } diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index 65d8f1c9c7764..cbd02abff7d2a 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -523,26 +523,33 @@ impl Clone for TcpAcceptor { #[allow(experimental)] mod test { use super::*; - use io::net::ip::SocketAddr; + use io::net::tcp::*; + use io::net::ip::*; + use io::net::udp::*; use io::*; + use io::test::*; use prelude::*; // FIXME #11530 this fails on android because tests are run as root - iotest!(fn bind_error() { + #[cfg_attr(any(windows, target_os = "android"), ignore)] + #[test] + fn bind_error() { match TcpListener::bind("0.0.0.0", 1) { Ok(..) => fail!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } - } #[cfg_attr(any(windows, target_os = "android"), ignore)]) + } - iotest!(fn connect_error() { + #[test] + fn connect_error() { match TcpStream::connect("0.0.0.0", 1) { Ok(..) => fail!(), Err(e) => assert_eq!(e.kind, ConnectionRefused), } - }) + } - iotest!(fn listen_ip4_localhost() { + #[test] + fn listen_ip4_localhost() { let socket_addr = next_test_ip4(); let ip_str = socket_addr.ip.to_string(); let port = socket_addr.port; @@ -558,9 +565,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 144); - }) + } - iotest!(fn connect_localhost() { + #[test] + fn connect_localhost() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -575,9 +583,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 64); - }) + } - iotest!(fn connect_ip4_loopback() { + #[test] + fn connect_ip4_loopback() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -592,9 +601,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 44); - }) + } - iotest!(fn connect_ip6_loopback() { + #[test] + fn connect_ip6_loopback() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -609,9 +619,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 66); - }) + } - iotest!(fn smoke_test_ip4() { + #[test] + fn smoke_test_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -626,9 +637,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 99); - }) + } - iotest!(fn smoke_test_ip6() { + #[test] + fn smoke_test_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -643,9 +655,10 @@ mod test { let mut buf = [0]; stream.read(buf).unwrap(); assert!(buf[0] == 99); - }) + } - iotest!(fn read_eof_ip4() { + #[test] + fn read_eof_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -660,9 +673,10 @@ mod test { let mut buf = [0]; let nread = stream.read(buf); assert!(nread.is_err()); - }) + } - iotest!(fn read_eof_ip6() { + #[test] + fn read_eof_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -677,9 +691,10 @@ mod test { let mut buf = [0]; let nread = stream.read(buf); assert!(nread.is_err()); - }) + } - iotest!(fn read_eof_twice_ip4() { + #[test] + fn read_eof_twice_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -702,9 +717,10 @@ mod test { "unknown kind: {}", e.kind); } } - }) + } - iotest!(fn read_eof_twice_ip6() { + #[test] + fn read_eof_twice_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -727,9 +743,10 @@ mod test { "unknown kind: {}", e.kind); } } - }) + } - iotest!(fn write_close_ip4() { + #[test] + fn write_close_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -754,9 +771,10 @@ mod test { } } } - }) + } - iotest!(fn write_close_ip6() { + #[test] + fn write_close_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -781,9 +799,10 @@ mod test { } } } - }) + } - iotest!(fn multiple_connect_serial_ip4() { + #[test] + fn multiple_connect_serial_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -802,9 +821,10 @@ mod test { stream.read(buf).unwrap(); assert_eq!(buf[0], 99); } - }) + } - iotest!(fn multiple_connect_serial_ip6() { + #[test] + fn multiple_connect_serial_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -823,9 +843,10 @@ mod test { stream.read(buf).unwrap(); assert_eq!(buf[0], 99); } - }) + } - iotest!(fn multiple_connect_interleaved_greedy_schedule_ip4() { + #[test] + fn multiple_connect_interleaved_greedy_schedule_ip4() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -862,9 +883,10 @@ mod test { stream.write([i as u8]).unwrap(); }); } - }) + } - iotest!(fn multiple_connect_interleaved_greedy_schedule_ip6() { + #[test] + fn multiple_connect_interleaved_greedy_schedule_ip6() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -901,9 +923,10 @@ mod test { stream.write([i as u8]).unwrap(); }); } - }) + } - iotest!(fn multiple_connect_interleaved_lazy_schedule_ip4() { + #[test] + fn multiple_connect_interleaved_lazy_schedule_ip4() { static MAX: int = 10; let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); @@ -940,9 +963,10 @@ mod test { stream.write([99]).unwrap(); }); } - }) + } - iotest!(fn multiple_connect_interleaved_lazy_schedule_ip6() { + #[test] + fn multiple_connect_interleaved_lazy_schedule_ip6() { static MAX: int = 10; let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); @@ -979,7 +1003,7 @@ mod test { stream.write([99]).unwrap(); }); } - }) + } pub fn socket_name(addr: SocketAddr) { let ip_str = addr.ip.to_string(); @@ -1015,18 +1039,21 @@ mod test { assert_eq!(addr, peer_name.unwrap()); } - iotest!(fn socket_and_peer_name_ip4() { + #[test] + fn socket_and_peer_name_ip4() { peer_name(next_test_ip4()); socket_name(next_test_ip4()); - }) + } - iotest!(fn socket_and_peer_name_ip6() { + #[test] + fn socket_and_peer_name_ip6() { // FIXME: peer name is not consistent //peer_name(next_test_ip6()); socket_name(next_test_ip6()); - }) + } - iotest!(fn partial_read() { + #[test] + fn partial_read() { let addr = next_test_ip4(); let port = addr.port; let (tx, rx) = channel(); @@ -1048,9 +1075,10 @@ mod test { assert_eq!(c.read(b), Ok(1)); c.write([1]).unwrap(); rx.recv(); - }) + } - iotest!(fn double_bind() { + #[test] + fn double_bind() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1063,9 +1091,10 @@ mod test { "unknown error: {} {}", e, e.kind); } } - }) + } - iotest!(fn fast_rebind() { + #[test] + fn fast_rebind() { let addr = next_test_ip4(); let port = addr.port; let (tx, rx) = channel(); @@ -1090,9 +1119,10 @@ mod test { // Close listener } let _listener = TcpListener::bind(addr.ip.to_string().as_slice(), port); - }) + } - iotest!(fn tcp_clone_smoke() { + #[test] + fn tcp_clone_smoke() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1121,9 +1151,10 @@ mod test { let mut buf = [0, 0]; assert_eq!(s1.read(buf), Ok(1)); rx2.recv(); - }) + } - iotest!(fn tcp_clone_two_read() { + #[test] + fn tcp_clone_two_read() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1155,9 +1186,10 @@ mod test { tx1.send(()); rx.recv(); - }) + } - iotest!(fn tcp_clone_two_write() { + #[test] + fn tcp_clone_two_write() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1182,9 +1214,10 @@ mod test { s1.write([2]).unwrap(); rx.recv(); - }) + } - iotest!(fn shutdown_smoke() { + #[test] + fn shutdown_smoke() { use rt::rtio::RtioTcpStream; let addr = next_test_ip4(); @@ -1202,9 +1235,10 @@ mod test { assert!(s.obj.close_write().is_ok()); assert!(s.write([1]).is_err()); assert_eq!(s.read_to_end(), Ok(vec!(1))); - }) + } - iotest!(fn accept_timeout() { + #[test] + fn accept_timeout() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1249,9 +1283,10 @@ mod test { port).unwrap()); }); a.accept().unwrap(); - }) + } - iotest!(fn close_readwrite_smoke() { + #[test] + fn close_readwrite_smoke() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1287,9 +1322,10 @@ mod test { let _ = s2.close_write(); let _ = s3.close_read(); let _ = s3.close_write(); - }) + } - iotest!(fn close_read_wakes_up() { + #[test] + fn close_read_wakes_up() { let addr = next_test_ip4(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1314,9 +1350,10 @@ mod test { // this test will never finish if the child doesn't wake up rx.recv(); - }) + } - iotest!(fn readwrite_timeouts() { + #[test] + fn readwrite_timeouts() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1348,9 +1385,10 @@ mod test { tx.send(()); s.set_timeout(None); assert_eq!(s.read([0, 0]), Ok(1)); - }) + } - iotest!(fn read_timeouts() { + #[test] + fn read_timeouts() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1378,9 +1416,10 @@ mod test { for _ in range(0i, 100) { assert!(s.write([0, ..128 * 1024]).is_ok()); } - }) + } - iotest!(fn write_timeouts() { + #[test] + fn write_timeouts() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1407,9 +1446,10 @@ mod test { tx.send(()); assert!(s.read([0]).is_ok()); - }) + } - iotest!(fn timeout_concurrent_read() { + #[test] + fn timeout_concurrent_read() { let addr = next_test_ip6(); let ip_str = addr.ip.to_string(); let port = addr.port; @@ -1436,9 +1476,10 @@ mod test { tx.send(()); rx2.recv(); - }) + } - iotest!(fn clone_while_reading() { + #[test] + fn clone_while_reading() { let addr = next_test_ip6(); let listen = TcpListener::bind(addr.ip.to_string().as_slice(), addr.port); let mut accept = listen.listen().unwrap(); @@ -1476,9 +1517,10 @@ mod test { tx.send(()); rxdone.recv(); rxdone.recv(); - }) + } - iotest!(fn clone_accept_smoke() { + #[test] + fn clone_accept_smoke() { let addr = next_test_ip4(); let l = TcpListener::bind(addr.ip.to_string().as_slice(), addr.port); let mut a = l.listen().unwrap(); @@ -1493,9 +1535,10 @@ mod test { assert!(a.accept().is_ok()); assert!(a2.accept().is_ok()); - }) + } - iotest!(fn clone_accept_concurrent() { + #[test] + fn clone_accept_concurrent() { let addr = next_test_ip4(); let l = TcpListener::bind(addr.ip.to_string().as_slice(), addr.port); let a = l.listen().unwrap(); @@ -1516,18 +1559,20 @@ mod test { assert!(rx.recv().is_ok()); assert!(rx.recv().is_ok()); - }) + } - iotest!(fn close_accept_smoke() { + #[test] + fn close_accept_smoke() { let addr = next_test_ip4(); let l = TcpListener::bind(addr.ip.to_string().as_slice(), addr.port); let mut a = l.listen().unwrap(); a.close_accept().unwrap(); assert_eq!(a.accept().err().unwrap().kind, EndOfFile); - }) + } - iotest!(fn close_accept_concurrent() { + #[test] + fn close_accept_concurrent() { let addr = next_test_ip4(); let l = TcpListener::bind(addr.ip.to_string().as_slice(), addr.port); let a = l.listen().unwrap(); @@ -1541,5 +1586,5 @@ mod test { a2.close_accept().unwrap(); assert_eq!(rx.recv().err().unwrap().kind, EndOfFile); - }) + } } diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index ab61d2a4d916e..3ba8765fc3e21 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -264,18 +264,24 @@ impl Writer for UdpStream { #[allow(experimental)] mod test { use super::*; - use io::net::ip::{SocketAddr}; + use prelude::*; + use io::*; + use io::net::ip::*; + use io::test::*; // FIXME #11530 this fails on android because tests are run as root - iotest!(fn bind_error() { + #[cfg_attr(any(windows, target_os = "android"), ignore)] + #[test] + fn bind_error() { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; match UdpSocket::bind(addr) { Ok(..) => fail!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } - } #[cfg_attr(any(windows, target_os = "android"), ignore)]) + } - iotest!(fn socket_smoke_test_ip4() { + #[test] + fn socket_smoke_test_ip4() { let server_ip = next_test_ip4(); let client_ip = next_test_ip4(); let (tx1, rx1) = channel(); @@ -308,9 +314,10 @@ mod test { Err(..) => fail!() } rx2.recv(); - }) + } - iotest!(fn socket_smoke_test_ip6() { + #[test] + fn socket_smoke_test_ip6() { let server_ip = next_test_ip6(); let client_ip = next_test_ip6(); let (tx, rx) = channel::<()>(); @@ -340,9 +347,10 @@ mod test { } Err(..) => fail!() } - }) + } - iotest!(fn stream_smoke_test_ip4() { + #[test] + fn stream_smoke_test_ip4() { let server_ip = next_test_ip4(); let client_ip = next_test_ip4(); let (tx1, rx1) = channel(); @@ -378,9 +386,10 @@ mod test { Err(..) => fail!() } rx2.recv(); - }) + } - iotest!(fn stream_smoke_test_ip6() { + #[test] + fn stream_smoke_test_ip6() { let server_ip = next_test_ip6(); let client_ip = next_test_ip6(); let (tx1, rx1) = channel(); @@ -416,7 +425,7 @@ mod test { Err(..) => fail!() } rx2.recv(); - }) + } pub fn socket_name(addr: SocketAddr) { let server = UdpSocket::bind(addr); @@ -431,15 +440,18 @@ mod test { assert_eq!(addr, so_name.unwrap()); } - iotest!(fn socket_name_ip4() { + #[test] + fn socket_name_ip4() { socket_name(next_test_ip4()); - }) + } - iotest!(fn socket_name_ip6() { + #[test] + fn socket_name_ip6() { socket_name(next_test_ip6()); - }) + } - iotest!(fn udp_clone_smoke() { + #[test] + fn udp_clone_smoke() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut sock1 = UdpSocket::bind(addr1).unwrap(); @@ -467,9 +479,10 @@ mod test { let mut buf = [0, 0]; assert_eq!(sock1.recv_from(buf), Ok((1, addr2))); rx2.recv(); - }) + } - iotest!(fn udp_clone_two_read() { + #[test] + fn udp_clone_two_read() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut sock1 = UdpSocket::bind(addr1).unwrap(); @@ -500,9 +513,10 @@ mod test { tx1.send(()); rx.recv(); - }) + } - iotest!(fn udp_clone_two_write() { + #[test] + fn udp_clone_two_write() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut sock1 = UdpSocket::bind(addr1).unwrap(); @@ -543,10 +557,11 @@ mod test { rx.recv(); serv_rx.recv(); - }) + } #[cfg(not(windows))] // FIXME #17553 - iotest!(fn recv_from_timeout() { + #[test] + fn recv_from_timeout() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut a = UdpSocket::bind(addr1).unwrap(); @@ -580,9 +595,10 @@ mod test { // Make sure the child didn't die rx2.recv(); - }) + } - iotest!(fn send_to_timeout() { + #[test] + fn send_to_timeout() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut a = UdpSocket::bind(addr1).unwrap(); @@ -596,5 +612,5 @@ mod test { Err(e) => fail!("other error: {}", e), } } - }) + } } diff --git a/src/libstd/io/pipe.rs b/src/libstd/io/pipe.rs index 1304877fc14c5..d7d478bd458c8 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/io/pipe.rs @@ -118,7 +118,11 @@ impl Writer for PipeStream { #[cfg(test)] mod test { - iotest!(fn partial_read() { + use super::*; + use prelude::*; + + #[test] + fn partial_read() { use os; use io::pipe::PipeStream; @@ -135,5 +139,5 @@ mod test { let mut buf = [0, ..10]; input.read(buf).unwrap(); tx.send(()); - }) + } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 56bdbe4a9796f..5220e5c984ab7 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -662,39 +662,52 @@ impl Drop for Process { #[cfg(test)] mod tests { + #![allow(unused_imports)] + extern crate native; - use io::process::{Command, Process}; + + use super::*; use prelude::*; + use io::timer::*; + use io::*; + use io::fs::PathExtensions; + use time::Duration; + use str; + use rt::running_on_valgrind; // FIXME(#10380) these tests should not all be ignored on android. #[cfg(not(target_os="android"))] - iotest!(fn smoke() { + #[test] + fn smoke() { let p = Command::new("true").spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); assert!(p.wait().unwrap().success()); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn smoke_failure() { + #[test] + fn smoke_failure() { match Command::new("if-this-is-a-binary-then-the-world-has-ended").spawn() { Ok(..) => fail!(), Err(..) => {} } - }) + } #[cfg(not(target_os="android"))] - iotest!(fn exit_reported_right() { + #[test] + fn exit_reported_right() { let p = Command::new("false").spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); assert!(p.wait().unwrap().matches_exit_status(1)); drop(p.wait().clone()); - }) + } #[cfg(all(unix, not(target_os="android")))] - iotest!(fn signal_reported_right() { + #[test] + fn signal_reported_right() { let p = Command::new("/bin/sh").arg("-c").arg("kill -1 $$").spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); @@ -702,7 +715,7 @@ mod tests { process::ExitSignal(1) => {}, result => fail!("not terminated by signal 1 (instead, {})", result), } - }) + } pub fn read_all(input: &mut Reader) -> String { input.read_to_string().unwrap() @@ -719,23 +732,26 @@ mod tests { } #[cfg(not(target_os="android"))] - iotest!(fn stdout_works() { + #[test] + fn stdout_works() { let mut cmd = Command::new("echo"); cmd.arg("foobar").stdout(CreatePipe(false, true)); assert_eq!(run_output(cmd), "foobar\n".to_string()); - }) + } #[cfg(all(unix, not(target_os="android")))] - iotest!(fn set_cwd_works() { + #[test] + fn set_cwd_works() { let mut cmd = Command::new("/bin/sh"); cmd.arg("-c").arg("pwd") .cwd(&Path::new("/")) .stdout(CreatePipe(false, true)); assert_eq!(run_output(cmd), "/\n".to_string()); - }) + } #[cfg(all(unix, not(target_os="android")))] - iotest!(fn stdin_works() { + #[test] + fn stdin_works() { let mut p = Command::new("/bin/sh") .arg("-c").arg("read line; echo $line") .stdin(CreatePipe(true, false)) @@ -746,21 +762,24 @@ mod tests { let out = read_all(p.stdout.get_mut_ref() as &mut Reader); assert!(p.wait().unwrap().success()); assert_eq!(out, "foobar\n".to_string()); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn detach_works() { + #[test] + fn detach_works() { let mut p = Command::new("true").detached().spawn().unwrap(); assert!(p.wait().unwrap().success()); - }) + } #[cfg(windows)] - iotest!(fn uid_fails_on_windows() { + #[test] + fn uid_fails_on_windows() { assert!(Command::new("test").uid(10).spawn().is_err()); - }) + } #[cfg(all(unix, not(target_os="android")))] - iotest!(fn uid_works() { + #[test] + fn uid_works() { use libc; let mut p = Command::new("/bin/sh") .arg("-c").arg("true") @@ -768,36 +787,40 @@ mod tests { .gid(unsafe { libc::getgid() as uint }) .spawn().unwrap(); assert!(p.wait().unwrap().success()); - }) + } #[cfg(all(unix, not(target_os="android")))] - iotest!(fn uid_to_root_fails() { + #[test] + fn uid_to_root_fails() { use libc; // if we're already root, this isn't a valid test. Most of the bots run // as non-root though (android is an exception). if unsafe { libc::getuid() == 0 } { return } assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err()); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_process_status() { + #[test] + fn test_process_status() { let mut status = Command::new("false").status().unwrap(); assert!(status.matches_exit_status(1)); status = Command::new("true").status().unwrap(); assert!(status.success()); - }) + } - iotest!(fn test_process_output_fail_to_start() { + #[test] + fn test_process_output_fail_to_start() { match Command::new("/no-binary-by-this-name-should-exist").output() { Err(e) => assert_eq!(e.kind, FileNotFound), Ok(..) => fail!() } - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_process_output_output() { + #[test] + fn test_process_output_output() { let ProcessOutput {status, output, error} = Command::new("echo").arg("hello").output().unwrap(); let output_str = str::from_utf8(output.as_slice()).unwrap(); @@ -808,33 +831,37 @@ mod tests { if !running_on_valgrind() { assert_eq!(error, Vec::new()); } - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_process_output_error() { + #[test] + fn test_process_output_error() { let ProcessOutput {status, output, error} = Command::new("mkdir").arg(".").output().unwrap(); assert!(status.matches_exit_status(1)); assert_eq!(output, Vec::new()); assert!(!error.is_empty()); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_finish_once() { + #[test] + fn test_finish_once() { let mut prog = Command::new("false").spawn().unwrap(); assert!(prog.wait().unwrap().matches_exit_status(1)); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_finish_twice() { + #[test] + fn test_finish_twice() { let mut prog = Command::new("false").spawn().unwrap(); assert!(prog.wait().unwrap().matches_exit_status(1)); assert!(prog.wait().unwrap().matches_exit_status(1)); - }) + } #[cfg(not(target_os="android"))] - iotest!(fn test_wait_with_output_once() { + #[test] + fn test_wait_with_output_once() { let prog = Command::new("echo").arg("hello").spawn().unwrap(); let ProcessOutput {status, output, error} = prog.wait_with_output().unwrap(); let output_str = str::from_utf8(output.as_slice()).unwrap(); @@ -845,7 +872,7 @@ mod tests { if !running_on_valgrind() { assert_eq!(error, Vec::new()); } - }) + } #[cfg(all(unix, not(target_os="android")))] pub fn pwd_cmd() -> Command { @@ -865,7 +892,8 @@ mod tests { cmd } - iotest!(fn test_keep_current_working_dir() { + #[test] + fn test_keep_current_working_dir() { use os; let prog = pwd_cmd().spawn().unwrap(); @@ -878,9 +906,10 @@ mod tests { assert_eq!(parent_stat.unstable.device, child_stat.unstable.device); assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode); - }) + } - iotest!(fn test_change_working_directory() { + #[test] + fn test_change_working_directory() { use os; // test changing to the parent of os::getcwd() because we know // the path exists (and os::getcwd() is not expected to be root) @@ -895,7 +924,7 @@ mod tests { assert_eq!(parent_stat.unstable.device, child_stat.unstable.device); assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode); - }) + } #[cfg(all(unix, not(target_os="android")))] pub fn env_cmd() -> Command { @@ -916,7 +945,8 @@ mod tests { } #[cfg(not(target_os="android"))] - iotest!(fn test_inherit_env() { + #[test] + fn test_inherit_env() { use os; if running_on_valgrind() { return; } @@ -930,9 +960,10 @@ mod tests { output.as_slice() .contains(format!("{}={}", *k, *v).as_slice())); } - }) + } #[cfg(target_os="android")] - iotest!(fn test_inherit_env() { + #[test] + fn test_inherit_env() { use os; if running_on_valgrind() { return; } @@ -953,9 +984,10 @@ mod tests { *v).as_slice())); } } - }) + } - iotest!(fn test_override_env() { + #[test] + fn test_override_env() { use os; let mut new_env = vec![("RUN_TEST_NEW_ENV", "123")]; @@ -978,18 +1010,20 @@ mod tests { assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); - }) + } - iotest!(fn test_add_to_env() { + #[test] + fn test_add_to_env() { let prog = env_cmd().env("RUN_TEST_NEW_ENV", "123").spawn().unwrap(); let result = prog.wait_with_output().unwrap(); let output = str::from_utf8_lossy(result.output.as_slice()).into_string(); assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"), "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); - }) + } - iotest!(fn test_remove_from_env() { + #[test] + fn test_remove_from_env() { use os; // save original environment @@ -1012,7 +1046,7 @@ mod tests { assert!(!output.as_slice().contains("RUN_TEST_NEW_ENV"), "found RUN_TEST_NEW_ENV inside of:\n\n{}", output); - }) + } #[cfg(unix)] pub fn sleeper() -> Process { @@ -1026,20 +1060,23 @@ mod tests { Command::new("ping").arg("127.0.0.1").arg("-n").arg("1000").spawn().unwrap() } - iotest!(fn test_kill() { + #[test] + fn test_kill() { let mut p = sleeper(); Process::kill(p.id(), PleaseExitSignal).unwrap(); assert!(!p.wait().unwrap().success()); - }) + } - iotest!(fn test_exists() { + #[test] + fn test_exists() { let mut p = sleeper(); assert!(Process::kill(p.id(), 0).is_ok()); p.signal_kill().unwrap(); assert!(!p.wait().unwrap().success()); - }) + } - iotest!(fn test_zero() { + #[test] + fn test_zero() { let mut p = sleeper(); p.signal_kill().unwrap(); for _ in range(0i, 20) { @@ -1050,9 +1087,10 @@ mod tests { timer::sleep(Duration::milliseconds(100)); } fail!("never saw the child go away"); - }) + } - iotest!(fn wait_timeout() { + #[test] + fn wait_timeout() { let mut p = sleeper(); p.set_timeout(Some(10)); assert_eq!(p.wait().err().unwrap().kind, TimedOut); @@ -1060,9 +1098,10 @@ mod tests { p.signal_kill().unwrap(); p.set_timeout(None); assert!(p.wait().is_ok()); - }) + } - iotest!(fn wait_timeout2() { + #[test] + fn wait_timeout2() { let (tx, rx) = channel(); let tx2 = tx.clone(); spawn(proc() { @@ -1081,19 +1120,21 @@ mod tests { }); rx.recv(); rx.recv(); - }) + } - iotest!(fn forget() { + #[test] + fn forget() { let p = sleeper(); let id = p.id(); p.forget(); assert!(Process::kill(id, 0).is_ok()); assert!(Process::kill(id, PleaseExitSignal).is_ok()); - }) + } - iotest!(fn dont_close_fd_on_command_spawn() { + #[test] + fn dont_close_fd_on_command_spawn() { use std::rt::rtio::{Truncate, Write}; - use native::io::file; + use self::native::io::file; let path = if cfg!(windows) { Path::new("NUL") @@ -1110,7 +1151,7 @@ mod tests { let _ = cmd.stdout(InheritFd(fdes.fd())); assert!(cmd.status().unwrap().success()); assert!(fdes.inner_write("extra write\n".as_bytes()).is_ok()); - }) + } #[test] #[cfg(windows)] diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 03e48ab79b144..b174f19f19822 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -382,14 +382,17 @@ impl Writer for StdWriter { #[cfg(test)] mod tests { - iotest!(fn smoke() { + use super::*; + use prelude::*; + + fn smoke() { // Just make sure we can acquire handles stdin(); stdout(); stderr(); - }) + } - iotest!(fn capture_stdout() { + fn capture_stdout() { use io::{ChanReader, ChanWriter}; let (tx, rx) = channel(); @@ -399,9 +402,9 @@ mod tests { println!("hello!"); }); assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string()); - }) + } - iotest!(fn capture_stderr() { + fn capture_stderr() { use realstd::comm::channel; use realstd::io::{Writer, ChanReader, ChanWriter, Reader}; @@ -413,5 +416,5 @@ mod tests { }); let s = r.read_to_string().unwrap(); assert!(s.as_slice().contains("my special message")); - }) + } } diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index cfc5fb982b86c..1a47e20f58580 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -18,42 +18,6 @@ use prelude::*; use std::io::net::ip::*; use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; -macro_rules! iotest ( - { fn $name:ident() $b:block $(#[$a:meta])* } => ( - mod $name { - #![allow(unused_imports)] - - use super::super::*; - use super::*; - use io; - use prelude::*; - use io::*; - use io::fs::*; - use io::test::*; - use io::net::tcp::*; - use io::net::ip::*; - use io::net::udp::*; - #[cfg(unix)] - use io::net::pipe::*; - use io::timer::*; - use io::process::*; - use rt::running_on_valgrind; - use str; - use time::Duration; - - fn f() $b - - $(#[$a])* #[test] fn green() { f() } - $(#[$a])* #[test] fn native() { - use native; - let (tx, rx) = channel(); - native::task::spawn(proc() { tx.send(f()) }); - rx.recv(); - } - } - ) -) - /// Get a port number, starting at 9600, for use in tests pub fn next_test_port() -> u16 { static mut next_offset: AtomicUint = INIT_ATOMIC_UINT; diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index 39c6c74e45eef..55d4073154eea 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -232,55 +232,70 @@ fn in_ms_u64(d: Duration) -> u64 { #[cfg(test)] mod test { - iotest!(fn test_io_timer_sleep_simple() { + use super::*; + use time::Duration; + use task::spawn; + use io::*; + use prelude::*; + + #[test] + fn test_io_timer_sleep_simple() { let mut timer = Timer::new().unwrap(); timer.sleep(Duration::milliseconds(1)); - }) + } - iotest!(fn test_io_timer_sleep_oneshot() { + #[test] + fn test_io_timer_sleep_oneshot() { let mut timer = Timer::new().unwrap(); timer.oneshot(Duration::milliseconds(1)).recv(); - }) + } - iotest!(fn test_io_timer_sleep_oneshot_forget() { + #[test] + fn test_io_timer_sleep_oneshot_forget() { let mut timer = Timer::new().unwrap(); timer.oneshot(Duration::milliseconds(100000000)); - }) + } - iotest!(fn oneshot_twice() { + #[test] + fn oneshot_twice() { let mut timer = Timer::new().unwrap(); let rx1 = timer.oneshot(Duration::milliseconds(10000)); let rx = timer.oneshot(Duration::milliseconds(1)); rx.recv(); assert_eq!(rx1.recv_opt(), Err(())); - }) + } - iotest!(fn test_io_timer_oneshot_then_sleep() { + #[test] + fn test_io_timer_oneshot_then_sleep() { let mut timer = Timer::new().unwrap(); let rx = timer.oneshot(Duration::milliseconds(100000000)); timer.sleep(Duration::milliseconds(1)); // this should invalidate rx assert_eq!(rx.recv_opt(), Err(())); - }) + } - iotest!(fn test_io_timer_sleep_periodic() { + #[test] + fn test_io_timer_sleep_periodic() { let mut timer = Timer::new().unwrap(); let rx = timer.periodic(Duration::milliseconds(1)); rx.recv(); rx.recv(); rx.recv(); - }) + } - iotest!(fn test_io_timer_sleep_periodic_forget() { + #[test] + fn test_io_timer_sleep_periodic_forget() { let mut timer = Timer::new().unwrap(); timer.periodic(Duration::milliseconds(100000000)); - }) + } - iotest!(fn test_io_timer_sleep_standalone() { - sleep(Duration::milliseconds(1)) - }) + #[test] + fn test_io_timer_sleep_standalone() { + super::sleep(Duration::milliseconds(1)) + } - iotest!(fn oneshot() { + #[test] + fn oneshot() { let mut timer = Timer::new().unwrap(); let rx = timer.oneshot(Duration::milliseconds(1)); @@ -290,9 +305,10 @@ mod test { let rx = timer.oneshot(Duration::milliseconds(1)); rx.recv(); assert!(rx.recv_opt().is_err()); - }) + } - iotest!(fn override() { + #[test] + fn override() { let mut timer = Timer::new().unwrap(); let orx = timer.oneshot(Duration::milliseconds(100)); let prx = timer.periodic(Duration::milliseconds(100)); @@ -300,9 +316,10 @@ mod test { assert_eq!(orx.recv_opt(), Err(())); assert_eq!(prx.recv_opt(), Err(())); timer.oneshot(Duration::milliseconds(1)).recv(); - }) + } - iotest!(fn period() { + #[test] + fn period() { let mut timer = Timer::new().unwrap(); let rx = timer.periodic(Duration::milliseconds(1)); rx.recv(); @@ -310,32 +327,40 @@ mod test { let rx2 = timer.periodic(Duration::milliseconds(1)); rx2.recv(); rx2.recv(); - }) + } - iotest!(fn sleep() { + #[test] + fn sleep() { let mut timer = Timer::new().unwrap(); timer.sleep(Duration::milliseconds(1)); timer.sleep(Duration::milliseconds(1)); - }) + } - iotest!(fn oneshot_fail() { + #[test] + #[should_fail] + fn oneshot_fail() { let mut timer = Timer::new().unwrap(); let _rx = timer.oneshot(Duration::milliseconds(1)); fail!(); - } #[should_fail]) + } - iotest!(fn period_fail() { + #[test] + #[should_fail] + fn period_fail() { let mut timer = Timer::new().unwrap(); let _rx = timer.periodic(Duration::milliseconds(1)); fail!(); - } #[should_fail]) + } - iotest!(fn normal_fail() { + #[test] + #[should_fail] + fn normal_fail() { let _timer = Timer::new().unwrap(); fail!(); - } #[should_fail]) + } - iotest!(fn closing_channel_during_drop_doesnt_kill_everything() { + #[test] + fn closing_channel_during_drop_doesnt_kill_everything() { // see issue #10375 let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); @@ -346,9 +371,10 @@ mod test { // when we drop the TimerWatcher we're going to destroy the channel, // which must wake up the task on the other end - }) + } - iotest!(fn reset_doesnt_switch_tasks() { + #[test] + fn reset_doesnt_switch_tasks() { // similar test to the one above. let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); @@ -358,9 +384,10 @@ mod test { }); timer.oneshot(Duration::milliseconds(1)); - }) + } - iotest!(fn reset_doesnt_switch_tasks2() { + #[test] + fn reset_doesnt_switch_tasks2() { // similar test to the one above. let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); @@ -370,80 +397,90 @@ mod test { }); timer.sleep(Duration::milliseconds(1)); - }) + } - iotest!(fn sender_goes_away_oneshot() { + #[test] + fn sender_goes_away_oneshot() { let rx = { let mut timer = Timer::new().unwrap(); timer.oneshot(Duration::milliseconds(1000)) }; assert_eq!(rx.recv_opt(), Err(())); - }) + } - iotest!(fn sender_goes_away_period() { + #[test] + fn sender_goes_away_period() { let rx = { let mut timer = Timer::new().unwrap(); timer.periodic(Duration::milliseconds(1000)) }; assert_eq!(rx.recv_opt(), Err(())); - }) + } - iotest!(fn receiver_goes_away_oneshot() { + #[test] + fn receiver_goes_away_oneshot() { let mut timer1 = Timer::new().unwrap(); timer1.oneshot(Duration::milliseconds(1)); let mut timer2 = Timer::new().unwrap(); // while sleeping, the previous timer should fire and not have its // callback do something terrible. timer2.sleep(Duration::milliseconds(2)); - }) + } - iotest!(fn receiver_goes_away_period() { + #[test] + fn receiver_goes_away_period() { let mut timer1 = Timer::new().unwrap(); timer1.periodic(Duration::milliseconds(1)); let mut timer2 = Timer::new().unwrap(); // while sleeping, the previous timer should fire and not have its // callback do something terrible. timer2.sleep(Duration::milliseconds(2)); - }) + } - iotest!(fn sleep_zero() { + #[test] + fn sleep_zero() { let mut timer = Timer::new().unwrap(); timer.sleep(Duration::milliseconds(0)); - }) + } - iotest!(fn sleep_negative() { + #[test] + fn sleep_negative() { let mut timer = Timer::new().unwrap(); timer.sleep(Duration::milliseconds(-1000000)); - }) + } - iotest!(fn oneshot_zero() { + #[test] + fn oneshot_zero() { let mut timer = Timer::new().unwrap(); let rx = timer.oneshot(Duration::milliseconds(0)); rx.recv(); - }) + } - iotest!(fn oneshot_negative() { + #[test] + fn oneshot_negative() { let mut timer = Timer::new().unwrap(); let rx = timer.oneshot(Duration::milliseconds(-1000000)); rx.recv(); - }) + } - iotest!(fn periodic_zero() { + #[test] + fn periodic_zero() { let mut timer = Timer::new().unwrap(); let rx = timer.periodic(Duration::milliseconds(0)); rx.recv(); rx.recv(); rx.recv(); rx.recv(); - }) + } - iotest!(fn periodic_negative() { + #[test] + fn periodic_negative() { let mut timer = Timer::new().unwrap(); let rx = timer.periodic(Duration::milliseconds(-1000000)); rx.recv(); rx.recv(); rx.recv(); rx.recv(); - }) + } } diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs index 4bde2712140ef..6aaf91dee16c9 100644 --- a/src/test/run-pass/core-run-destroy.rs +++ b/src/test/run-pass/core-run-destroy.rs @@ -20,12 +20,8 @@ extern crate libc; -extern crate native; - use std::io::{Process, Command, timer}; use std::time::Duration; - -use libc; use std::str; macro_rules! succeed( ($e:expr) => ( diff --git a/src/test/run-pass/issue-12684.rs b/src/test/run-pass/issue-12684.rs index 536a72f9cb34e..c3aba9e8dc954 100644 --- a/src/test/run-pass/issue-12684.rs +++ b/src/test/run-pass/issue-12684.rs @@ -11,7 +11,7 @@ use std::time::Duration; fn main() { - native::task::spawn(proc() customtask()); + std::task::spawn(proc() customtask()); } fn customtask() { diff --git a/src/test/run-pass/process-detach.rs b/src/test/run-pass/process-detach.rs index f4ba9901560b8..569d4acb4c610 100644 --- a/src/test/run-pass/process-detach.rs +++ b/src/test/run-pass/process-detach.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-windows -// ignore-android +// ignore-test + +// FIXME: this test is being ignored until signals are implemented // This test ensures that the 'detach' field on processes does the right thing. // By detaching the child process, they should be put into a separate process diff --git a/src/test/run-pass/tcp-connect-timeouts.rs b/src/test/run-pass/tcp-connect-timeouts.rs index 167e89ffd3070..e186f63e0a45e 100644 --- a/src/test/run-pass/tcp-connect-timeouts.rs +++ b/src/test/run-pass/tcp-connect-timeouts.rs @@ -30,17 +30,13 @@ use std::time::Duration; #[cfg_attr(target_os = "freebsd", ignore)] fn eventual_timeout() { - use native; let addr = next_test_ip4(); let host = addr.ip.to_string(); let port = addr.port; - // Use a native task to receive connections because it turns out libuv is - // really good at accepting connections and will likely run out of file - // descriptors before timing out. let (tx1, rx1) = channel(); let (_tx2, rx2) = channel::<()>(); - native::task::spawn(proc() { + std::task::spawn(proc() { let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen(); tx1.send(()); let _ = rx2.recv_opt();