Skip to content

Commit

Permalink
test/more: test argument --pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Ideflop authored and sylvestre committed Mar 10, 2024
1 parent 986c70c commit a227af7
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/by-util/test_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check warning on line 39 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L38-L39

Added lines #L38 - L39 were not covered by tests
}
}

Expand Down Expand Up @@ -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;

Check warning on line 162 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L161-L162

Added lines #L161 - L162 were not covered by tests

let file = "test_file";

at.write(file, "line1\nline2");

Check warning on line 166 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L166

Added line #L166 was not covered by tests

// output only the second line "line2"
scene

Check warning on line 169 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L169

Added line #L169 was not covered by tests
.ucmd()
.arg("-P")
.arg("line2")
.arg(file)
.succeeds()
.no_stderr()
.stdout_does_not_contain("line1")
.stdout_contains("line2");
}

Check warning on line 178 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L177-L178

Added lines #L177 - L178 were not covered by tests
}

#[test]
fn test_more_pattern_not_found() {
if std::io::stdout().is_terminal() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

Check warning on line 185 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L184-L185

Added lines #L184 - L185 were not covered by tests

let file = "test_file";

let file_content = "line1\nline2";
at.write(file, file_content);

Check warning on line 190 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L190

Added line #L190 was not covered by tests

scene

Check warning on line 192 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L192

Added line #L192 was not covered by tests
.ucmd()
.arg("-P")
.arg("something")
.arg(file)
.succeeds()
.no_stderr()
.stdout_contains("Pattern not found")
.stdout_contains("line1")
.stdout_contains("line2");
}

Check warning on line 202 in tests/by-util/test_more.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L201-L202

Added lines #L201 - L202 were not covered by tests
}

0 comments on commit a227af7

Please sign in to comment.