mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-17 13:47:26 +03:00
Have valgrind output XML to a tempfile
This commit is contained in:
parent
b7fd45b58c
commit
65336919fc
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2321,6 +2321,7 @@ dependencies = [
|
||||
"serde-xml-rs",
|
||||
"strip-ansi-escapes",
|
||||
"target-lexicon",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
@ -88,3 +88,4 @@ quickcheck_macros = "0.8"
|
||||
strip-ansi-escapes = "0.1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-xml-rs = "0.4"
|
||||
tempfile = "3.1.0"
|
||||
|
@ -21,9 +21,9 @@ mod cli_run {
|
||||
}
|
||||
assert!(out.status.success());
|
||||
|
||||
let valgrind_out =
|
||||
let (valgrind_out, raw_xml) =
|
||||
run_with_valgrind(&[example_file("hello-world", "app").to_str().unwrap()]);
|
||||
assert!(valgrind_out.status.success());
|
||||
|
||||
let ending = "Hello, World!!!!!!!!!!!!!\n";
|
||||
if !&valgrind_out.stdout.ends_with(ending) {
|
||||
panic!(
|
||||
@ -31,10 +31,11 @@ mod cli_run {
|
||||
ending, &valgrind_out.stdout
|
||||
);
|
||||
}
|
||||
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
|
||||
let memory_errors = extract_valgrind_errors(&raw_xml);
|
||||
if !memory_errors.is_empty() {
|
||||
panic!("{:?}", memory_errors);
|
||||
}
|
||||
assert!(valgrind_out.status.success());
|
||||
}
|
||||
check_hello_world_output(run_roc(&[
|
||||
"build",
|
||||
@ -55,9 +56,8 @@ mod cli_run {
|
||||
}
|
||||
assert!(out.status.success());
|
||||
|
||||
let valgrind_out =
|
||||
let (valgrind_out, raw_xml) =
|
||||
run_with_valgrind(&[example_file("quicksort", "app").to_str().unwrap()]);
|
||||
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!(
|
||||
@ -65,10 +65,11 @@ mod cli_run {
|
||||
ending, &valgrind_out.stdout
|
||||
);
|
||||
}
|
||||
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
|
||||
let memory_errors = extract_valgrind_errors(&raw_xml);
|
||||
if !memory_errors.is_empty() {
|
||||
panic!("{:?}", memory_errors);
|
||||
}
|
||||
assert!(valgrind_out.status.success());
|
||||
}
|
||||
|
||||
// TODO: Uncomment this once we are correctly freeing the RocList even when in dev build.
|
||||
@ -93,9 +94,8 @@ mod cli_run {
|
||||
}
|
||||
assert!(out.status.success());
|
||||
|
||||
let valgrind_out =
|
||||
let (valgrind_out, raw_xml) =
|
||||
run_with_valgrind(&[example_file("multi-module", "app").to_str().unwrap()]);
|
||||
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!(
|
||||
@ -103,10 +103,11 @@ mod cli_run {
|
||||
ending, &valgrind_out.stdout
|
||||
);
|
||||
}
|
||||
let memory_errors = extract_valgrind_errors(&valgrind_out.stderr);
|
||||
let memory_errors = extract_valgrind_errors(&raw_xml);
|
||||
if !memory_errors.is_empty() {
|
||||
panic!("{:?}", memory_errors);
|
||||
}
|
||||
assert!(valgrind_out.status.success());
|
||||
}
|
||||
|
||||
// TODO: Uncomment this once we are correctly freeing the RocList even when in dev build.
|
||||
|
@ -3,14 +3,17 @@ extern crate inlinable_string;
|
||||
extern crate roc_collections;
|
||||
extern crate roc_load;
|
||||
extern crate roc_module;
|
||||
extern crate tempfile;
|
||||
|
||||
use roc_cli::repl::{INSTRUCTIONS, PROMPT, WELCOME_MESSAGE};
|
||||
use serde::Deserialize;
|
||||
use serde_xml_rs::from_str;
|
||||
use std::env;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, ExitStatus, Stdio};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
pub struct Out {
|
||||
pub stdout: String,
|
||||
@ -57,13 +60,17 @@ pub fn run_roc(args: &[&str]) -> Out {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn run_with_valgrind(args: &[&str]) -> Out {
|
||||
pub fn run_with_valgrind(args: &[&str]) -> (Out, String) {
|
||||
//TODO: figure out if there is a better way to get the valgrind executable.
|
||||
let mut cmd = Command::new("valgrind");
|
||||
let named_tempfile =
|
||||
NamedTempFile::new().expect("Unable to create tempfile for valgrind results");
|
||||
let filepath = named_tempfile.path().to_str().unwrap();
|
||||
|
||||
cmd.arg("--tool=memcheck");
|
||||
cmd.arg("--xml=yes");
|
||||
cmd.arg("--xml-fd=2");
|
||||
cmd.arg(format!("--xml-file={}", filepath));
|
||||
|
||||
for arg in args {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
@ -72,11 +79,19 @@ pub fn run_with_valgrind(args: &[&str]) -> Out {
|
||||
.output()
|
||||
.expect("failed to execute compiled `valgrind` binary in CLI test");
|
||||
|
||||
Out {
|
||||
stdout: String::from_utf8(output.stdout).unwrap(),
|
||||
stderr: String::from_utf8(output.stderr).unwrap(),
|
||||
status: output.status,
|
||||
}
|
||||
let mut file = named_tempfile.into_file();
|
||||
let mut raw_xml = String::new();
|
||||
|
||||
file.read_to_string(&mut raw_xml).unwrap();
|
||||
|
||||
(
|
||||
Out {
|
||||
stdout: String::from_utf8(output.stdout).unwrap(),
|
||||
stderr: String::from_utf8(output.stderr).unwrap(),
|
||||
status: output.status,
|
||||
},
|
||||
raw_xml,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -125,7 +140,8 @@ pub struct ValgrindErrorXWhat {
|
||||
#[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");
|
||||
from_str(xml).unwrap_or_else(|err|
|
||||
panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nRaw valgrind output was:\n\n{}", err, xml));
|
||||
parsed_xml
|
||||
.fields
|
||||
.iter()
|
||||
|
Loading…
Reference in New Issue
Block a user