Skip to content
Open
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/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ fn to_run_error(gctx: &GlobalContext, err: anyhow::Error) -> CliError {
if is_quiet {
CliError::code(exit_code)
} else {
// Ensure a newline between user and cargo's output, especially with trailing "\r"
let _ = writeln!(gctx.shell().err());
CliError::new(err, exit_code)
}
}
35 changes: 35 additions & 0 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ fn exit_code() {
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change catches the new line we added, but it’s difficult to understand the exact problem we’re trying to solve. Could we add the case from the issue as a regression test? We could first capture the previous behavior in one commit and then fix it in a follow-up commit. That would make it much easier to understand the issue we’re addressing on the Windows platform.

For the commit message format, we usually include the scope in parentheses. In Cargo, this typically refers to the subcommands, and we generally don’t capitalize it. Therefore, the most appropriate format for this change may be fix(run):.

@Suryansh-Dey Suryansh-Dey Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much for guiding me.
I have added a test which had overwriting stdout as expected output in first commit.
As you can see tests passes on windows after first commit

Image And in next commit the expected output is printing a \n before stderr.

[ERROR] process didn't exit successfully: `target/debug/foo[EXE]` ([EXIT_STATUS]: 2)

"#]]
Expand Down Expand Up @@ -306,6 +307,7 @@ fn exit_code_verbose() {
[RUNNING] `rustc [..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`

[ERROR] process didn't exit successfully: `target/debug/foo[EXE]` ([EXIT_STATUS]: 2)

"#]]
Expand All @@ -325,6 +327,39 @@ fn exit_code_verbose() {
.run();
}

#[cargo_test]
fn exit_code_with_carriage_return() {
let p = project()
.file(
"src/main.rs",
r#"fn main() { print!("hello\r"); std::process::exit(1); }"#,
)
.build();

let expected = if !cfg!(unix) {
str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`

[ERROR] process didn't exit successfully: `target/debug/foo[EXE]` ([EXIT_STATUS]: 1)

"#]]
} else {
str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`

"#]]
};
p.cargo("run")
.with_status(1)
.with_stderr_data(expected)
.with_stdout_data("hello\r")
.run();
}

#[cargo_test]
fn no_main_file() {
let p = project().file("src/lib.rs", "").build();
Expand Down