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