mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 20:34:28 +00:00
bug(fmt): just like the GNU version, fails when -W is bigger than 2500
Closes: #1704
This commit is contained in:
parent
992c113f09
commit
cacaf0cde8
|
@ -34,6 +34,7 @@ mod parasplit;
|
|||
static SYNTAX: &str = "[OPTION]... [FILE]...";
|
||||
static SUMMARY: &str = "Reformat paragraphs from input files (or stdin) to stdout.";
|
||||
static LONG_HELP: &str = "";
|
||||
static MAX_WIDTH: usize = 2500;
|
||||
|
||||
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;
|
||||
pub struct FmtOptions {
|
||||
|
@ -137,6 +138,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
crash!(1, "Invalid WIDTH specification: `{}': {}", s, e);
|
||||
}
|
||||
};
|
||||
if fmt_opts.width > MAX_WIDTH {
|
||||
crash!(
|
||||
1,
|
||||
"invalid width: '{}': Numerical result out of range",
|
||||
fmt_opts.width
|
||||
);
|
||||
}
|
||||
fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3);
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,19 @@ fn test_fmt_q() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fmt_w_too_big() {
|
||||
let result = new_ucmd!()
|
||||
.arg("-w")
|
||||
.arg("2501")
|
||||
.arg("one-word-per-line.txt")
|
||||
.run();
|
||||
//.stdout_is_fixture("call_graph.expected");
|
||||
assert_eq!(
|
||||
result.stderr.trim(),
|
||||
"fmt: error: invalid width: '2501': Numerical result out of range"
|
||||
);
|
||||
}
|
||||
/* #[test]
|
||||
Fails for now, see https://github.com/uutils/coreutils/issues/1501
|
||||
fn test_fmt_w() {
|
||||
|
|
Loading…
Reference in a new issue