From 42c0de1314b9be30e62d58e4543abced5c608fa6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Wed, 17 Feb 2021 00:40:01 +0100 Subject: [PATCH] better reporting of valgrind errors --- cli/tests/cli_run.rs | 34 +++++++++++++++++++++++++++++++++- cli/tests/helpers.rs | 12 ++++++------ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 48f682c03b..0819fa03a0 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -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, + // #[serde(default)] + // xwhat: Option, + // } + // + // #[derive(Debug, Deserialize, Clone)] + // pub struct ValgrindErrorXWhat { + // text: String, + // #[serde(default)] + // leakedbytes: Option, + // #[serde(default)] + // leakedblocks: Option, + // } + 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() { diff --git a/cli/tests/helpers.rs b/cli/tests/helpers.rs index 376158d678..27e8ad1044 100644 --- a/cli/tests/helpers.rs +++ b/cli/tests/helpers.rs @@ -192,20 +192,20 @@ struct ValgrindDummyStruct {} #[derive(Debug, Deserialize, Clone)] pub struct ValgrindError { - kind: String, + pub kind: String, #[serde(default)] - what: Option, + pub what: Option, #[serde(default)] - xwhat: Option, + pub xwhat: Option, } #[derive(Debug, Deserialize, Clone)] pub struct ValgrindErrorXWhat { - text: String, + pub text: String, #[serde(default)] - leakedbytes: Option, + pub leakedbytes: Option, #[serde(default)] - leakedblocks: Option, + pub leakedblocks: Option, } #[allow(dead_code)]