]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test: Add support for negative content pattern matching
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Jul 2022 16:47:08 +0000 (18:47 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Jul 2022 16:47:08 +0000 (18:47 +0200)
test/run

index 074c0295783b19dc8e4e7951b99881c129993157..d5b338957aacd94f9c8478f5f50baf1d325518ff 100755 (executable)
--- 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() {