Author SHA1 Message Date
Diomidis Spinellis cb4ea5ef15 Disable T in POSIX mode 2026-08-02 17:29:33 +03:00
mukunda katta 04023934fd ci: re-trigger checks (windows runner crates.io download flake) 2026-08-02 17:29:33 +03:00
mukunda kattaandDiomidis Spinellis addc2db04a feat: add T command (branch on no-substitution)
Implements the GNU `T LABEL` command: branch to LABEL if no s///
substitution has succeeded since the last input line was read or the
last t/T was taken. It is the inverse of `t` and shares the same
address and label parsing.

Wires 'T' into get_cmd_spec, resolve_branch_targets, and the processor
branch logic, resetting the substitution flag on evaluation just like
't'. Adds integration tests (simple branch + flag-clear) and a cmd-spec
unit test.

Closes #395

Co-authored-by: Diomidis Spinellis <dds@aueb.gr>
2026-08-02 17:27:58 +03:00
10 changed files with 516 additions and 377 deletions

No files matched your search

Generated
+324 -63
View File
File diff suppressed because it is too large. Load diff
+8 -6
View File
@@ -5,7 +5,8 @@
[package]
name = "sed"
version = "0.2.0"
version = "0.1.1"
authors = ["uutils developers"]
license = "MIT"
description = "sed ~ implemented as universal (cross-platform) utils, written in Rust"
default-run = "sed"
@@ -28,6 +29,7 @@ sed = []
[workspace.dependencies]
assert_fs = "1.1.3"
bytesize = "2.0.0"
chrono = { version = "0.4.37", default-features = false, features = [
"clock",
] }
@@ -46,11 +48,11 @@ predicates = "3.1.3"
rand = { version = "0.10.0" }
regex = "1.10.4"
sha2 = "0.11"
sysinfo = "0.38"
tempfile = "3.10.1"
terminal_size = "0.4.2"
textwrap = { version = "0.16.1", features = ["terminal_size"] }
uucore = { version = "0.10.0", features = ["libc"] }
rustix = "1.1.4"
uucore = { version = "0.9.0", features = ["libc"] }
xattr = "1.3.1"
@@ -64,11 +66,11 @@ memmap2.workspace = true
phf = { workspace = true }
predicates = { workspace = true }
regex = { workspace = true }
sysinfo = { workspace = true }
tempfile = { workspace = true }
terminal_size = { workspace = true }
textwrap = { workspace = true }
uucore = { workspace = true }
rustix = { workspace = true }
[dev-dependencies]
assert_fs = { workspace = true }
@@ -83,7 +85,7 @@ regex = { workspace = true }
sha2 = { workspace = true }
tempfile = { workspace = true }
uucore = { workspace = true, features = ["entries", "process", "signals", "benchmark"] }
uutests = "0.10.0"
uutests = "0.9.0"
[target.'cfg(unix)'.dev-dependencies]
xattr = { workspace = true }
@@ -133,7 +135,7 @@ must_use_candidate = "allow" # 56
needless_raw_string_hashes = "allow" # 20
needless_pass_by_value = "allow" # 15
missing_panics_doc = "allow" # 12
# cast_possible_truncation = "allow" # 7
cast_possible_truncation = "allow" # 7
unnecessary_wraps = "allow" # 6
match_wildcard_for_single_variants = "allow" # 4
cast_sign_loss = "allow" # 4
+125 -11
View File
@@ -646,6 +646,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
[[package]]
name = "ntapi"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae"
dependencies = [
"winapi",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
@@ -674,6 +683,25 @@ dependencies = [
"autocfg",
]
[[package]]
name = "objc2-core-foundation"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
dependencies = [
"bitflags",
]
[[package]]
name = "objc2-io-kit"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15"
dependencies = [
"libc",
"objc2-core-foundation",
]
[[package]]
name = "once_cell"
version = "1.21.4"
@@ -909,7 +937,7 @@ dependencies = [
"phf_codegen",
"predicates",
"regex",
"rustix",
"sysinfo",
"tempfile",
"terminal_size",
"textwrap",
@@ -985,9 +1013,9 @@ checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
[[package]]
name = "similar"
version = "3.1.2"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ee016af5d736b69fc89e19254540fa4b5f5492853fb5503920f084011c78b6"
checksum = "e6505efef05804732ed8a3f2d4f279429eb485bd69d5b0cc6b19cc02005cda16"
dependencies = [
"bstr",
]
@@ -1027,6 +1055,20 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sysinfo"
version = "0.38.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ab6a2f8bfe508deb3c6406578252e491d299cbbf3bc0529ecc3313aee4a52f"
dependencies = [
"libc",
"memchr",
"ntapi",
"objc2-core-foundation",
"objc2-io-kit",
"windows",
]
[[package]]
name = "tempfile"
version = "3.27.0"
@@ -1034,7 +1076,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
"getrandom 0.4.2",
"getrandom 0.3.4",
"once_cell",
"rustix",
"windows-sys",
@@ -1152,9 +1194,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uucore"
version = "0.10.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e97dd0fd8bb2ed12affba9f956c3b94b8ad3f9432746717475420e916ae0b8d4"
checksum = "069b34217c27f611e1589f540f58118dbf226a9e407d38ab472052ff075a1dc2"
dependencies = [
"bigdecimal",
"clap",
@@ -1170,7 +1212,6 @@ dependencies = [
"rustix",
"thiserror",
"unic-langid",
"unicode-width",
"uucore_procs",
"wild",
]
@@ -1192,9 +1233,9 @@ dependencies = [
[[package]]
name = "uucore_procs"
version = "0.10.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907f1b828046ea42cdb4bd898f05b48ab873a41937bf75ebe12f09a5bf411f58"
checksum = "34337da211e7abfff7189b794afb3b5018fe356fb36474b73645458fc1201350"
dependencies = [
"proc-macro2",
"quote",
@@ -1202,9 +1243,9 @@ dependencies = [
[[package]]
name = "uufuzz"
version = "0.10.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72d4c5bac0f8ccabaa8e8ccbf2724446f8b007c06ad343fabfe1a1525a4ff4f2"
checksum = "8e4192b67d5e7f0a3300db353ec3217beee89442f02c11d8ae108867eee392d0"
dependencies = [
"console",
"rand",
@@ -1320,6 +1361,49 @@ dependencies = [
"glob",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.62.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
dependencies = [
"windows-collections",
"windows-core",
"windows-future",
"windows-numerics",
]
[[package]]
name = "windows-collections"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
dependencies = [
"windows-core",
]
[[package]]
name = "windows-core"
version = "0.62.2"
@@ -1333,6 +1417,17 @@ dependencies = [
"windows-strings",
]
[[package]]
name = "windows-future"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
dependencies = [
"windows-core",
"windows-link",
"windows-threading",
]
[[package]]
name = "windows-implement"
version = "0.60.2"
@@ -1361,6 +1456,16 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-numerics"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
dependencies = [
"windows-core",
"windows-link",
]
[[package]]
name = "windows-result"
version = "0.4.1"
@@ -1388,6 +1493,15 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-threading"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
dependencies = [
"windows-link",
]
[[package]]
name = "wit-bindgen"
version = "0.51.0"
+2 -2
View File
@@ -14,8 +14,8 @@ libc = "0.2.153"
tempfile = "3.15.0"
rand = { version = "0.10.0" }
similar = "3.0.0"
uucore = { version = "0.10.0", features = ["libc"] }
uufuzz = "0.10.0"
uucore = { version = "0.9.0", features = ["libc"] }
uufuzz = "0.9.0"
sed = { path = ".." }
+5 -5
View File
@@ -255,12 +255,12 @@ impl Default for Transliteration {
/// Create a new Transliteration with identity mapping for the fast-path.
fn default() -> Self {
let mut fast = [0u8; 256];
for (slot, value) in fast.iter_mut().zip(0..=u8::MAX) {
*slot = value;
for (i, slot) in fast.iter_mut().enumerate() {
*slot = i as u8;
}
let mut unicode_fast = ['\0'; COMMON_UNICODE];
for (slot, cp) in unicode_fast.iter_mut().zip(0u32..) {
*slot = char::from_u32(cp).unwrap_or('\0');
for (i, slot) in unicode_fast.iter_mut().enumerate() {
*slot = char::from_u32(i as u32).unwrap_or('\0');
}
Self {
byte_fast: fast,
@@ -593,7 +593,7 @@ mod tests {
fn test_all_fast_path_mapped_to_space() {
let mut t = Transliteration::default();
for cp in 0..COMMON_UNICODE {
if let Some(ch) = u32::try_from(cp).ok().and_then(char::from_u32) {
if let Some(ch) = char::from_u32(cp as u32) {
t.insert(ch, ' ');
}
}
-70
View File
@@ -1373,72 +1373,6 @@ fn compile_text_command_posix(
Ok(CommandHandling::Continue)
}
// Handle v
fn compile_version_command(
lines: &mut ScriptLineProvider,
line: &mut ScriptCharProvider,
_cmd: &mut Command,
_context: &mut ProcessingContext,
) -> UResult<CommandHandling> {
// Claim version partify with GNU sed 4.9
const GNU_MAJOR: u8 = 4;
const GNU_MINOR: u8 = 9;
const GNU_PATCH: u8 = 0;
line.advance();
line.eat_spaces(); // Skip any leading whitespace.
let mut major = String::new();
let mut minor = String::new();
let mut patch = String::new();
let mut ver_semantic = 0;
while !line.eol() {
if line.current() == '.' {
ver_semantic += 1;
line.advance();
} else {
match ver_semantic {
0 => major.push(line.current()),
1 => minor.push(line.current()),
2 => patch.push(line.current()),
_ => return compilation_error(lines, line, "invalid version of sed"),
}
line.advance();
}
}
if major.is_empty() {
major = GNU_MAJOR.to_string();
minor = GNU_MINOR.to_string();
patch = GNU_PATCH.to_string();
}
if minor.is_empty() {
minor.push('0');
}
if patch.is_empty() {
patch.push('0');
}
match major.parse::<u8>() {
Ok(major_int) => match minor.parse::<u8>() {
Ok(minor_int) => match patch.parse::<u8>() {
Ok(patch_int) => {
if minor_int <= GNU_MINOR && major_int <= GNU_MAJOR && patch_int == GNU_PATCH {
return Ok(CommandHandling::Continue);
}
compilation_error(lines, line, "expected newer version of sed")
}
Err(_) => compilation_error(lines, line, "invalid version of sed"),
},
Err(_) => compilation_error(lines, line, "invalid version of sed"),
},
Err(_) => compilation_error(lines, line, "invalid version of sed"),
}
}
// Handles e
// With no argument, the command executes the pattern space as a shell
// command at runtime. With an argument, the rest of the line is the
@@ -1652,10 +1586,6 @@ fn get_cmd_spec(
n_addr: 2,
handler: compile_trans_command,
}),
'v' if !posix => Ok(CommandSpec {
n_addr: 0,
handler: compile_version_command,
}),
_ => compilation_error(lines, line, format!("invalid command code `{cmd_code}'")),
}
}
+46 -156
View File
@@ -29,11 +29,6 @@ use std::marker::PhantomData;
#[cfg(unix)]
use std::os::fd::RawFd;
#[cfg(unix)]
use rustix::fd::BorrowedFd;
#[cfg(target_os = "linux")]
use rustix::fs::copy_file_range as rustix_copy_file_range;
#[cfg(unix)]
use std::os::unix::io::AsRawFd;
@@ -407,24 +402,9 @@ impl FastCopy {
Self {
fd,
is_regular: ftype as libc::mode_t == libc::S_IFREG,
// st_blksize is always positive and small; fall back to a common
// block size if it ever doesn't fit in usize.
block_size: usize::try_from(st.st_blksize).unwrap_or(4096),
block_size: st.st_blksize as usize,
}
}
/// Return a borrowed file descriptor.
///
/// # Safety invariant
///
/// `FastCopy` only stores file descriptors obtained from open
/// [`File`](std::fs::File) objects. Those `File`s are kept alive
/// by the owning [`MmapLineCursor`] / output-buffer, guaranteeing
/// the fd remains valid for the duration of any borrow.
pub fn as_fd(&self) -> BorrowedFd<'_> {
// SAFETY: self.fd is a valid file descriptor owned by a live File.
unsafe { BorrowedFd::borrow_raw(self.fd) }
}
}
#[cfg(test)]
@@ -818,10 +798,10 @@ impl OutputBuffer {
if chunk.in_fast_copy.is_regular && self.fast_copy.is_regular {
portable_copy_file_range(
chunk.out_ptr,
chunk.in_fast_copy.as_fd(),
chunk.in_fast_copy.fd,
// Input file offset
unsafe { chunk.out_ptr.offset_from(chunk.base_ptr) } as libc::off_t,
self.fast_copy.as_fd(),
self.fast_copy.fd,
chunk.len,
// Alignment block size: the largest of the two
chunk.in_fast_copy.block_size.max(self.fast_copy.block_size),
@@ -936,9 +916,9 @@ fn reliable_write(fd: i32, ptr: *const u8, len: usize) -> std::io::Result<usize>
#[allow(unused_variables)]
fn portable_copy_file_range(
in_ptr: *const u8,
in_fd: BorrowedFd<'_>,
in_fd: i32,
in_off: libc::off_t,
out_fd: BorrowedFd<'_>,
out_fd: i32,
len: usize,
block_size: usize,
cover: WriteRange,
@@ -953,7 +933,7 @@ fn portable_copy_file_range(
}
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
{
reliable_write(out_fd.as_raw_fd(), in_ptr, len)
reliable_write(out_fd, in_ptr, len)
}
}
@@ -964,34 +944,37 @@ fn portable_copy_file_range(
#[cfg(all(target_os = "linux", target_env = "gnu"))]
fn reliable_copy_file_range(
in_ptr: *const u8,
in_fd: BorrowedFd<'_>,
in_fd: i32,
mut in_off: libc::off_t,
out_fd: BorrowedFd<'_>,
out_fd: i32,
len: usize,
) -> std::io::Result<usize> {
let mut pending = len;
while pending > 0 {
let mut in_off_u64 = in_off as u64;
let result: std::io::Result<usize> =
rustix_copy_file_range(in_fd, Some(&mut in_off_u64), out_fd, None, pending)
.map_err(std::io::Error::from);
match result {
Ok(0) => break,
Ok(ret) => {
pending -= ret;
in_off = in_off_u64 as libc::off_t;
}
Err(err) => {
return match err.raw_os_error() {
Some(libc::ENOSYS) | Some(libc::EOPNOTSUPP) | Some(libc::EXDEV) => {
// Fallback to write(2).
reliable_write(out_fd.as_raw_fd(), in_ptr, pending)
}
_ => Err(err),
};
}
let ret = unsafe {
libc::copy_file_range(
in_fd,
&raw mut in_off,
out_fd,
std::ptr::null_mut(), // Use and update output offset
pending,
0,
)
};
if ret < 0 {
let err = io::Error::last_os_error();
return match err.raw_os_error() {
Some(libc::ENOSYS) | Some(libc::EOPNOTSUPP) | Some(libc::EXDEV) => {
// Fallback to write(2).
reliable_write(out_fd, in_ptr, pending)
}
_ => Err(err),
};
} else if ret == 0 {
// EOF reached
break;
}
pending -= ret as usize;
}
Ok(len)
}
@@ -1003,27 +986,24 @@ fn reliable_copy_file_range(
#[cfg(all(target_os = "linux", target_env = "gnu"))]
fn aligned_copy_file_range(
mut in_ptr: *const u8,
in_fd: BorrowedFd<'_>,
in_fd: i32,
mut in_off: libc::off_t,
out_fd: BorrowedFd<'_>,
out_fd: i32,
len: usize,
block_size: usize,
cover: WriteRange,
) -> std::io::Result<usize> {
// Get current output offset.
// If either offset doesn't fit in usize (only possible on 32-bit
// targets), give up on alignment and just copy everything.
let (Ok(out_off), Ok(in_off_bytes)) = (
usize::try_from(rustix::fs::tell(out_fd)?),
usize::try_from(in_off),
) else {
return reliable_copy_file_range(in_ptr, in_fd, in_off, out_fd, len);
};
// 1. Get current output offset.
let res = unsafe { libc::lseek(out_fd, 0, libc::SEEK_CUR) as i64 };
if res < 0 {
return Err(std::io::Error::last_os_error());
}
let out_off = res as usize;
let mut pending = len;
// Obtain head alignment.
// Bytes to end of block:
let remainder = in_off_bytes % block_size;
let remainder = in_off as usize % block_size;
// Bytes to write (block_size becomes 0):
let head_align = (block_size - remainder) % block_size;
@@ -1035,7 +1015,7 @@ fn aligned_copy_file_range(
if head_align > 0 {
// Align the two files on a block boundary.
let head_len = head_align.min(pending);
reliable_write(out_fd.as_raw_fd(), in_ptr, head_len)?;
reliable_write(out_fd, in_ptr, head_len)?;
in_ptr = unsafe { in_ptr.add(head_len) };
in_off += head_len as i64;
pending -= head_len;
@@ -1049,7 +1029,7 @@ fn aligned_copy_file_range(
// Copy tail if needed.
if pending > 0 && cover == WriteRange::Complete {
in_ptr = unsafe { in_ptr.add(aligned_len) };
pending -= reliable_write(out_fd.as_raw_fd(), in_ptr, pending)?;
pending -= reliable_write(out_fd, in_ptr, pending)?;
}
Ok(len - pending)
@@ -1082,8 +1062,6 @@ mod tests {
#[cfg(all(target_os = "linux", target_env = "gnu"))]
use std::io::{self, Write};
use std::io::{Seek, SeekFrom};
#[cfg(target_os = "linux")]
use std::os::unix::io::AsFd;
use tempfile::NamedTempFile;
use tempfile::tempfile;
@@ -1815,8 +1793,8 @@ mod tests {
infile.write_all(data).unwrap();
infile.rewind().unwrap();
let in_fd = infile.as_fd();
let out_fd = outfile.as_fd();
let in_fd = infile.as_raw_fd();
let out_fd = outfile.as_raw_fd();
let in_ptr = data.as_ptr();
// Copy with block size 4, cover = Complete
@@ -1851,8 +1829,8 @@ mod tests {
infile.write_all(data).unwrap();
infile.rewind().unwrap();
let in_fd = infile.as_fd();
let out_fd = outfile.as_fd();
let in_fd = infile.as_raw_fd();
let out_fd = outfile.as_raw_fd();
let in_ptr = data.as_ptr();
// Copy with block size 4, cover = Blocks
@@ -1870,94 +1848,6 @@ mod tests {
assert_eq!(&buf, b"abcdefgh");
}
#[test]
#[cfg(target_os = "linux")]
fn test_aligned_copy_respects_existing_out_offset() {
let mut infile = tempfile().unwrap();
let mut outfile = tempfile().unwrap();
// Write a prefix into the output file so tell() returns a non-zero offset.
let prefix = b"HEADER";
outfile.write_all(prefix).unwrap();
outfile.flush().unwrap();
// Input data = 12 bytes (3 blocks of 4 when block_size=4).
let data = b"abcdefghijkl";
infile.write_all(data).unwrap();
infile.rewind().unwrap();
let in_fd = infile.as_fd();
let out_fd = outfile.as_fd();
let in_ptr = data.as_ptr();
let copied = aligned_copy_file_range(
in_ptr,
in_fd,
0,
out_fd,
data.len(),
4,
WriteRange::Complete,
)
.unwrap();
assert_eq!(copied, data.len());
outfile.rewind().unwrap();
let mut buf = Vec::new();
outfile.read_to_end(&mut buf).unwrap();
assert_eq!(&buf, b"HEADERabcdefghijkl");
}
#[test]
#[cfg(target_os = "linux")]
fn test_reliable_copy_file_range_rustix_path() {
let mut infile = tempfile().unwrap();
let mut outfile = tempfile().unwrap();
let data = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
infile.write_all(data).unwrap();
infile.rewind().unwrap();
let in_fd = infile.as_fd();
let out_fd = outfile.as_fd();
let in_ptr = data.as_ptr();
// Copy a subrange starting at offset 10.
let copied = reliable_copy_file_range(in_ptr, in_fd, 10, out_fd, 16).unwrap();
assert_eq!(copied, 16);
outfile.rewind().unwrap();
let mut buf = Vec::new();
outfile.read_to_end(&mut buf).unwrap();
assert_eq!(&buf, b"ABCDEFGHIJKLMNOP");
// Now verify that copying into a file with existing data appends correctly.
let mut infile2 = tempfile().unwrap();
let mut outfile2 = tempfile().unwrap();
let input_data = b"abcdefghijklmnopqrstuvwxyz";
infile2.write_all(input_data).unwrap();
infile2.rewind().unwrap();
outfile2.write_all(b"PRE:").unwrap();
outfile2.flush().unwrap();
let in_fd2 = infile2.as_fd();
let out_fd2 = outfile2.as_fd();
let in_ptr2 = input_data.as_ptr();
let copied2 = reliable_copy_file_range(in_ptr2, in_fd2, 5, out_fd2, 10).unwrap();
assert_eq!(copied2, 10);
outfile2.rewind().unwrap();
let mut buf2 = Vec::new();
outfile2.read_to_end(&mut buf2).unwrap();
assert_eq!(&buf2, b"PRE:fghijklmno");
}
///////////////////////////////
// Unit tests for write_chunk()
///////////////////////////////
+3 -4
View File
@@ -24,16 +24,15 @@ use crate::sed::command::{ByteSpace, CharacterMode, ProcessingContext};
use crate::sed::compiler::compile;
use crate::sed::processor::process_all_files;
use crate::sed::script_line_provider::ScriptValue;
use clap::{Arg, ArgMatches, Command, arg};
use clap::{Arg, ArgMatches, Command, arg, crate_version};
use std::collections::HashMap;
use std::env;
use std::path::PathBuf;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::format_usage;
const ABOUT: &str = "Stream editor for filtering and transforming text (part of uutils)";
const ABOUT: &str = "Stream editor for filtering and transforming text";
const USAGE: &str = "sed [OPTION]... [script] [file]...";
const VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), " (uutils)");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
@@ -63,7 +62,7 @@ pub fn uu_app() -> Command {
let util_name = uucore::util_name();
Command::new(util_name)
.version(VERSION)
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.args_override_self(true)
+2 -6
View File
@@ -796,17 +796,13 @@ fn process_file(
}
'q' => {
// Quit after printing the pattern space.
set_exit_code(
i32::try_from(*extract_variant!(command, Number)).unwrap_or(i32::MAX),
);
set_exit_code(*extract_variant!(command, Number) as i32);
context.stop_processing = true;
break;
}
'Q' => {
// Quit immediatelly.
set_exit_code(
i32::try_from(*extract_variant!(command, Number)).unwrap_or(i32::MAX),
);
set_exit_code(*extract_variant!(command, Number) as i32);
context.stop_processing = true;
context.quiet = true;
break;
+1 -54
View File
@@ -38,18 +38,7 @@ fn test_version() {
.arg("--version")
.succeeds()
.no_stderr()
.stdout_is(&short);
assert!(short.contains("uutils"));
}
#[test]
fn test_help_mentions_uutils() {
new_ucmd!()
.arg("--help")
.succeeds()
.no_stderr()
.stdout_contains("part of uutils");
.stdout_is(short);
}
#[test]
@@ -2272,48 +2261,6 @@ fn test_print_first_line_no_newline() {
.stdout_is("foo");
}
#[test]
fn test_expected_newer_version() {
new_ucmd!()
.args(&["v4.10"])
.fails()
.stderr_is("sed: <script argument 1>:1:6: error: expected newer version of sed\n");
}
#[test]
fn test_invalid_version() {
new_ucmd!()
.args(&["v4.a"])
.fails()
.stderr_is("sed: <script argument 1>:1:5: error: invalid version of sed\n");
}
#[test]
fn test_valid_version() {
new_ucmd!().args(&["v4.9"]).succeeds();
}
#[test]
fn test_valid_only_major_version() {
// v4.0.0
new_ucmd!().args(&["v4"]).succeeds();
}
#[test]
fn test_invalid_only_major_version() {
// v999.0.0
new_ucmd!()
.args(&["v999"])
.fails()
.stderr_is("sed: <script argument 1>:1:5: error: invalid version of sed\n");
}
#[test]
fn test_default_version() {
// defaults to v4.9.0
new_ucmd!().args(&["v"]).succeeds();
}
//--posix should reject GNU substitute flags i/I https://github.com/uutils/sed/issues/401
#[test]
fn test_posix_reject_flags() {