mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +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
2 changed files with 21 additions and 0 deletions
|
@ -34,6 +34,7 @@ mod parasplit;
|
||||||
static SYNTAX: &str = "[OPTION]... [FILE]...";
|
static SYNTAX: &str = "[OPTION]... [FILE]...";
|
||||||
static SUMMARY: &str = "Reformat paragraphs from input files (or stdin) to stdout.";
|
static SUMMARY: &str = "Reformat paragraphs from input files (or stdin) to stdout.";
|
||||||
static LONG_HELP: &str = "";
|
static LONG_HELP: &str = "";
|
||||||
|
static MAX_WIDTH: usize = 2500;
|
||||||
|
|
||||||
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;
|
pub type FileOrStdReader = BufReader<Box<dyn Read + 'static>>;
|
||||||
pub struct FmtOptions {
|
pub struct FmtOptions {
|
||||||
|
@ -137,6 +138,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
crash!(1, "Invalid WIDTH specification: `{}': {}", s, e);
|
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);
|
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]
|
/* #[test]
|
||||||
Fails for now, see https://github.com/uutils/coreutils/issues/1501
|
Fails for now, see https://github.com/uutils/coreutils/issues/1501
|
||||||
fn test_fmt_w() {
|
fn test_fmt_w() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue