1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-16 02:01:05 +00:00
uutils-coreutils/tests/by-util/test_tty.rs
Sylvestre Ledru 18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00

87 lines
2.1 KiB
Rust

// 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.
use std::fs::File;
use crate::common::util::TestScenario;
#[test]
#[cfg(not(windows))]
fn test_dev_null() {
new_ucmd!()
.set_stdin(File::open("/dev/null").unwrap())
.fails_with_code(1)
.stdout_is("not a tty\n");
}
#[test]
#[cfg(not(windows))]
fn test_dev_null_silent() {
new_ucmd!()
.args(&["-s"])
.set_stdin(File::open("/dev/null").unwrap())
.fails_with_code(1)
.stdout_is("");
}
#[test]
fn test_close_stdin() {
let mut child = new_ucmd!().run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).stdout_is("not a tty\n");
}
#[test]
fn test_close_stdin_silent() {
let mut child = new_ucmd!().arg("-s").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
}
#[test]
fn test_close_stdin_silent_long() {
let mut child = new_ucmd!().arg("--silent").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
}
#[test]
fn test_close_stdin_silent_alias() {
let mut child = new_ucmd!().arg("--quiet").run_no_wait();
child.close_stdin();
child.wait().unwrap().code_is(1).no_stdout();
}
#[test]
fn test_wrong_argument() {
new_ucmd!().args(&["a"]).fails_with_code(2);
}
#[test]
fn test_help() {
new_ucmd!().args(&["--help"]).succeeds();
}
#[test]
// FixME: freebsd panic
#[cfg(all(unix, not(target_os = "freebsd")))]
fn test_stdout_fail() {
use std::process::{Command, Stdio};
let ts = TestScenario::new(util_name!());
// 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();
assert_eq!(status.code(), Some(3));
}