From 5c009584fb497dba69413d91bebbf5685519f6b3 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Fri, 23 Aug 2024 03:31:00 -0700 Subject: [PATCH] Add missing eqwalizer OTP version check in tests Summary: Eqwalizer is not supported for OTP < 26. The previous diff to skip running eqwalizer tests for OTP25 missed one. Reviewed By: RobinMorisset Differential Revision: D61711285 fbshipit-source-id: 93c496fc21c0ed1d60cd69bc82c84a1f3eadfbb8 --- crates/elp/src/bin/main.rs | 193 +++++++++++++++++++------------------ 1 file changed, 99 insertions(+), 94 deletions(-) diff --git a/crates/elp/src/bin/main.rs b/crates/elp/src/bin/main.rs index 5e506e630..3cf0962f7 100644 --- a/crates/elp/src/bin/main.rs +++ b/crates/elp/src/bin/main.rs @@ -311,108 +311,113 @@ mod tests { // This function is a simplified/inlined version of eqwalizer_cli::eqwalize_app, // with panics in case of failures, and checks eqWAlization results per module. pub fn eqwalize_all_snapshots(project: &str, app: &str, buck: bool, config: EqwalizerConfig) { - if !buck || cfg!(feature = "buck") { - let mut cli = Fake::default(); - let project_config = DiscoverConfig::new(!buck, "test"); - let str_path = project_path(project); - let project_path: &Path = Path::new(&str_path); - let mut loaded = load::load_project_at( - &mut cli, - project_path, - project_config, - IncludeOtp::Yes, - Mode::Cli, - &BUCK_QUERY_CONFIG, - ) - .with_context(|| format!("Failed to load project at {}", str_path)) - .unwrap(); - loaded - .analysis_host - .raw_database_mut() - .set_eqwalizer_config(Arc::new(config)); - build::compile_deps(&loaded, &mut cli) - .with_context(|| format!("Failed to compile deps for project {}", project)) - .unwrap(); - - let analysis = loaded.analysis(); - let module_index = analysis - .module_index(loaded.project_id) - .with_context(|| format!("No module index for project {}", project)) + if otp_supported_by_eqwalizer() { + if !buck || cfg!(feature = "buck") { + let mut cli = Fake::default(); + let project_config = DiscoverConfig::new(!buck, "test"); + let str_path = project_path(project); + let project_path: &Path = Path::new(&str_path); + let mut loaded = load::load_project_at( + &mut cli, + project_path, + project_config, + IncludeOtp::Yes, + Mode::Cli, + &BUCK_QUERY_CONFIG, + ) + .with_context(|| format!("Failed to load project at {}", str_path)) .unwrap(); - let file_ids: Vec = module_index - .iter_own() - .filter_map(|(_name, _source, file_id)| { - if analysis.file_app_name(file_id).ok()? == Some(AppName(app.into())) { - Some(file_id) - } else { - None - } - }) - .collect(); - - let files_count = file_ids.len(); - let project_id = loaded.project_id; - // Use 4 instances for tests - let chunk_size = (files_count + 3) / 4; - let output = file_ids - .clone() - .chunks(chunk_size) - .par_bridge() - .map_with(analysis.clone(), move |analysis, file_ids| { - analysis - .eqwalizer_diagnostics(project_id, file_ids.to_vec()) - .expect("cancelled") - }) - .fold(EqwalizerDiagnostics::default, |acc, output| { - acc.combine((*output).clone()) - }) - .reduce(EqwalizerDiagnostics::default, |acc, other| { - acc.combine(other) - }); - - match output { - EqwalizerDiagnostics::Diagnostics { - errors: diagnostics_by_module, - .. - } => { - for file_id in file_ids { - let mut cli = Fake::default(); - let pretty_reporter = - &mut reporting::PrettyReporter::new(&analysis, &loaded, &mut cli); - let module = module_index.module_for_file(file_id).unwrap(); - if let Some(diagnostics) = diagnostics_by_module.get(module.as_str()) { + loaded + .analysis_host + .raw_database_mut() + .set_eqwalizer_config(Arc::new(config)); + build::compile_deps(&loaded, &mut cli) + .with_context(|| format!("Failed to compile deps for project {}", project)) + .unwrap(); + + let analysis = loaded.analysis(); + let module_index = analysis + .module_index(loaded.project_id) + .with_context(|| format!("No module index for project {}", project)) + .unwrap(); + let file_ids: Vec = module_index + .iter_own() + .filter_map(|(_name, _source, file_id)| { + if analysis.file_app_name(file_id).ok()? == Some(AppName(app.into())) { + Some(file_id) + } else { + None + } + }) + .collect(); + + let files_count = file_ids.len(); + let project_id = loaded.project_id; + // Use 4 instances for tests + let chunk_size = (files_count + 3) / 4; + let output = file_ids + .clone() + .chunks(chunk_size) + .par_bridge() + .map_with(analysis.clone(), move |analysis, file_ids| { + analysis + .eqwalizer_diagnostics(project_id, file_ids.to_vec()) + .expect("cancelled") + }) + .fold(EqwalizerDiagnostics::default, |acc, output| { + acc.combine((*output).clone()) + }) + .reduce(EqwalizerDiagnostics::default, |acc, other| { + acc.combine(other) + }); + + match output { + EqwalizerDiagnostics::Diagnostics { + errors: diagnostics_by_module, + .. + } => { + for file_id in file_ids { + let mut cli = Fake::default(); + let pretty_reporter = + &mut reporting::PrettyReporter::new(&analysis, &loaded, &mut cli); + let module = module_index.module_for_file(file_id).unwrap(); + if let Some(diagnostics) = diagnostics_by_module.get(module.as_str()) { + pretty_reporter + .write_eqwalizer_diagnostics(file_id, &diagnostics) + .with_context(|| { + format!( + "Failed to write diagnostics for {}", + module.as_str() + ) + }) + .unwrap(); + } pretty_reporter - .write_eqwalizer_diagnostics(file_id, &diagnostics) + .write_error_count() .with_context(|| { format!("Failed to write diagnostics for {}", module.as_str()) }) .unwrap(); + + let exp_path = expect_file!(format!( + "../resources/test/{}/{}/{}.pretty", + project, + app, + module.as_str() + )); + let (stdout, _) = cli.to_strings(); + assert_normalised_file(exp_path, &stdout, project_path.into()); } - pretty_reporter - .write_error_count() - .with_context(|| { - format!("Failed to write diagnostics for {}", module.as_str()) - }) - .unwrap(); - - let exp_path = expect_file!(format!( - "../resources/test/{}/{}/{}.pretty", - project, - app, - module.as_str() - )); - let (stdout, _) = cli.to_strings(); - assert_normalised_file(exp_path, &stdout, project_path.into()); } - } - EqwalizerDiagnostics::NoAst { module } => { - panic!( - "Could not run tests because module {} was not found", - module - ) - } - EqwalizerDiagnostics::Error(error) => { - panic!("Could not run tests: {}", error) + EqwalizerDiagnostics::NoAst { module } => { + panic!( + "Could not run tests because module {} was not found", + module + ) + } + EqwalizerDiagnostics::Error(error) => { + panic!("Could not run tests: {}", error) + } } } }