Skip to content

Commit 689e54d

Browse files
neuschaefertgross35
authored andcommitted
ctest-next: Better error propagation when subprocesses fail
When a process fails, it can be useful to know the termination reason in addition to the stderr output, especially when a process is terminated with a fatal signal such as SIGSEGV.
1 parent acd869f commit 689e54d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ctest-next/src/macro_expansion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub fn expand<P: AsRef<Path>>(crate_path: P, cfg: &[(String, Option<String>)]) -
2727
let output = cmd.output()?;
2828

2929
if !output.status.success() {
30-
let error = std::str::from_utf8(&output.stderr)?;
31-
return Err(error.into());
30+
let stderr = std::str::from_utf8(&output.stderr)?;
31+
return Err(format!("macro expansion failed with {}: {}", output.status, stderr).into());
3232
}
3333

3434
let expanded = std::str::from_utf8(&output.stdout)?.to_string();

ctest-next/src/runner.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ pub fn __compile_test(
146146

147147
let output = cmd.output()?;
148148
if !output.status.success() {
149-
return Err(std::str::from_utf8(&output.stderr)?.into());
149+
let stderr = std::str::from_utf8(&output.stderr)?;
150+
return Err(format!("compile test failed with {}: {}", output.status, stderr).into());
150151
}
151152

152153
Ok(binary_path)
@@ -171,7 +172,8 @@ pub fn __run_test<P: AsRef<Path>>(test_binary: P) -> Result<String> {
171172
let output = cmd.output()?;
172173

173174
if !output.status.success() {
174-
return Err(std::str::from_utf8(&output.stderr)?.into());
175+
let stderr = std::str::from_utf8(&output.stderr)?;
176+
return Err(format!("run test failed with {}: {}", output.status, stderr).into());
175177
}
176178

177179
Ok(std::str::from_utf8(&output.stdout)?.to_string())

0 commit comments

Comments
 (0)