Implement GNU R (read one line from file) command - #544
Implement GNU R (read one line from file) command#544Jorge-Polanco-Roque wants to merge 4 commits into
Conversation
The R command queues the next successive line of a file to be output at the end of the current cycle. It is the line-oriented counterpart to r, mirroring how W relates to w. The backing file is opened lazily and read one line at a time via a new NamedReader; an unreadable or exhausted file yields no further lines, matching GNU sed (no error is raised). Reserved to non-POSIX mode and rejected under --sandbox, like r. Fixes uutils#394 Signed-off-by: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #544 +/- ##
==========================================
- Coverage 83.04% 82.90% -0.14%
==========================================
Files 13 14 +1
Lines 7046 6949 -97
Branches 401 405 +4
==========================================
- Hits 5851 5761 -90
+ Misses 1192 1185 -7
Partials 3 3
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:
|
Merging this PR will improve performance by 3.17%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | access_log_translit |
1 s | 1 s | +3.17% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Jorge-Polanco-Roque:feat/R-read-one-line (49e0e12) with main (77f442d)
|
please add tests to improve the coverage. some tests are missing to reach important cases |
Add unit tests for compile_read_line_command (sandbox rejection and that it installs a NamedReader) and integration tests covering R appending under -n (suppressed auto-print) and a file shorter than the input.
|
Thanks — added tests to cover the missing cases: unit tests for |
GNU sed keeps a single cursor per file name, so multiple `R file` commands read successive lines. Each R instance was creating its own NamedReader, so they all restarted from line 1. Share one Rc<RefCell<NamedReader>> per path via the compilation context. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add integration tests for a shared cursor across R commands on the same file, address-gated R that only advances when it runs, independent cursors for distinct files, and a final line without a trailing newline. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Added integration tests for R covering the cases that were missing: address-gated R that only advances when it runs, independent cursors across different files, and a final line without a trailing newline. While writing them I also caught and fixed a real divergence from GNU: multiple |
|
GNU sed testsuite comparison: |
Closes #394.
Implements the GNU
Rcommand, the line-oriented counterpart tor(mirroring howWrelates tow, added in #531).R filenamequeues the next successive line offilenameto be inserted into the output stream at the end of the current cycle. Each cycle consumes one more line; once the file is exhausted no line is queued.Behavior
NamedReader, analogous toNamedWriter).--sandbox, exactly liker/w/W.Tests
NamedReader(successive lines, final line without newline, missing file).--posixrejection,--sandboxrejection.cargo fmt --all -- --check,cargo test --all, andcargo clippy --all-targets --workspace -psed -- -D warningsall pass locally.