Log output on cli run error

This commit is contained in:
Brendan Hansknecht 2020-10-13 19:41:45 -07:00
parent 4228d3ac36
commit d2cfd8e195
2 changed files with 22 additions and 7 deletions

View File

@ -23,8 +23,14 @@ mod cli_run {
let valgrind_out =
run_with_valgrind(&[example_file("hello-world", "app").to_str().unwrap()]);
assert!(&valgrind_out.stdout.ends_with("Hello, World!!!!!!!!!!!!!\n"));
assert!(valgrind_out.status.success());
let ending = "Hello, World!!!!!!!!!!!!!\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
"expected output to end with {:?} but instead got {:?}",
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
@ -51,10 +57,14 @@ mod cli_run {
let valgrind_out =
run_with_valgrind(&[example_file("quicksort", "app").to_str().unwrap()]);
assert!(&valgrind_out
.stdout
.ends_with("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"));
assert!(valgrind_out.status.success());
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
"expected output to end with {:?} but instead got {:?}",
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);
@ -85,10 +95,14 @@ mod cli_run {
let valgrind_out =
run_with_valgrind(&[example_file("multi-module", "app").to_str().unwrap()]);
assert!(&valgrind_out
.stdout
.ends_with("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"));
assert!(valgrind_out.status.success());
let ending = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n";
if !&valgrind_out.stdout.ends_with(ending) {
panic!(
"expected output to end with {:?} but instead got {:?}",
ending, &valgrind_out.stdout
);
}
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
if !memory_errors.is_empty() {
panic!("{:?}", memory_errors);

View File

@ -122,6 +122,7 @@ pub struct ValgrindErrorXWhat {
leakedblocks: Option<isize>,
}
#[allow(dead_code)]
pub fn extract_valgrind_errors(xml: &str) -> Vec<ValgrindError> {
let parsed_xml: ValgrindOutput =
from_str(xml).expect("failed to parse the `valgrind` xml output");