2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2023-02-21 20:52:18 +00:00
|
|
|
use is_terminal::IsTerminal;
|
2023-05-24 11:28:30 +00:00
|
|
|
|
2020-05-11 08:44:12 +00:00
|
|
|
#[test]
|
|
|
|
fn test_more_no_arg() {
|
2021-04-24 17:02:03 +00:00
|
|
|
// Reading from stdin is now supported, so this must succeed
|
2023-02-21 20:52:18 +00:00
|
|
|
if std::io::stdout().is_terminal() {
|
2021-04-24 17:02:03 +00:00
|
|
|
new_ucmd!().succeeds();
|
2021-05-31 03:55:28 +00:00
|
|
|
}
|
2020-05-11 08:44:12 +00:00
|
|
|
}
|
2021-04-02 20:34:02 +00:00
|
|
|
|
2023-05-17 18:38:03 +00:00
|
|
|
#[test]
|
|
|
|
fn test_valid_arg() {
|
2023-05-18 07:18:33 +00:00
|
|
|
if std::io::stdout().is_terminal() {
|
2023-05-20 06:56:50 +00:00
|
|
|
new_ucmd!().arg("-c").succeeds();
|
|
|
|
new_ucmd!().arg("--print-over").succeeds();
|
2023-05-17 18:38:03 +00:00
|
|
|
|
2023-05-20 06:56:50 +00:00
|
|
|
new_ucmd!().arg("-p").succeeds();
|
|
|
|
new_ucmd!().arg("--clean-print").succeeds();
|
2023-05-26 22:04:04 +00:00
|
|
|
|
|
|
|
new_ucmd!().arg("-s").succeeds();
|
|
|
|
new_ucmd!().arg("--squeeze").succeeds();
|
2023-05-29 12:36:18 +00:00
|
|
|
|
2023-06-05 16:48:45 +00:00
|
|
|
new_ucmd!().arg("-u").succeeds();
|
|
|
|
new_ucmd!().arg("--plain").succeeds();
|
|
|
|
|
2023-05-29 12:36:18 +00:00
|
|
|
new_ucmd!().arg("-n").arg("10").succeeds();
|
|
|
|
new_ucmd!().arg("--lines").arg("0").succeeds();
|
|
|
|
new_ucmd!().arg("--number").arg("0").succeeds();
|
2023-06-05 16:48:45 +00:00
|
|
|
|
|
|
|
new_ucmd!().arg("-F").arg("10").succeeds();
|
|
|
|
new_ucmd!().arg("--from-line").arg("0").succeeds();
|
2023-05-29 12:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
if std::io::stdout().is_terminal() {
|
|
|
|
new_ucmd!().arg("--invalid").fails();
|
|
|
|
|
|
|
|
new_ucmd!().arg("--lines").arg("-10").fails();
|
|
|
|
new_ucmd!().arg("--number").arg("-10").fails();
|
2023-06-05 16:48:45 +00:00
|
|
|
|
|
|
|
new_ucmd!().arg("--from-line").arg("-10").fails();
|
2023-05-18 07:18:33 +00:00
|
|
|
}
|
2023-05-17 18:38:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 20:03:44 +00:00
|
|
|
#[test]
|
|
|
|
fn test_argument_from_file() {
|
|
|
|
if std::io::stdout().is_terminal() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let file = "test_file";
|
|
|
|
|
|
|
|
at.write(file, "1\n2");
|
|
|
|
|
|
|
|
// output all lines
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-F")
|
|
|
|
.arg("0")
|
|
|
|
.arg(file)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr()
|
|
|
|
.stdout_contains("1")
|
|
|
|
.stdout_contains("2");
|
|
|
|
|
|
|
|
// output only the second line
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-F")
|
|
|
|
.arg("2")
|
|
|
|
.arg(file)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr()
|
|
|
|
.stdout_contains("2")
|
|
|
|
.stdout_does_not_contain("1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 20:34:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_more_dir_arg() {
|
2021-05-30 05:10:54 +00:00
|
|
|
// Run the test only if there's a valid terminal, else do nothing
|
2021-04-24 17:02:03 +00:00
|
|
|
// Maybe we could capture the error, i.e. "Device not found" in that case
|
|
|
|
// but I am leaving this for later
|
2023-02-21 20:52:18 +00:00
|
|
|
if std::io::stdout().is_terminal() {
|
2021-11-09 20:23:41 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(".")
|
|
|
|
.fails()
|
|
|
|
.usage_error("'.' is a directory.");
|
2021-05-31 03:55:28 +00:00
|
|
|
}
|
2021-04-02 20:34:02 +00:00
|
|
|
}
|
2023-05-23 16:03:25 +00:00
|
|
|
|
|
|
|
#[test]
|
2023-05-24 11:28:30 +00:00
|
|
|
#[cfg(target_family = "unix")]
|
2023-05-23 16:03:25 +00:00
|
|
|
fn test_more_invalid_file_perms() {
|
2023-05-24 14:32:29 +00:00
|
|
|
use std::fs::{set_permissions, Permissions};
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
2023-05-24 11:28:30 +00:00
|
|
|
if std::io::stdout().is_terminal() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let permissions = Permissions::from_mode(0o244);
|
2023-05-24 13:57:55 +00:00
|
|
|
at.make_file("invalid-perms.txt");
|
2023-05-24 11:28:30 +00:00
|
|
|
set_permissions(at.plus("invalid-perms.txt"), permissions).unwrap();
|
2023-05-24 14:32:29 +00:00
|
|
|
ucmd.arg("invalid-perms.txt")
|
|
|
|
.fails()
|
|
|
|
.code_is(1)
|
|
|
|
.stderr_contains("permission denied");
|
2023-05-24 11:28:30 +00:00
|
|
|
}
|
2023-05-23 16:03:25 +00:00
|
|
|
}
|