From 8a2bd95b26d22a9a65213bd2cf708e22f0da883b Mon Sep 17 00:00:00 2001 From: aandresen-slack <66700013+aandresen-slack@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:26:12 -0800 Subject: [PATCH] Update candidates test check to do comparison by individual element (#12) * Update candidates test check to do comparison by individual element * simpler --- src/cli/test_runners/test_runner.rs | 42 +++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/cli/test_runners/test_runner.rs b/src/cli/test_runners/test_runner.rs index 49597717..cde0989d 100644 --- a/src/cli/test_runners/test_runner.rs +++ b/src/cli/test_runners/test_runner.rs @@ -294,7 +294,11 @@ impl TestRunner { } } else if dir.contains("/migration-candidates/") { let candidates_file = format!("{}/candidates.txt", dir); - let expected_candidates_contents = fs::read_to_string(candidates_file).unwrap(); + let expected_candidates = fs::read_to_string(candidates_file) + .unwrap() + .lines() + .map(String::from) + .collect::>(); let result = result.unwrap(); @@ -309,18 +313,40 @@ impl TestRunner { } } - if migration_candidates.join("\n") == expected_candidates_contents { - (".".to_string(), Some(result.1), Some(result.0)) - } else { + let missing_candidates = expected_candidates + .iter() + .filter(|item| !migration_candidates.contains(item)) + .map(String::from) + .collect::>(); + let unexpected_candidates = migration_candidates + .iter() + .filter(|item| !expected_candidates.contains(item)) + .map(String::from) + .collect::>(); + + if unexpected_candidates.len() > 0 { test_diagnostics.push(( - dir, + dir.clone(), + format!( + "Found unexpected candidates: {}", + unexpected_candidates.join("\n") + ), + )); + } + if missing_candidates.len() > 0 { + test_diagnostics.push(( + dir.clone(), format!( - "- {}\n+ {}", - expected_candidates_contents, - migration_candidates.join("\n") + "Missing expected candidates: {}", + missing_candidates.join("\n") ), )); + } + + if unexpected_candidates.len() > 0 || missing_candidates.len() > 0 { ("F".to_string(), Some(result.1), Some(result.0)) + } else { + (".".to_string(), Some(result.1), Some(result.0)) } } else { match result {