Repository navigation
sed: flush named output files with -u - #663
Himanshu-singh04 wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #663 +/- ##
==========================================
+ Coverage 95.43% 95.47% +0.04%
==========================================
Files 14 14
Lines 7730 7764 +34
Branches 460 461 +1
==========================================
+ Hits 7377 7413 +36
+ Misses 352 350 -2
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| for script in ["w", "W", "s/a/A/w"] { | ||
| let directory = tempfile::tempdir().unwrap(); | ||
| let path = directory.path().join("output"); | ||
| let mut child = Command::new(env!("CARGO_BIN_EXE_sed")) |
There was a problem hiding this comment.
could you please use new_ucmd!() with run_no_wait() like the other tests instead of Command + CARGO_BIN_EXE_sed?
There was a problem hiding this comment.
Updated the test to use new_ucmd!().run_no_wait() with piped stdin in 606e5ac.
| use tempfile::NamedTempFile; | ||
| use uutests::new_ucmd; | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
please move it next to the other -u / w tests, not at the top of the file
There was a problem hiding this comment.
Moved the regression test beside the existing file write tests in 606e5ac.
| /// Write String to the file, possibly with a newline, returning errors. | ||
| pub fn write_line(&mut self, line: &str, newline: bool) -> UResult<()> { | ||
| self.write_line_bytes(line.as_bytes(), newline) | ||
| pub fn write_line(&mut self, line: &str, newline: bool, unbuffered: bool) -> UResult<()> { |
There was a problem hiding this comment.
is write_line still used anywhere? if not, could be removed instead of growing a new arg
There was a problem hiding this comment.
Checked the call sites; write_line was unused, so I removed it in 606e5ac.
| writer.borrow_mut().write_line_bytes( | ||
| pattern.as_bytes(), | ||
| pattern.is_newline_terminated(), | ||
| context.unbuffered, |
There was a problem hiding this comment.
context.unbuffered is also forced on when stdout is a terminal (process_all_files), so sed 's/a/b/w out' big in a terminal now flushes out on every line.
GNU only does that with -u. could you please keep the -u flag separate from the tty detection?
|
thanks for this PR! |
1 similar comment
|
thanks for this PR! |
606e5ac to
914b153
Compare
Merging this PR will degrade performance by 3.86%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Fixes #657.
-uflushed standard output but left files written byw,W, ands///wbuffered until processing ended.NamedWriternow flushes each completed write when unbuffered mode is active. Other writes retain their existing buffering.Added an integration test that leaves stdin open and checks each named file before EOF. It failed on the original code and passes with this change.
Validation:
cargo test(408 unit tests, 365 integration tests; 2 existing ignored)cargo fmt --checkcargo clippy --all-targets -- -D warningsgit diff --check