Skip to content

sed: continue with the next command after n instead of starting a new cycle - #592

Open
DePasqualeOrg wants to merge 1 commit into
uutils:mainfrom
DePasqualeOrg:fix-n-command
Open

DePasqualeOrg wants to merge 1 commit into
uutils:mainfrom
DePasqualeOrg:fix-n-command

Conversation

@DePasqualeOrg

@DePasqualeOrg DePasqualeOrg commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude Code and Codex flagged this gap during my work with this project. The changes here have gone through extensive automated review. I'm happy to make changes as needed or close this PR and maintain it as a private patch if it doesn't meet your standards.


Fixes #568.

GNU sed's n prints the pattern space unless -n is given, writes any text queued by a, r or R, replaces the pattern space with the next line of input, and continues with the command after n. In uutils sed, n ends the cycle instead, so the next line starts the script from the top. For example, printf '1\n2\n3\n4\n' | sed 'n;d' prints all four lines, while GNU sed prints 1 and 3.

This PR handles n the way N already works: it records the command to continue from, and when the next line has been read, processing resumes there with that line as the pattern space. If there is no next line, sed stops without running the remaining commands, as GNU sed does. Without -s, n reads the first line of the next file; with -s or -i, each file starts at the top of the script.

codecov/patch and codecov/project fail only because CI does not count the coverage of tests that run the sed binary; they should pass after #591 is merged.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 65 / PASSED: 18 / FAILED: 39 / SKIPPED: 8
  Reference: TOTAL: 65 / PASSED: 17 / FAILED: 40 / SKIPPED: 8

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + distrib

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.76%. Comparing base (1113479) to head (a634674).

Files with missing lines Patch % Lines
src/sed/processor.rs 0.00% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
- Coverage   83.86%   83.76%   -0.11%     
==========================================
  Files          14       14              
  Lines        7203     7212       +9     
  Branches      424      428       +4     
==========================================
  Hits         6041     6041              
- Misses       1157     1166       +9     
  Partials        5        5              
Flag Coverage Δ
macos_latest 84.87% <0.00%> (-0.12%) ⬇️
ubuntu_latest 85.07% <0.00%> (-0.11%) ⬇️
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.

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.

n starts a new cycle instead of continuing with the next command

1 participant