about summary refs log tree commit diff
path: root/src/libstd/run.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-01-30 14:10:53 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-03 09:32:34 -0800
commit209642c65177d6cf42dd4eea693040aa91cde9ee (patch)
treeb9c7c1c2382c978a53b6dd3f1c6c6fccb116cf0a /src/libstd/run.rs
parent29e7247fd8be5a9879ebcd1a3ddc47e2fa743abd (diff)
std: Fix tests with io_error usage
Diffstat (limited to 'src/libstd/run.rs')
-rw-r--r--src/libstd/run.rs81
1 files changed, 33 insertions, 48 deletions
diff --git a/src/libstd/run.rs b/src/libstd/run.rs
index fe4693a079f..04e42b3eedf 100644
--- a/src/libstd/run.rs
+++ b/src/libstd/run.rs
@@ -11,6 +11,7 @@
 //! Utilities for spawning and managing processes
 
 #[allow(missing_doc)];
+#[deny(unused_must_use)];
 
 use comm::SharedChan;
 use io::Reader;
@@ -258,10 +259,10 @@ impl Process {
      * On Posix OSs SIGTERM will be sent to the process. On Win32
      * TerminateProcess(..) will be called.
      */
-    pub fn destroy(&mut self) {
-        // This should never fail because we own the process
-        self.inner.signal(io::process::PleaseExitSignal).unwrap();
+    pub fn destroy(&mut self) -> io::IoResult<()> {
+        let ret = self.inner.signal(io::process::PleaseExitSignal);
         self.finish();
+        return ret;
     }
 
     /**
@@ -271,10 +272,11 @@ impl Process {
      * On Posix OSs SIGKILL will be sent to the process. On Win32
      * TerminateProcess(..) will be called.
      */
-    pub fn force_destroy(&mut self) {
+    pub fn force_destroy(&mut self) -> io::IoResult<()> {
         // This should never fail because we own the process
-        self.inner.signal(io::process::MustDieSignal).unwrap();
+        let ret = self.inner.signal(io::process::MustDieSignal);
         self.finish();
+        return ret;
 
     }
 }
@@ -330,33 +332,25 @@ mod tests {
     use task::spawn;
     use unstable::running_on_valgrind;
     use io::pipe::PipeStream;
-    use io::{io_error, FileNotFound};
+    use io::{FileNotFound};
     use libc::c_int;
 
     #[test]
     #[cfg(not(target_os="android"))] // FIXME(#10380)
     fn test_process_status() {
-        let mut status = run::process_status("false", []).expect("failed to exec `false`");
+        let mut status = run::process_status("false", []).unwrap();
         assert!(status.matches_exit_status(1));
 
-        status = run::process_status("true", []).expect("failed to exec `true`");
+        status = run::process_status("true", []).unwrap();
         assert!(status.success());
     }
 
     #[test]
     fn test_process_output_fail_to_start() {
-        // If the executable does not exist, then the io_error condition should be raised with
-        // IoErrorKind FileNotFound.
-
-        let mut trapped_io_error = false;
-        let opt_outp = io_error::cond.trap(|e| {
-            trapped_io_error = true;
-            assert_eq!(e.kind, FileNotFound);
-        }).inside(|| -> Option<run::ProcessOutput> {
-            run::process_output("/no-binary-by-this-name-should-exist", [])
-        });
-        assert!(trapped_io_error);
-        assert!(opt_outp.is_none());
+        match run::process_output("/no-binary-by-this-name-should-exist", []) {
+            Err(e) => assert_eq!(e.kind, FileNotFound),
+            Ok(..) => fail!()
+        }
     }
 
     #[test]
@@ -364,7 +358,7 @@ mod tests {
     fn test_process_output_output() {
 
         let run::ProcessOutput {status, output, error}
-             = run::process_output("echo", [~"hello"]).expect("failed to exec `echo`");
+             = run::process_output("echo", [~"hello"]).unwrap();
         let output_str = str::from_utf8_owned(output).unwrap();
 
         assert!(status.success());
@@ -380,7 +374,7 @@ mod tests {
     fn test_process_output_error() {
 
         let run::ProcessOutput {status, output, error}
-             = run::process_output("mkdir", [~"."]).expect("failed to exec `mkdir`");
+             = run::process_output("mkdir", [~"."]).unwrap();
 
         assert!(status.matches_exit_status(1));
         assert_eq!(output, ~[]);
@@ -401,7 +395,7 @@ mod tests {
             in_fd: Some(pipe_in.input),
             out_fd: Some(pipe_out.out),
             err_fd: Some(pipe_err.out)
-        }).expect("failed to exec `cat`");
+        }).unwrap();
 
         os::close(pipe_in.input as int);
         os::close(pipe_out.out as int);
@@ -419,27 +413,18 @@ mod tests {
 
     fn writeclose(fd: c_int, s: &str) {
         let mut writer = PipeStream::open(fd);
-        writer.write(s.as_bytes());
+        writer.write(s.as_bytes()).unwrap();
     }
 
     fn readclose(fd: c_int) -> ~str {
-        let mut res = ~[];
-        let mut reader = PipeStream::open(fd);
-        let mut buf = [0, ..1024];
-        loop {
-            match reader.read(buf) {
-                Some(n) => { res.push_all(buf.slice_to(n)); }
-                None => break
-            }
-        }
-        str::from_utf8_owned(res).unwrap()
+        PipeStream::open(fd).read_to_str().unwrap()
     }
 
     #[test]
     #[cfg(not(target_os="android"))] // FIXME(#10380)
     fn test_finish_once() {
         let mut prog = run::Process::new("false", [], run::ProcessOptions::new())
-            .expect("failed to exec `false`");
+            .unwrap();
         assert!(prog.finish().matches_exit_status(1));
     }
 
@@ -447,7 +432,7 @@ mod tests {
     #[cfg(not(target_os="android"))] // FIXME(#10380)
     fn test_finish_twice() {
         let mut prog = run::Process::new("false", [], run::ProcessOptions::new())
-            .expect("failed to exec `false`");
+            .unwrap();
         assert!(prog.finish().matches_exit_status(1));
         assert!(prog.finish().matches_exit_status(1));
     }
@@ -457,7 +442,7 @@ mod tests {
     fn test_finish_with_output_once() {
 
         let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new())
-            .expect("failed to exec `echo`");
+            .unwrap();
         let run::ProcessOutput {status, output, error}
             = prog.finish_with_output();
         let output_str = str::from_utf8_owned(output).unwrap();
@@ -475,7 +460,7 @@ mod tests {
     fn test_finish_with_output_twice() {
 
         let mut prog = run::Process::new("echo", [~"hello"], run::ProcessOptions::new())
-            .expect("failed to exec `echo`");
+            .unwrap();
         let run::ProcessOutput {status, output, error}
             = prog.finish_with_output();
 
@@ -504,14 +489,14 @@ mod tests {
         run::Process::new("pwd", [], run::ProcessOptions {
             dir: dir,
             .. run::ProcessOptions::new()
-        }).expect("failed to exec `pwd`")
+        }).unwrap()
     }
     #[cfg(unix,target_os="android")]
     fn run_pwd(dir: Option<&Path>) -> run::Process {
         run::Process::new("/system/bin/sh", [~"-c",~"pwd"], run::ProcessOptions {
             dir: dir,
             .. run::ProcessOptions::new()
-        }).expect("failed to exec `/system/bin/sh`")
+        }).unwrap()
     }
 
     #[cfg(windows)]
@@ -519,7 +504,7 @@ mod tests {
         run::Process::new("cmd", [~"/c", ~"cd"], run::ProcessOptions {
             dir: dir,
             .. run::ProcessOptions::new()
-        }).expect("failed to run `cmd`")
+        }).unwrap()
     }
 
     #[test]
@@ -530,8 +515,8 @@ mod tests {
         let parent_dir = os::getcwd();
         let child_dir = Path::new(output.trim());
 
-        let parent_stat = parent_dir.stat();
-        let child_stat = child_dir.stat();
+        let parent_stat = parent_dir.stat().unwrap();
+        let child_stat = child_dir.stat().unwrap();
 
         assert_eq!(parent_stat.unstable.device, child_stat.unstable.device);
         assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode);
@@ -547,8 +532,8 @@ mod tests {
         let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
         let child_dir = Path::new(output.trim());
 
-        let parent_stat = parent_dir.stat();
-        let child_stat = child_dir.stat();
+        let parent_stat = parent_dir.stat().unwrap();
+        let child_stat = child_dir.stat().unwrap();
 
         assert_eq!(parent_stat.unstable.device, child_stat.unstable.device);
         assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode);
@@ -559,14 +544,14 @@ mod tests {
         run::Process::new("env", [], run::ProcessOptions {
             env: env,
             .. run::ProcessOptions::new()
-        }).expect("failed to exec `env`")
+        }).unwrap()
     }
     #[cfg(unix,target_os="android")]
     fn run_env(env: Option<~[(~str, ~str)]>) -> run::Process {
         run::Process::new("/system/bin/sh", [~"-c",~"set"], run::ProcessOptions {
             env: env,
             .. run::ProcessOptions::new()
-        }).expect("failed to exec `/system/bin/sh`")
+        }).unwrap()
     }
 
     #[cfg(windows)]
@@ -574,7 +559,7 @@ mod tests {
         run::Process::new("cmd", [~"/c", ~"set"], run::ProcessOptions {
             env: env,
             .. run::ProcessOptions::new()
-        }).expect("failed to run `cmd`")
+        }).unwrap()
     }
 
     #[test]