1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #5595 from cakebaker/cut_too_long_delimiter

cut: add test & improve error message if the delimiter is too long
This commit is contained in:
Sylvestre Ledru 2023-11-29 12:52:13 +01:00 committed by GitHub
commit 571ca3cbd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -426,7 +426,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
delim = "";
}
if delim.chars().count() > 1 {
Err("invalid input: The '--delimiter' ('-d') option expects empty or 1 character long, but was provided a value 2 characters or longer".into())
Err("the delimiter must be a single character".into())
} else {
let delim = if delim.is_empty() {
"\0".to_owned()

View file

@ -126,7 +126,7 @@ fn test_too_large() {
}
#[test]
fn test_specify_delimiter() {
fn test_delimiter() {
for param in ["-d", "--delimiter", "--del"] {
new_ucmd!()
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
@ -135,6 +135,15 @@ fn test_specify_delimiter() {
}
}
#[test]
fn test_delimiter_with_more_than_one_char() {
new_ucmd!()
.args(&["-d", "ab", "-f1"])
.fails()
.stderr_contains("cut: the delimiter must be a single character")
.no_stdout();
}
#[test]
fn test_output_delimiter() {
// we use -d here to ensure output delimiter