diff options
author | Bryant Mairs <bryantmairs@google.com> | 2017-12-15 15:22:01 -0800 |
---|---|---|
committer | Bryant Mairs <bryantmairs@google.com> | 2017-12-20 07:05:04 -0800 |
commit | 46fe1319a73a9d4c0081c2b5f8900d7943f3a44b (patch) | |
tree | 7d7547cf70e4e0f9adb3feb4bcdf167eeb668b1a | |
parent | 7b4402f091ccac878f3cbb772a6df20ba7a7a9e6 (diff) | |
download | nix-46fe1319a73a9d4c0081c2b5f8900d7943f3a44b.zip |
Remove useless Err(_) match arms
-rw-r--r-- | test/sys/test_ptrace.rs | 7 | ||||
-rw-r--r-- | test/sys/test_uio.rs | 7 | ||||
-rw-r--r-- | test/sys/test_wait.rs | 23 | ||||
-rw-r--r-- | test/test_stat.rs | 62 | ||||
-rw-r--r-- | test/test_unistd.rs | 17 |
5 files changed, 48 insertions, 68 deletions
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index d3e579f3..f31ba877 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -66,8 +66,8 @@ fn test_ptrace_cont() { return; } - match fork() { - Ok(Child) => { + match fork().expect("Error: Fork Failed") { + Child => { ptrace::traceme().unwrap(); // As recommended by ptrace(2), raise SIGTRAP to pause the child // until the parent is ready to continue @@ -76,7 +76,7 @@ fn test_ptrace_cont() { } }, - Ok(Parent { child }) => { + Parent { child } => { assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); ptrace::cont(child, None).unwrap(); assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); @@ -86,6 +86,5 @@ fn test_ptrace_cont() { _ => panic!("The process should have been killed"), } }, - Err(_) => panic!("Error: Fork Failed") } } diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 262874b3..8c326a38 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -208,8 +208,8 @@ fn test_process_vm_readv() { let mut vector = vec![1u8, 2, 3, 4, 5]; let (r, w) = pipe().unwrap(); - match fork() { - Ok(Parent { child }) => { + match fork().expect("Error: Fork Failed") { + Parent { child } => { close(w).unwrap(); // wait for child read(r, &mut [0u8]).unwrap(); @@ -229,7 +229,7 @@ fn test_process_vm_readv() { assert_eq!(Ok(5), ret); assert_eq!(20u8, buf.iter().sum()); }, - Ok(Child) => { + Child => { let _ = close(r); for i in vector.iter_mut() { *i += 1; @@ -238,6 +238,5 @@ fn test_process_vm_readv() { let _ = close(w); loop { let _ = pause(); } }, - Err(_) => panic!("fork failed") } } diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index e834f9f0..9992607c 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -11,14 +11,12 @@ fn test_wait_signal() { let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: The child only calls `pause` and/or `_exit`, which are async-signal-safe. - match fork() { - Ok(Child) => pause().unwrap_or_else(|_| unsafe { _exit(123) }), - Ok(Parent { child }) => { + match fork().expect("Error: Fork Failed") { + Child => pause().unwrap_or_else(|_| unsafe { _exit(123) }), + Parent { child } => { kill(child, Some(SIGKILL)).expect("Error: Kill Failed"); assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, SIGKILL, false))); }, - // panic, fork should never fail unless there is a serious problem with the OS - Err(_) => panic!("Error: Fork Failed") } } @@ -28,13 +26,11 @@ fn test_wait_exit() { let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is async-signal-safe. - match fork() { - Ok(Child) => unsafe { _exit(12); }, - Ok(Parent { child }) => { + match fork().expect("Error: Fork Failed") { + Child => unsafe { _exit(12); }, + Parent { child } => { assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 12))); }, - // panic, fork should never fail unless there is a serious problem with the OS - Err(_) => panic!("Error: Fork Failed") } } @@ -100,10 +96,9 @@ mod ptrace { #[allow(unused_variables)] let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); - match fork() { - Ok(Child) => ptrace_child(), - Ok(Parent { child }) => ptrace_parent(child), - Err(_) => panic!("Error: Fork Failed") + match fork().expect("Error: Fork Failed") { + Child => ptrace_child(), + Parent { child } => ptrace_parent(child), } } } diff --git a/test/test_stat.rs b/test/test_stat.rs index 900def89..a65778ea 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -21,44 +21,36 @@ fn valid_uid_gid(stat: FileStat) -> bool { } fn assert_stat_results(stat_result: Result<FileStat>) { - match stat_result { - Ok(stats) => { - assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent - assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent - assert!(stats.st_mode > 0); // must be positive integer - assert!(stats.st_nlink == 1); // there links created, must be 1 - assert!(valid_uid_gid(stats)); // must be positive integers - assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file - assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent - assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file - } - Err(_) => panic!("stat call failed") // if stats system call fails, something is seriously wrong on that machine - } + let stats = stat_result.expect("stat call failed"); + assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent + assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent + assert!(stats.st_mode > 0); // must be positive integer + assert!(stats.st_nlink == 1); // there links created, must be 1 + assert!(valid_uid_gid(stats)); // must be positive integers + assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file + assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent + assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file } fn assert_lstat_results(stat_result: Result<FileStat>) { - match stat_result { - Ok(stats) => { - assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent - assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent - assert!(stats.st_mode > 0); // must be positive integer - - // st_mode is c_uint (u32 on Android) while S_IFMT is mode_t - // (u16 on Android), and that will be a compile error. - // On other platforms they are the same (either both are u16 or u32). - assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link - assert!(stats.st_nlink == 1); // there links created, must be 1 - assert!(valid_uid_gid(stats)); // must be positive integers - assert!(stats.st_size > 0); // size is > 0 because it points to another file - assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent - - // st_blocks depends on whether the machine's file system uses fast - // or slow symlinks, so just make sure it's not negative - // (Android's st_blocks is ulonglong which is always non-negative.) - assert!(stats.st_blocks >= 0); - } - Err(_) => panic!("stat call failed") // if stats system call fails, something is seriously wrong on that machine - } + let stats = stat_result.expect("stat call failed"); + assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent + assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent + assert!(stats.st_mode > 0); // must be positive integer + + // st_mode is c_uint (u32 on Android) while S_IFMT is mode_t + // (u16 on Android), and that will be a compile error. + // On other platforms they are the same (either both are u16 or u32). + assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link + assert!(stats.st_nlink == 1); // there links created, must be 1 + assert!(valid_uid_gid(stats)); // must be positive integers + assert!(stats.st_size > 0); // size is > 0 because it points to another file + assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent + + // st_blocks depends on whether the machine's file system uses fast + // or slow symlinks, so just make sure it's not negative + // (Android's st_blocks is ulonglong which is always non-negative.) + assert!(stats.st_blocks >= 0); } #[test] diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 7c26210c..e15fec17 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -20,9 +20,9 @@ fn test_fork_and_waitpid() { let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is signal-safe - match fork() { - Ok(Child) => unsafe { _exit(0) }, - Ok(Parent { child }) => { + match fork().expect("Error: Fork Failed") { + Child => unsafe { _exit(0) }, + Parent { child } => { // assert that child was created and pid > 0 let child_raw: ::libc::pid_t = child.into(); assert!(child_raw > 0); @@ -39,8 +39,6 @@ fn test_fork_and_waitpid() { } }, - // panic, fork should never fail unless there is a serious problem with the OS - Err(_) => panic!("Error: Fork Failed") } } @@ -51,17 +49,14 @@ fn test_wait() { let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); // Safe: Child only calls `_exit`, which is signal-safe - let pid = fork(); - match pid { - Ok(Child) => unsafe { _exit(0) }, - Ok(Parent { child }) => { + match fork().expect("Error: Fork Failed") { + Child => unsafe { _exit(0) }, + Parent { child } => { let wait_status = wait(); // just assert that (any) one child returns with WaitStatus::Exited assert_eq!(wait_status, Ok(WaitStatus::Exited(child, 0))); }, - // panic, fork should never fail unless there is a serious problem with the OS - Err(_) => panic!("Error: Fork Failed") } } |