| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
#[cfg(unix)] |
| 7 |
use std::fs::File; |
| 8 |
|
| 9 |
use uutests::new_ucmd; |
| 10 |
|
| 11 |
#[test] |
| 12 |
#[cfg(unix)] |
| 13 |
fn test_dev_null() { |
| 14 |
new_ucmd!() |
| 15 |
.set_stdin(File::open("/dev/null").unwrap()) |
| 16 |
.fails_with_code(1) |
| 17 |
.stdout_is("not a tty\n"); |
| 18 |
} |
| 19 |
|
| 20 |
#[test] |
| 21 |
#[cfg(unix)] |
| 22 |
fn test_dev_null_silent() { |
| 23 |
new_ucmd!() |
| 24 |
.args(&["-s"]) |
| 25 |
.set_stdin(File::open("/dev/null").unwrap()) |
| 26 |
.fails_with_code(1) |
| 27 |
.no_output(); |
| 28 |
} |
| 29 |
|
| 30 |
#[test] |
| 31 |
#[cfg(unix)] |
| 32 |
fn test_close_stdin() { |
| 33 |
let mut child = new_ucmd!().run_no_wait(); |
| 34 |
child.close_stdin(); |
| 35 |
child.wait().unwrap().code_is(1).stdout_is("not a tty\n"); |
| 36 |
} |
| 37 |
|
| 38 |
#[test] |
| 39 |
#[cfg(unix)] |
| 40 |
fn test_close_stdin_silent() { |
| 41 |
let mut child = new_ucmd!().arg("-s").run_no_wait(); |
| 42 |
child.close_stdin(); |
| 43 |
child.wait().unwrap().code_is(1).no_stdout(); |
| 44 |
} |
| 45 |
|
| 46 |
#[test] |
| 47 |
#[cfg(unix)] |
| 48 |
fn test_close_stdin_silent_long() { |
| 49 |
let mut child = new_ucmd!().arg("--silent").run_no_wait(); |
| 50 |
child.close_stdin(); |
| 51 |
child.wait().unwrap().code_is(1).no_stdout(); |
| 52 |
} |
| 53 |
|
| 54 |
#[test] |
| 55 |
#[cfg(unix)] |
| 56 |
fn test_close_stdin_silent_alias() { |
| 57 |
let mut child = new_ucmd!().arg("--quiet").run_no_wait(); |
| 58 |
child.close_stdin(); |
| 59 |
child.wait().unwrap().code_is(1).no_stdout(); |
| 60 |
} |
| 61 |
|
| 62 |
#[test] |
| 63 |
fn test_wrong_argument() { |
| 64 |
new_ucmd!().args(&["a"]).fails_with_code(2); |
| 65 |
} |
| 66 |
|
| 67 |
#[test] |
| 68 |
fn test_help() { |
| 69 |
new_ucmd!().args(&["--help"]).succeeds(); |
| 70 |
} |
| 71 |
|
| 72 |
#[test] |
| 73 |
// FixME: freebsd panic |
| 74 |
#[cfg(all(unix, not(target_os = "freebsd")))] |
| 75 |
fn test_stdout_fail() { |
| 76 |
use std::process::{Command, Stdio}; |
| 77 |
use uutests::at_and_ts; |
| 78 |
|
| 79 |
let (_, ts) = at_and_ts!(); |
| 80 |
// Sleep inside a shell to ensure the process doesn't finish before we've |
| 81 |
// closed its stdout |
| 82 |
let mut proc = Command::new("sh") |
| 83 |
.arg("-c") |
| 84 |
.arg(format!( |
| 85 |
"sleep 0.2; exec {} {}", |
| 86 |
ts.bin_path.to_str().unwrap(), |
| 87 |
ts.util_name |
| 88 |
)) |
| 89 |
.stdout(Stdio::piped()) |
| 90 |
.spawn() |
| 91 |
.unwrap(); |
| 92 |
drop(proc.stdout.take()); |
| 93 |
let status = proc.wait().unwrap(); |
| 94 |
assert_eq!(status.code(), Some(3)); |
| 95 |
} |
| 96 |
|
| 97 |
#[test] |
| 98 |
#[cfg(unix)] |
| 99 |
fn test_version_pipe_no_stderr() { |
| 100 |
let mut child = new_ucmd!().arg("--version").run_no_wait(); |
| 101 |
child.close_stdout(); |
| 102 |
child.wait().unwrap().no_stderr(); |
| 103 |
} |
| 104 |
|
| 105 |
#[test] |
| 106 |
#[cfg(target_os = "linux")] |
| 107 |
fn test_write_error() { |
| 108 |
let dev_full = std::fs::OpenOptions::new() |
| 109 |
.write(true) |
| 110 |
.open("/dev/full") |
| 111 |
.unwrap(); |
| 112 |
|
| 113 |
new_ucmd!() |
| 114 |
.set_stdout(dev_full) |
| 115 |
.fails() |
| 116 |
.stderr_is("tty: No space left on device\n"); |
| 117 |
} |