From ad8d265e29e66e04082bc5d4bf6f68130ac8f6d6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 10 Jul 2024 16:44:37 -0400 Subject: chore: fix flaky publish::npm_workspace test (#24511) --- tests/util/server/src/lib.rs | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'tests/util/server/src/lib.rs') diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs index d23fde0dd..f09e7c224 100644 --- a/tests/util/server/src/lib.rs +++ b/tests/util/server/src/lib.rs @@ -846,25 +846,45 @@ pub fn wildcard_match_detailed( ); return WildcardMatchResult::Fail(output_lines.join("\n")); } - for (actual, expected) in actual_lines.iter().zip(expected_lines.iter()) + + if let Some(invalid_expected) = + expected_lines.iter().find(|e| e.contains("[WILDCARD]")) { - if actual != expected { + panic!( + concat!( + "Cannot use [WILDCARD] inside [UNORDERED_START]. Use [WILDLINE] instead.\n", + " Invalid expected line: {}" + ), + invalid_expected + ); + } + + for actual_line in actual_lines { + let maybe_found_index = + expected_lines.iter().position(|expected_line| { + actual_line == *expected_line + || wildcard_match(expected_line, actual_line) + }); + if let Some(found_index) = maybe_found_index { + let expected = expected_lines.remove(found_index); + output_lines.push(format!( + "{}", + colors::gray(annotate_whitespace(expected)) + )); + } else { output_lines .push("==== UNORDERED LINE DID NOT MATCH ====".to_string()); output_lines.push(format!( " ACTUAL: {}", - colors::red(annotate_whitespace(actual)) - )); - output_lines.push(format!( - "EXPECTED: {}", - colors::green(annotate_whitespace(expected)) + colors::red(annotate_whitespace(actual_line)) )); + for expected in expected_lines { + output_lines.push(format!( + " EXPECTED ANY: {}", + colors::green(annotate_whitespace(expected)) + )); + } return WildcardMatchResult::Fail(output_lines.join("\n")); - } else { - output_lines.push(format!( - "{}", - colors::gray(annotate_whitespace(expected)) - )); } } } -- cgit v1.2.3