Skip to content

Commit

Permalink
Merge pull request #6104 from cakebaker/more_fix_incorrect_tests
Browse files Browse the repository at this point in the history
more: fix two incorrect tests
  • Loading branch information
sylvestre authored Mar 23, 2024
2 parents d9b2fec + 5e6fa49 commit fa1850c
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"));
}
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");
}
}

#[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;

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

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

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();

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

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

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();

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
.ucmd()
.arg(file)
.arg("--from-line")
.arg("0")
.succeeds();

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();
}
}

Expand Down

0 comments on commit fa1850c

Please sign in to comment.