From 76308dbec9f0538a17c443a01a241cf120c6177e Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sun, 4 Apr 2021 22:35:22 +0200 Subject: [PATCH] ls: tests for invalid patterns for hide and ignore --- src/uu/ls/src/ls.rs | 4 ++-- tests/by-util/test_ls.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index e011b9e52..1e6e300ff 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -449,7 +449,7 @@ impl Config { for pattern in options.values_of(options::IGNORE).into_iter().flatten() { match glob::Pattern::new(pattern) { Ok(p) => ignore_patterns.push(p), - Err(e) => show_error!("{}", e), + Err(_) => show_error!("Invalid pattern for ignore: '{}'", pattern), } } @@ -457,7 +457,7 @@ impl Config { for pattern in options.values_of(options::HIDE).into_iter().flatten() { match glob::Pattern::new(pattern) { Ok(p) => ignore_patterns.push(p), - Err(e) => show_error!("{}", e), + Err(_) => show_error!("Invalid pattern for hide: '{}'", pattern), } } } diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 7d678acea..377e12f74 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -1288,4 +1288,29 @@ fn test_ls_ignore_hide() { .arg("*.md") .succeeds() .stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n"); + + // Stacking multiple patterns + scene + .ucmd() + .arg("--ignore") + .arg("README*") + .arg("--ignore") + .arg("CONTRIBUTING*") + .succeeds() + .stdout_is("some_other_file\n"); + + // Invalid patterns + scene + .ucmd() + .arg("--ignore") + .arg("READ[ME") + .succeeds() + .stderr_contains(&"Invalid pattern"); + + scene + .ucmd() + .arg("--ignore") + .arg("READ[ME") + .succeeds() + .stderr_contains(&"Invalid pattern"); }