Skip to content

Commit a227af7

Browse files
Ideflopsylvestre
authored andcommitted
test/more: test argument --pattern
1 parent 986c70c commit a227af7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/by-util/test_more.rs

+50
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fn test_valid_arg() {
3434

3535
new_ucmd!().arg("-F").arg("10").succeeds();
3636
new_ucmd!().arg("--from-line").arg("0").succeeds();
37+
38+
new_ucmd!().arg("-P").arg("something").succeeds();
39+
new_ucmd!().arg("--pattern").arg("-1").succeeds();
3740
}
3841
}
3942

@@ -151,3 +154,50 @@ fn test_more_error_on_multiple_files() {
151154
.stderr_contains("file3");
152155
}
153156
}
157+
158+
#[test]
159+
fn test_more_pattern_found() {
160+
if std::io::stdout().is_terminal() {
161+
let scene = TestScenario::new(util_name!());
162+
let at = &scene.fixtures;
163+
164+
let file = "test_file";
165+
166+
at.write(file, "line1\nline2");
167+
168+
// output only the second line "line2"
169+
scene
170+
.ucmd()
171+
.arg("-P")
172+
.arg("line2")
173+
.arg(file)
174+
.succeeds()
175+
.no_stderr()
176+
.stdout_does_not_contain("line1")
177+
.stdout_contains("line2");
178+
}
179+
}
180+
181+
#[test]
182+
fn test_more_pattern_not_found() {
183+
if std::io::stdout().is_terminal() {
184+
let scene = TestScenario::new(util_name!());
185+
let at = &scene.fixtures;
186+
187+
let file = "test_file";
188+
189+
let file_content = "line1\nline2";
190+
at.write(file, file_content);
191+
192+
scene
193+
.ucmd()
194+
.arg("-P")
195+
.arg("something")
196+
.arg(file)
197+
.succeeds()
198+
.no_stderr()
199+
.stdout_contains("Pattern not found")
200+
.stdout_contains("line1")
201+
.stdout_contains("line2");
202+
}
203+
}

0 commit comments

Comments
 (0)