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