better reporting of valgrind errors

This commit is contained in:
Folkert 2021-02-17 00:40:01 +01:00
parent 6d6c7a294a
commit 42c0de1314
2 changed files with 39 additions and 7 deletions

View file

@ -13,6 +13,7 @@ mod helpers;
mod cli_run {
use crate::helpers::{
example_file, extract_valgrind_errors, fixture_file, run_cmd, run_roc, run_with_valgrind,
ValgrindError, ValgrindErrorXWhat,
};
use serial_test::serial;
use std::path::Path;
@ -59,8 +60,39 @@ mod cli_run {
panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nvalgrind xml was: \"{}\"\n\nvalgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", err, raw_xml, valgrind_out.stdout, valgrind_out.stderr);
});
// #[derive(Debug, Deserialize, Clone)]
// pub struct ValgrindError {
// kind: String,
// #[serde(default)]
// what: Option<String>,
// #[serde(default)]
// xwhat: Option<ValgrindErrorXWhat>,
// }
//
// #[derive(Debug, Deserialize, Clone)]
// pub struct ValgrindErrorXWhat {
// text: String,
// #[serde(default)]
// leakedbytes: Option<isize>,
// #[serde(default)]
// leakedblocks: Option<isize>,
// }
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
for error in memory_errors {
let ValgrindError { kind, what, xwhat } = error;
println!("Valgrind Error: {}\n", kind);
if let Some(ValgrindErrorXWhat {
text,
leakedbytes: _,
leakedblocks: _,
}) = xwhat
{
println!(" {}", text);
}
}
panic!("Valgrind reported memory errors");
}
} else {
let exit_code = match valgrind_out.status.code() {

View file

@ -192,20 +192,20 @@ struct ValgrindDummyStruct {}
#[derive(Debug, Deserialize, Clone)]
pub struct ValgrindError {
kind: String,
pub kind: String,
#[serde(default)]
what: Option<String>,
pub what: Option<String>,
#[serde(default)]
xwhat: Option<ValgrindErrorXWhat>,
pub xwhat: Option<ValgrindErrorXWhat>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct ValgrindErrorXWhat {
text: String,
pub text: String,
#[serde(default)]
leakedbytes: Option<isize>,
pub leakedbytes: Option<isize>,
#[serde(default)]
leakedblocks: Option<isize>,
pub leakedblocks: Option<isize>,
}
#[allow(dead_code)]