Skip to content

Implement GNU R (read one line from file) command - #544

Open
Jorge-Polanco-Roque wants to merge 2 commits into
uutils:mainfrom
Jorge-Polanco-Roque:feat/R-read-one-line
Open

Implement GNU R (read one line from file) command#544
Jorge-Polanco-Roque wants to merge 2 commits into
uutils:mainfrom
Jorge-Polanco-Roque:feat/R-read-one-line

Conversation

@Jorge-Polanco-Roque

Copy link
Copy Markdown

Closes #394.

Implements the GNU R command, the line-oriented counterpart to r (mirroring how W relates to w, added in #531).

R filename queues the next successive line of filename to 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

$ printf 'a\nb\nc\nd\n' | sed -e 'R lines.txt'   # lines.txt = x1,x2,x3
a
x1
b
x2
c
x3
d
  • The file is opened lazily on first use and read one line at a time (new NamedReader, analogous to NamedWriter).
  • An unreadable or exhausted file yields no further lines — no error is raised, matching GNU sed.
  • Reserved to non-POSIX mode and rejected under --sandbox, exactly like r/w/W.

Tests

  • Unit tests for NamedReader (successive lines, final line without newline, missing file).
  • Integration tests: successive-line behavior, silent missing file, --posix rejection, --sandbox rejection.

cargo fmt --all -- --check, cargo test --all, and cargo clippy --all-targets --workspace -psed -- -D warnings all pass locally.

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

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.65432% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.09%. Comparing base (f1c5813) to head (a3e6cc3).

Files with missing lines Patch % Lines
src/sed/processor.rs 0.00% 6 Missing ⚠️
src/sed/compiler.rs 88.57% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #544      +/-   ##
==========================================
+ Coverage   83.04%   83.09%   +0.05%     
==========================================
  Files          13       14       +1     
  Lines        7046     7127      +81     
  Branches      401      405       +4     
==========================================
+ Hits         5851     5922      +71     
- Misses       1192     1202      +10     
  Partials        3        3              
Flag Coverage Δ
macos_latest 83.71% <87.65%> (+0.04%) ⬆️
ubuntu_latest 83.92% <87.65%> (+0.04%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented Aug 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 3.17%

⚡ 1 improved benchmark
✅ 10 untouched benchmarks

Performance Changes

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 (a3e6cc3) with main (f1c5813)

Open in CodSpeed

@sylvestre

Copy link
Copy Markdown
Contributor

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.
@Jorge-Polanco-Roque

Copy link
Copy Markdown
Author

Thanks — added tests to cover the missing cases: unit tests for compile_read_line_command (sandbox rejection and that it installs a NamedReader), plus integration tests for R appending under -n (suppressed auto-print) and for a source file shorter than the input. The R compile and execute paths are now exercised directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add R command (read one line from file)

2 participants