]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Add check for expected return codes
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Dec 2024 18:30:05 +0000 (18:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Dec 2024 18:30:05 +0000 (18:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/testsuite.h

index 6cfbc1794c0cb119d7aeb650f41bce34bfc6e401..db69f769d310b359743fa26888f9f8ccf41d0cba 100644 (file)
@@ -171,6 +171,21 @@ ERROR:
                } \
        } while (0)
 
+#define ASSERT_ERROR(expr, e) \
+       do { \
+               int __r = expr; \
+               if (__r >= 0) { \
+                       LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
+                               __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+                       goto FAIL; \
+               } else if (e != -__r) { \
+                       LOG_ERROR("Failed assertion: " #expr " failed with (%d - %s) " \
+                               "but was expected to fail with (%d - %s) in %s:%d\n", \
+                               errno, strerror(-__r), e, strerror(e), __FILE__, __LINE__); \
+                       goto FAIL; \
+               } \
+       } while (0)
+
 #define ASSERT_ERRNO(expr, e) \
        do { \
                if (!(expr)) { \