From 58cb8352bbd08d2364f795c2fcc1505a2335a99d Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 16 May 2023 17:12:13 -0400 Subject: [PATCH] Consistent handling of ld chained fixup warning in cli/glue tests --- crates/cli/tests/cli_run.rs | 13 ++++--------- crates/cli_utils/src/helpers.rs | 12 ++++++++++++ crates/glue/tests/test_glue_cli.rs | 8 +++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 66ef2967b8..0261da1162 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -10,8 +10,9 @@ extern crate roc_module; #[cfg(test)] mod cli_run { use cli_utils::helpers::{ - extract_valgrind_errors, file_path_from_root, fixture_file, fixtures_dir, known_bad_file, - run_cmd, run_roc, run_with_valgrind, strip_colors, Out, ValgrindError, ValgrindErrorXWhat, + extract_valgrind_errors, file_path_from_root, fixture_file, fixtures_dir, has_error, + known_bad_file, run_cmd, run_roc, run_with_valgrind, strip_colors, Out, ValgrindError, + ValgrindErrorXWhat, }; use const_format::concatcp; use indoc::indoc; @@ -149,13 +150,7 @@ mod cli_run { // for some reason, llvm prints out this warning when targeting windows let ignorable = "warning: ignoring debug info with an invalid version (0) in app\r\n"; let stderr = stderr.replacen(ignorable, "", 1); - - let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n"); - if !(stderr.is_empty() || is_reporting_runtime - // macOS ld reports this warning, but if we remove -undefined dynamic_lookup, - // linking stops working properly. - || stderr.trim() == "ld: warning: -undefined dynamic_lookup may not work with chained fixups") - { + if has_error(&stderr) { panic!("\n___________\nThe roc command:\n\n {:?}\n\nhad unexpected stderr:\n\n {}\n___________\n", compile_out.cmd_str, stderr); } diff --git a/crates/cli_utils/src/helpers.rs b/crates/cli_utils/src/helpers.rs index e6a99a58b5..fde912a7b3 100644 --- a/crates/cli_utils/src/helpers.rs +++ b/crates/cli_utils/src/helpers.rs @@ -104,6 +104,18 @@ where run_roc_with_stdin(&path_to_roc_binary(), args, &[]) } +pub fn has_error(stderr: &str) -> bool { + let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n"); + + let is_clean = stderr.is_empty() || + is_reporting_runtime || + // macOS ld reports this warning, but if we remove -undefined dynamic_lookup, + // linking stops working properly. + stderr.trim() == "ld: warning: -undefined dynamic_lookup may not work with chained fixups"; + + !is_clean +} + pub fn path_to_roc_binary() -> PathBuf { path_to_binary(if cfg!(windows) { "roc.exe" } else { "roc" }) } diff --git a/crates/glue/tests/test_glue_cli.rs b/crates/glue/tests/test_glue_cli.rs index f9075f1ec3..d3d033bd80 100644 --- a/crates/glue/tests/test_glue_cli.rs +++ b/crates/glue/tests/test_glue_cli.rs @@ -12,7 +12,7 @@ mod helpers; #[cfg(test)] mod glue_cli_run { use crate::helpers::fixtures_dir; - use cli_utils::helpers::{run_glue, run_roc, Out}; + use cli_utils::helpers::{has_error, run_glue, run_roc, Out}; use std::fs; use std::path::Path; @@ -215,8 +215,7 @@ mod glue_cli_run { let ignorable = "🔨 Rebuilding platform...\n"; let stderr = glue_out.stderr.replacen(ignorable, "", 1); - let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n"); - if !(stderr.is_empty() || is_reporting_runtime) { + if has_error(&stderr) { panic!("`roc glue` command had unexpected stderr: {}", stderr); } @@ -238,8 +237,7 @@ mod glue_cli_run { let ignorable = "🔨 Rebuilding platform...\n"; let stderr = compile_out.stderr.replacen(ignorable, "", 1); - let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n"); - if !(stderr.is_empty() || is_reporting_runtime) { + if has_error(&stderr) { panic!("`roc` command had unexpected stderr: {}", stderr); }