Get tests working

This commit is contained in:
Sam Mohr 2024-08-14 19:31:45 -07:00
parent 3662c90346
commit 4ec213a114
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
2 changed files with 75 additions and 71 deletions

View file

@ -12,8 +12,7 @@ mod helpers;
#[cfg(test)] #[cfg(test)]
mod glue_cli_run { mod glue_cli_run {
use crate::helpers::fixtures_dir; use crate::helpers::fixtures_dir;
use cli_utils::helpers::{has_error, run_glue, run_roc, Out}; use cli_utils::helpers::{Out, Run};
use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
#[cfg(all(target_os = "linux", target_arch = "x86_64"))] #[cfg(all(target_os = "linux", target_arch = "x86_64"))]
@ -46,7 +45,7 @@ mod glue_cli_run {
fn $test_name() { fn $test_name() {
let dir = fixtures_dir($fixture_dir); let dir = fixtures_dir($fixture_dir);
generate_glue_for(&dir, std::iter::empty()); // generate_glue_for(&dir, std::iter::empty());
fn validate<'a, I: IntoIterator<Item = &'a str>>(dir: PathBuf, args: I) { fn validate<'a, I: IntoIterator<Item = &'a str>>(dir: PathBuf, args: I) {
let out = run_app(&dir.join("app.roc"), args); let out = run_app(&dir.join("app.roc"), args);
@ -198,83 +197,76 @@ mod glue_cli_run {
assert_eq!(all_fixtures, &mut VecSet::default()); assert_eq!(all_fixtures, &mut VecSet::default());
} }
fn generate_glue_for<'a, I: IntoIterator<Item = &'a str>>( // fn generate_glue_for<'a, I: IntoIterator<Item = &'a str>>(
platform_dir: &'a Path, // platform_dir: &'a Path,
args: I, // args: I,
) -> Out { // ) -> Out {
let platform_module_path = platform_dir.join("platform.roc"); // let platform_module_path = platform_dir.join("platform.roc");
let glue_dir = platform_dir.join("test_glue"); // let glue_dir = platform_dir.join("test_glue");
let fixture_templates_dir = platform_dir // let fixture_templates_dir = platform_dir
.parent() // .parent()
.unwrap() // .unwrap()
.parent() // .parent()
.unwrap() // .unwrap()
.join("fixture-templates"); // .join("fixture-templates");
// Copy the rust template from the templates directory into the fixture dir. // // Copy the rust template from the templates directory into the fixture dir.
dircpy::CopyBuilder::new(fixture_templates_dir.join("rust"), platform_dir) // dircpy::CopyBuilder::new(fixture_templates_dir.join("rust"), platform_dir)
.overwrite(true) // overwrite any files that were already present // .overwrite(true) // overwrite any files that were already present
.run() // .run()
.unwrap(); // .unwrap();
// Delete the glue file to make sure we're actually regenerating it! // // Delete the glue file to make sure we're actually regenerating it!
if glue_dir.exists() { // if glue_dir.exists() {
fs::remove_dir_all(&glue_dir) // fs::remove_dir_all(&glue_dir)
.expect("Unable to remove test_glue dir in order to regenerate it in the test"); // .expect("Unable to remove test_glue dir in order to regenerate it in the test");
} // }
let rust_glue_spec = fixture_templates_dir // let rust_glue_spec = fixture_templates_dir
.parent() // .parent()
.unwrap() // .unwrap()
.parent() // .parent()
.unwrap() // .unwrap()
.join("src") // .join("src")
.join("RustGlue.roc"); // .join("RustGlue.roc");
// Generate a fresh test_glue for this platform // // Generate a fresh test_glue for this platform
let parts : Vec<_> = // let parts : Vec<_> =
// converting these all to String avoids lifetime issues // // converting these all to String avoids lifetime issues
std::iter::once("glue".to_string()).chain( // std::iter::once("glue".to_string()).chain(
args.into_iter().map(|arg| arg.to_string()).chain([ // args.into_iter().map(|arg| arg.to_string()).chain([
rust_glue_spec.to_str().unwrap().to_string(), // rust_glue_spec.to_str().unwrap().to_string(),
glue_dir.to_str().unwrap().to_string(), // glue_dir.to_str().unwrap().to_string(),
platform_module_path.to_str().unwrap().to_string(), // platform_module_path.to_str().unwrap().to_string(),
]), // ]),
).collect(); // ).collect();
let glue_out = run_glue(parts.iter()); // let glue_out = run_glue(parts.iter());
if has_error(&glue_out.stderr) { // if has_error(&glue_out.stderr) {
panic!( // panic!(
"`roc {}` command had unexpected stderr: {}", // "`roc {}` command had unexpected stderr: {}",
parts.join(" "), // parts.join(" "),
glue_out.stderr // glue_out.stderr
); // );
} // }
assert!(glue_out.status.success(), "bad status {glue_out:?}"); // assert!(glue_out.status.success(), "bad status {glue_out:?}");
glue_out // glue_out
} // }
fn run_app<'a, 'b, I: IntoIterator<Item = &'a str>>(app_file: &'b Path, args: I) -> Out { fn run_app<'a, 'b, I: IntoIterator<Item = &'a str>>(app_file: &'b Path, args: I) -> Out {
// Generate test_glue for this platform // Generate test_glue for this platform
let compile_out = run_roc( let compile_out = Run::new_roc()
// converting these all to String avoids lifetime issues .add_args(
args.into_iter() // converting these all to String avoids lifetime issues
.map(|arg| arg.to_string()) args.into_iter()
.chain([app_file.to_str().unwrap().to_string()]), .map(|arg| arg.to_string())
&[], .chain([app_file.to_str().unwrap().to_string()]),
&[], )
); .run();
if has_error(&compile_out.stderr) { compile_out.assert_clean_success();
panic!(
"`roc` command had unexpected stderr: {}",
compile_out.stderr
);
}
assert!(compile_out.status.success(), "bad status {compile_out:?}");
compile_out compile_out
} }

View file

@ -1,5 +1,7 @@
#![cfg(test)] #![cfg(test)]
use std::io::Read;
use indoc::indoc; use indoc::indoc;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -160,10 +162,20 @@ fn run_with_valgrind(binary_path: &std::path::Path) {
.to_str() .to_str()
.unwrap(); .unwrap();
let (valgrind_out, raw_xml) = let valgrind_out = cli_utils::helpers::Run::new_roc()
cli_utils::helpers::run_with_valgrind([], &[generated_filename.to_string()]); .arg(generated_filename)
.run_with_valgrind();
if valgrind_out.status.success() { if valgrind_out.status.success() {
let mut raw_xml = String::new();
valgrind_out
.valgrind_xml
.as_ref()
.unwrap()
.read_to_string(&mut raw_xml)
.unwrap();
let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| {
panic!( panic!(
indoc!( indoc!(