Skip to content

Commit

Permalink
more: fix incorrect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Mar 22, 2024
1 parent d9b2fec commit 5e6fa49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/uu/more/src/more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (methods) isnt

use std::{
fs::File,
io::{stdin, stdout, BufReader, IsTerminal, Read, Stdout, Write},
io::{stdin, stdout, BufReader, Read, Stdout, Write},
panic::set_hook,
path::Path,
time::Duration,
Expand Down Expand Up @@ -159,13 +157,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
buff.clear();
}
reset_term(&mut stdout);
} else if !std::io::stdin().is_terminal() {
} else {
stdin().read_to_string(&mut buff).unwrap();
if buff.is_empty() {
return Err(UUsageError::new(1, "bad usage"));

Check warning on line 163 in src/uu/more/src/more.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/more/src/more.rs#L163

Added line #L163 was not covered by tests
}
let mut stdout = setup_term();
more(&buff, &mut stdout, false, None, None, &mut options)?;
reset_term(&mut stdout);
} else {
return Err(UUsageError::new(1, "bad usage"));
}
Ok(())
}
Expand Down
44 changes: 27 additions & 17 deletions tests/by-util/test_more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,46 @@ use std::io::IsTerminal;

#[test]
fn test_more_no_arg() {
// Reading from stdin is now supported, so this must succeed
if std::io::stdout().is_terminal() {
new_ucmd!().succeeds();
new_ucmd!().fails().stderr_contains("more: bad usage");

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L11

Added line #L11 was not covered by tests
}
}

#[test]
fn test_valid_arg() {
if std::io::stdout().is_terminal() {
new_ucmd!().arg("-c").succeeds();
new_ucmd!().arg("--print-over").succeeds();
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L18-L19

Added lines #L18 - L19 were not covered by tests

let file = "test_file";
at.touch(file);

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L22

Added line #L22 was not covered by tests

scene.ucmd().arg(file).arg("-c").succeeds();
scene.ucmd().arg(file).arg("--print-over").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L24-L25

Added lines #L24 - L25 were not covered by tests

new_ucmd!().arg("-p").succeeds();
new_ucmd!().arg("--clean-print").succeeds();
scene.ucmd().arg(file).arg("-p").succeeds();
scene.ucmd().arg(file).arg("--clean-print").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L27-L28

Added lines #L27 - L28 were not covered by tests

new_ucmd!().arg("-s").succeeds();
new_ucmd!().arg("--squeeze").succeeds();
scene.ucmd().arg(file).arg("-s").succeeds();
scene.ucmd().arg(file).arg("--squeeze").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L30-L31

Added lines #L30 - L31 were not covered by tests

new_ucmd!().arg("-u").succeeds();
new_ucmd!().arg("--plain").succeeds();
scene.ucmd().arg(file).arg("-u").succeeds();
scene.ucmd().arg(file).arg("--plain").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L33-L34

Added lines #L33 - L34 were not covered by tests

new_ucmd!().arg("-n").arg("10").succeeds();
new_ucmd!().arg("--lines").arg("0").succeeds();
new_ucmd!().arg("--number").arg("0").succeeds();
scene.ucmd().arg(file).arg("-n").arg("10").succeeds();
scene.ucmd().arg(file).arg("--lines").arg("0").succeeds();
scene.ucmd().arg(file).arg("--number").arg("0").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L36 - L38 were not covered by tests

new_ucmd!().arg("-F").arg("10").succeeds();
new_ucmd!().arg("--from-line").arg("0").succeeds();
scene.ucmd().arg(file).arg("-F").arg("10").succeeds();
scene

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L40-L41

Added lines #L40 - L41 were not covered by tests
.ucmd()
.arg(file)
.arg("--from-line")
.arg("0")
.succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L46

Added line #L46 was not covered by tests

new_ucmd!().arg("-P").arg("something").succeeds();
new_ucmd!().arg("--pattern").arg("-1").succeeds();
scene.ucmd().arg(file).arg("-P").arg("something").succeeds();
scene.ucmd().arg(file).arg("--pattern").arg("-1").succeeds();

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

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_more.rs#L48-L49

Added lines #L48 - L49 were not covered by tests
}
}

Expand Down

0 comments on commit 5e6fa49

Please sign in to comment.