diff --git a/tests/by-util/test_more.rs b/tests/by-util/test_more.rs index 3e9c426ad..3a5eb58b0 100644 --- a/tests/by-util/test_more.rs +++ b/tests/by-util/test_more.rs @@ -34,6 +34,9 @@ fn test_valid_arg() { new_ucmd!().arg("-F").arg("10").succeeds(); new_ucmd!().arg("--from-line").arg("0").succeeds(); + + new_ucmd!().arg("-P").arg("something").succeeds(); + new_ucmd!().arg("--pattern").arg("-1").succeeds(); } } @@ -151,3 +154,50 @@ fn test_more_error_on_multiple_files() { .stderr_contains("file3"); } } + +#[test] +fn test_more_pattern_found() { + if std::io::stdout().is_terminal() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + let file = "test_file"; + + at.write(file, "line1\nline2"); + + // output only the second line "line2" + scene + .ucmd() + .arg("-P") + .arg("line2") + .arg(file) + .succeeds() + .no_stderr() + .stdout_does_not_contain("line1") + .stdout_contains("line2"); + } +} + +#[test] +fn test_more_pattern_not_found() { + if std::io::stdout().is_terminal() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + let file = "test_file"; + + let file_content = "line1\nline2"; + at.write(file, file_content); + + scene + .ucmd() + .arg("-P") + .arg("something") + .arg(file) + .succeeds() + .no_stderr() + .stdout_contains("Pattern not found") + .stdout_contains("line1") + .stdout_contains("line2"); + } +}