1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-05 15:37:47 +00:00

Merge branch 'main' into rm-correct-prompts

This commit is contained in:
Pat Laster 2022-10-17 17:41:44 -05:00 committed by GitHub
commit 87df47dee3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 284 additions and 159 deletions

377
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -170,7 +170,7 @@ impl<'a, 'b> MDWriter<'a, 'b> {
.render_usage() .render_usage()
.to_string() .to_string()
.lines() .lines()
.skip(1) .map(|l| l.strip_prefix("Usage:").unwrap_or(l))
.map(|l| l.trim()) .map(|l| l.trim())
.filter(|l| !l.is_empty()) .filter(|l| !l.is_empty())
.collect::<Vec<_>>() .collect::<Vec<_>>()

View file

@ -18,7 +18,7 @@ path = "src/cut.rs"
clap = { version = "4.0", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
memchr = "2" memchr = "2"
bstr = "0.2" bstr = "1.0"
atty = "0.2" atty = "0.2"
[[bin]] [[bin]]

View file

@ -145,7 +145,7 @@ fn list_to_ranges(list: &str, complement: bool) -> Result<Vec<Range>, String> {
fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> UResult<()> { fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> UResult<()> {
let newline_char = if opts.zero_terminated { b'\0' } else { b'\n' }; let newline_char = if opts.zero_terminated { b'\0' } else { b'\n' };
let buf_in = BufReader::new(reader); let mut buf_in = BufReader::new(reader);
let mut out = stdout_writer(); let mut out = stdout_writer();
let delim = opts let delim = opts
.out_delim .out_delim
@ -189,7 +189,7 @@ fn cut_fields_delimiter<R: Read>(
newline_char: u8, newline_char: u8,
out_delim: &str, out_delim: &str,
) -> UResult<()> { ) -> UResult<()> {
let buf_in = BufReader::new(reader); let mut buf_in = BufReader::new(reader);
let mut out = stdout_writer(); let mut out = stdout_writer();
let input_delim_len = delim.len(); let input_delim_len = delim.len();
@ -273,7 +273,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> URes
); );
} }
let buf_in = BufReader::new(reader); let mut buf_in = BufReader::new(reader);
let mut out = stdout_writer(); let mut out = stdout_writer();
let delim_len = opts.delimiter.len(); let delim_len = opts.delimiter.len();

View file

@ -38,8 +38,9 @@ static OPT_HEX_SUFFIXES: &str = "hex-suffixes";
static OPT_SUFFIX_LENGTH: &str = "suffix-length"; static OPT_SUFFIX_LENGTH: &str = "suffix-length";
static OPT_DEFAULT_SUFFIX_LENGTH: &str = "0"; static OPT_DEFAULT_SUFFIX_LENGTH: &str = "0";
static OPT_VERBOSE: &str = "verbose"; static OPT_VERBOSE: &str = "verbose";
//The ---io-blksize parameter is consumed and ignored. //The ---io and ---io-blksize parameters are consumed and ignored.
//The parameter is included to make GNU coreutils tests pass. //The parameter is included to make GNU coreutils tests pass.
static OPT_IO: &str = "-io";
static OPT_IO_BLKSIZE: &str = "-io-blksize"; static OPT_IO_BLKSIZE: &str = "-io-blksize";
static OPT_ELIDE_EMPTY_FILES: &str = "elide-empty-files"; static OPT_ELIDE_EMPTY_FILES: &str = "elide-empty-files";
@ -154,6 +155,13 @@ pub fn uu_app() -> Command {
.help("print a diagnostic just before each output file is opened") .help("print a diagnostic just before each output file is opened")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg(
Arg::new(OPT_IO)
.long(OPT_IO)
.alias(OPT_IO)
.takes_value(true)
.hide(true),
)
.arg( .arg(
Arg::new(OPT_IO_BLKSIZE) Arg::new(OPT_IO_BLKSIZE)
.long("io-blksize") .long("io-blksize")
@ -912,10 +920,22 @@ impl<'a> Write for LineBytesChunkWriter<'a> {
// then move on to the next chunk if necessary. // then move on to the next chunk if necessary.
None => { None => {
let end = self.num_bytes_remaining_in_current_chunk; let end = self.num_bytes_remaining_in_current_chunk;
let num_bytes_written = self.inner.write(&buf[..end.min(buf.len())])?;
self.num_bytes_remaining_in_current_chunk -= num_bytes_written; // This is ugly but here to match GNU behavior. If the input
total_bytes_written += num_bytes_written; // doesn't end with a \n, pretend that it does for handling
buf = &buf[num_bytes_written..]; // the second to last segment chunk. See `line-bytes.sh`.
if end == buf.len()
&& self.num_bytes_remaining_in_current_chunk
< self.chunk_size.try_into().unwrap()
&& buf[buf.len() - 1] != b'\n'
{
self.num_bytes_remaining_in_current_chunk = 0;
} else {
let num_bytes_written = self.inner.write(&buf[..end.min(buf.len())])?;
self.num_bytes_remaining_in_current_chunk -= num_bytes_written;
total_bytes_written += num_bytes_written;
buf = &buf[num_bytes_written..];
}
} }
// If there is a newline character and the line // If there is a newline character and the line

View file

@ -1395,7 +1395,7 @@ fn test_cp_reflink_bad() {
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_EXISTING_FILE) .arg(TEST_EXISTING_FILE)
.fails() .fails()
.stderr_contains("error: \"bad\" isn't a valid value for '--reflink[=<WHEN>]'"); .stderr_contains("error: 'bad' isn't a valid value for '--reflink[=<WHEN>]'");
} }
#[test] #[test]

View file

@ -92,14 +92,14 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("1") .arg("1")
.arg("c") .arg("c")
.fails() .fails()
.stderr_contains("Invalid value \"c\""); .stderr_contains("Invalid value 'c'");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
.arg("c") .arg("c")
.arg("c") .arg("c")
.arg("1") .arg("1")
.fails() .fails()
.stderr_contains("Invalid value \"c\""); .stderr_contains("Invalid value 'c'");
} }
#[test] #[test]

View file

@ -659,6 +659,22 @@ fn test_line_bytes_no_empty_file() {
assert!(!at.plus("xak").exists()); assert!(!at.plus("xak").exists());
} }
#[test]
fn test_line_bytes_no_eof() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-C", "3"])
.pipe_in("1\n2222\n3\n4")
.succeeds()
.no_stdout()
.no_stderr();
assert_eq!(at.read("xaa"), "1\n");
assert_eq!(at.read("xab"), "222");
assert_eq!(at.read("xac"), "2\n");
assert_eq!(at.read("xad"), "3\n");
assert_eq!(at.read("xae"), "4");
assert!(!at.plus("xaf").exists());
}
#[test] #[test]
fn test_guard_input() { fn test_guard_input() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());

4
tests/fixtures/split/noeof.txt vendored Normal file
View file

@ -0,0 +1,4 @@
1
2222
3
4