Files

98 lines
2.3 KiB
Rust
Raw Permalink Normal View History

2023-08-21 10:49:27 +02:00
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
2021-06-16 17:16:28 +02:00
use std::fs::File;
2025-03-28 09:51:51 +01:00
use uutests::new_ucmd;
2021-03-29 13:00:47 +02:00
#[test]
#[cfg(not(windows))]
fn test_dev_null() {
new_ucmd!()
2021-06-16 17:16:28 +02:00
.set_stdin(File::open("/dev/null").unwrap())
2025-03-01 15:29:11 +01:00
.fails_with_code(1)
2021-03-29 13:00:47 +02:00
.stdout_is("not a tty\n");
}
#[test]
#[cfg(not(windows))]
fn test_dev_null_silent() {
new_ucmd!()
.args(&["-s"])
2021-06-16 17:16:28 +02:00
.set_stdin(File::open("/dev/null").unwrap())
2025-03-01 15:29:11 +01:00
.fails_with_code(1)
2021-03-29 13:00:47 +02:00
.stdout_is("");
}
#[test]
fn test_close_stdin() {
2021-06-16 17:16:28 +02:00
let mut child = new_ucmd!().run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).stdout_is("not a tty\n");
2021-03-29 13:00:47 +02:00
}
#[test]
fn test_close_stdin_silent() {
2021-06-16 17:16:28 +02:00
let mut child = new_ucmd!().arg("-s").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
2021-03-29 13:00:47 +02:00
}
#[test]
fn test_close_stdin_silent_long() {
2021-06-16 17:16:28 +02:00
let mut child = new_ucmd!().arg("--silent").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
2021-03-29 13:00:47 +02:00
}
#[test]
fn test_close_stdin_silent_alias() {
2021-06-16 17:16:28 +02:00
let mut child = new_ucmd!().arg("--quiet").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
2021-03-29 13:00:47 +02:00
}
#[test]
fn test_wrong_argument() {
2025-03-01 15:29:11 +01:00
new_ucmd!().args(&["a"]).fails_with_code(2);
2021-03-29 13:00:47 +02:00
}
2021-06-16 17:38:07 +02:00
#[test]
fn test_help() {
new_ucmd!().args(&["--help"]).succeeds();
}
2021-06-16 17:38:07 +02:00
#[test]
2021-08-24 08:53:20 +02:00
// FixME: freebsd panic
2021-08-27 18:10:13 +02:00
#[cfg(all(unix, not(target_os = "freebsd")))]
2021-06-16 17:38:07 +02:00
fn test_stdout_fail() {
2021-08-27 18:10:13 +02:00
use std::process::{Command, Stdio};
2025-07-01 01:52:57 +02:00
use uutests::at_and_ts;
let (_, ts) = at_and_ts!();
2021-08-27 18:10:13 +02:00
// Sleep inside a shell to ensure the process doesn't finish before we've
// closed its stdout
let mut proc = Command::new("sh")
.arg("-c")
.arg(format!(
"sleep 0.2; exec {} {}",
ts.bin_path.to_str().unwrap(),
ts.util_name
))
.stdout(Stdio::piped())
.spawn()
.unwrap();
drop(proc.stdout.take());
let status = proc.wait().unwrap();
2021-06-16 17:38:07 +02:00
assert_eq!(status.code(), Some(3));
}
#[test]
#[cfg(unix)]
fn test_version_pipe_no_stderr() {
let mut child = new_ucmd!().arg("--version").run_no_wait();
child.close_stdout();
child.wait().unwrap().no_stderr();
}