[gjs: 3/6] jsapi-util-args: Fix assert_match() in tests




commit e52b4d4b660bc27dfceeaa1a590a5b2f218a1397
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Jul 2 18:06:50 2021 -0700

    jsapi-util-args: Fix assert_match() in tests
    
    Apparently I never checked what happened when this assertion failed. Since
    it is only used directly in run_code_expect_exception(), the string and
    pattern are generated dynamically, so the error message would be something
    like '("message" matches "pattern")', totally unhelpful.
    
    Use g_assertion_message_cmpstr() with a made-up comparison operator, to
    give a more helpful message.

 test/gjs-test-call-args.cpp | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/test/gjs-test-call-args.cpp b/test/gjs-test-call-args.cpp
index 5e0d4ea5..17d2039d 100644
--- a/test/gjs-test-call-args.cpp
+++ b/test/gjs-test-call-args.cpp
@@ -33,15 +33,16 @@ void g_assertion_message(const char*, const char*, int, const char*,
                          const char*) __attribute__((analyzer_noreturn));
 #endif
 
-#define assert_match(str, pattern)                                           \
-    G_STMT_START {                                                           \
-        const char *__s1 = (str), *__s2 = (pattern);                         \
-        if (!g_pattern_match_simple(__s2, __s1)) {                           \
-            g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
-                                "assertion failed (\"" #str                  \
-                                "\" matches \"" #pattern "\")");             \
-        }                                                                    \
-    }                                                                        \
+#define assert_match(str, pattern)                                          \
+    G_STMT_START {                                                          \
+        const char *__s1 = (str), *__s2 = (pattern);                        \
+        if (!g_pattern_match_simple(__s2, __s1)) {                          \
+            g_assertion_message_cmpstr(                                     \
+                G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC,                \
+                "assertion failed (\"" #str "\" matches \"" #pattern "\")", \
+                __s1, "~=", __s2);                                          \
+        }                                                                   \
+    }                                                                       \
     G_STMT_END
 
 typedef enum _test_enum {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]