From: Joel Rosdahl Date: Tue, 26 Jul 2022 16:47:08 +0000 (+0200) Subject: test: Add support for negative content pattern matching X-Git-Tag: v4.7~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=429d335f83866f703757ae8ffe1d50adb56af68d;p=thirdparty%2Fccache.git test: Add support for negative content pattern matching --- diff --git a/test/run b/test/run index 074c02957..d5b338957 100755 --- a/test/run +++ b/test/run @@ -278,9 +278,19 @@ expect_content_pattern() { if [ ! -e "$file" ]; then test_failed_internal "$file not found" fi - if [[ "$(<$file)" != $pattern ]]; then - test_failed_internal "Bad content of $file\nExpected pattern: $pattern\nActual: $(<$file)" + + local content="$(<$file)" + if [[ $pattern == !* ]]; then + pattern=${pattern:1} + if [[ "${content}" == $pattern ]]; then + test_failed_internal "Bad content of $file\nContent: $(<$file)\nMatched pattern: $pattern" + fi + else + if [[ "${content}" != $pattern ]]; then + test_failed_internal "Bad content of $file\nContent: $(<$file)\nDid not match pattern: $pattern" + fi fi + } expect_contains() {