summaryrefslogtreecommitdiff
path: root/test_util/src/assertions.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-09-14 12:21:57 -0400
committerGitHub <noreply@github.com>2023-09-14 16:21:57 +0000
commit54890ee98b9068af41214b86fb693135f0998a0a (patch)
tree9a64837d6ccfacafce6139f47c9cddb512de426d /test_util/src/assertions.rs
parent851f795001a9164572d02606587ddc5193bdfd2d (diff)
chore(tests): ability to pattern match unordered lines (#20488)
This adds the ability to pattern match unordered lines. For example, the downloading messages may appear in any order ``` [UNORDERED_START] Download https://localhost:4546/a.ts Download https://localhost:4546/b.ts [UNORDERED_END] Hello! ``` Additionally, I've made the pattern matching slightly more strict and the output better.
Diffstat (limited to 'test_util/src/assertions.rs')
-rw-r--r--test_util/src/assertions.rs41
1 files changed, 36 insertions, 5 deletions
diff --git a/test_util/src/assertions.rs b/test_util/src/assertions.rs
index 239e0e99c..91ac9dd1c 100644
--- a/test_util/src/assertions.rs
+++ b/test_util/src/assertions.rs
@@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use crate::colors;
+
#[macro_export]
macro_rules! assert_starts_with {
($string:expr, $($test:expr),+) => {
@@ -52,11 +54,40 @@ macro_rules! assert_not_contains {
#[track_caller]
pub fn assert_wildcard_match(actual: &str, expected: &str) {
- if !expected.contains("[WILDCARD]") {
+ if !expected.contains("[WILDCARD]") && !expected.contains("[IGNORE_START]") {
pretty_assertions::assert_eq!(actual, expected);
- } else if !crate::wildcard_match(expected, actual) {
- println!("OUTPUT START\n{actual}\nOUTPUT END");
- println!("EXPECTED START\n{expected}\nEXPECTED END");
- panic!("pattern match failed");
+ } else {
+ match crate::wildcard_match_detailed(expected, actual) {
+ crate::WildcardMatchResult::Success => {
+ // ignore
+ }
+ crate::WildcardMatchResult::Fail(debug_output) => {
+ println!(
+ "{}{}{}",
+ colors::bold("-- "),
+ colors::bold_red("OUTPUT"),
+ colors::bold(" START --"),
+ );
+ println!("{}", actual);
+ println!("{}", colors::bold("-- OUTPUT END --"));
+ println!(
+ "{}{}{}",
+ colors::bold("-- "),
+ colors::bold_green("EXPECTED"),
+ colors::bold(" START --"),
+ );
+ println!("{}", expected);
+ println!("{}", colors::bold("-- EXPECTED END --"));
+ println!(
+ "{}{}{}",
+ colors::bold("-- "),
+ colors::bold_blue("DEBUG"),
+ colors::bold(" START --"),
+ );
+ println!("{debug_output}");
+ println!("{}", colors::bold("-- DEBUG END --"));
+ panic!("pattern match failed");
+ }
+ }
}
}