Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sed/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ fn process_file(
);
context.stop_processing = true;
context.quiet = true;
// Like GNU sed, discard text queued by `a`, `r` and `R`.
context.append_elements.clear();
break;
}
'R' => {
Expand Down
32 changes: 32 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,38 @@ fn test_quit_no_newline() {
.stdout_is("foo\n");
}

/// `Q` discards text queued by `a`, `r` and `R`, as GNU sed does.
#[test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the test_ prefix like the other tests

fn test_quit_silently_discards_appended_text() -> std::io::Result<()> {
new_ucmd!()
.args(&["-e", "a A", "-e", "Q"])
.pipe_in("x\n")
.succeeds()
.stdout_is("");

let dir = tempfile::tempdir()?;
let (one, two, text) = (
dir.path().join("1"),
dir.path().join("2"),
dir.path().join("text"),
);
fs::write(&one, "a")?;
fs::write(&two, "b\n")?;
fs::write(&text, "X\n")?;
new_ucmd!()
.args(&["-e", &format!("R {}", text.display()), "-e", "Q"])
.pipe_in("x\n")
.succeeds()
.stdout_is("");
new_ucmd!()
.args(&["-e", &format!("2r {}", text.display()), "-e", "2Q"])
.arg(&one)
.arg(&two)
.succeeds()
.stdout_is("a");
Ok(())
}

// P with single line no newline input
#[test]
fn test_print_first_line_no_newline() {
Expand Down
Loading