From: Michael Tremer Date: Mon, 16 Dec 2024 18:30:05 +0000 (+0000) Subject: tests: Add check for expected return codes X-Git-Tag: 0.9.30~693 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9b2a87caabbff478fec8940c3ea5c2c73a18a81;p=pakfire.git tests: Add check for expected return codes Signed-off-by: Michael Tremer --- diff --git a/tests/testsuite.h b/tests/testsuite.h index 6cfbc1794..db69f769d 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -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)) { \