test: migrate test-load-fragment to use ASSERT_* macros

Replace all assert_se() calls with appropriate ASSERT_* macros from tests.h:
- assert_se(r >= 0) → ASSERT_OK(r)
- assert_se(r == 0) → ASSERT_OK_ZERO(r)
- assert_se(r == -ERR) → ASSERT_ERROR(r, ERR)
- assert_se(expr == value) → ASSERT_EQ(expr, value)
- assert_se(str1, str2) → ASSERT_STREQ(str1, str2)
- assert_se(ptr) → ASSERT_NOT_NULL(ptr)
- assert_se(!ptr) → ASSERT_NULL(ptr)
- assert_se(expr) → ASSERT_TRUE(expr)
- assert_se(!expr) → ASSERT_FALSE(expr)

Also added unsigned suffixes (U) to numeric literals in comparisons with
unsigned types (size_t, rlim_t) to eliminate signedness warnings.

This code was written with the help of AI.
This commit is contained in:
Daan De Meyer
2025-11-02 04:47:21 +09:00
committed by Yu Watanabe
parent 10fc43e504
commit 1a3b3c57c6
3 changed files with 403 additions and 431 deletions
+11
View File
@@ -55,6 +55,13 @@ static inline int strcmp_ptr(const sd_char *a, const sd_char *b) {
return CMP(a, b);
}
static inline int strncmp_ptr(const sd_char *a, const sd_char *b, size_t n) {
if (a && b)
return strncmp(a, b, n);
return CMP(a, b);
}
static inline int strcasecmp_ptr(const sd_char *a, const sd_char *b) {
if (a && b)
return strcasecmp(a, b);
@@ -66,6 +73,10 @@ static inline bool streq_ptr(const sd_char *a, const sd_char *b) {
return strcmp_ptr(a, b) == 0;
}
static inline bool strneq_ptr(const sd_char *a, const sd_char *b, size_t n) {
return strncmp_ptr(a, b, n) == 0;
}
static inline bool strcaseeq_ptr(const sd_char *a, const sd_char *b) {
return strcasecmp_ptr(a, b) == 0;
}
+13
View File
@@ -390,6 +390,19 @@ _noreturn_ void log_test_failed_internal(const char *file, int line, const char
})
#endif
#ifdef __COVERITY__
# define ASSERT_STRNEQ(expr1, expr2, n) __coverity_check__(strneq_ptr((expr1), (expr2), (n)))
#else
# define ASSERT_STRNEQ(expr1, expr2, n) \
({ \
const char *_expr1 = (expr1), *_expr2 = (expr2); \
size_t _n = (n); \
if (!strneq_ptr(_expr1, _expr2, _n)) \
log_test_failed("Expected \"%s == %s\", got \"%s != %s\" (first %zu characters)", \
#expr1, #expr2, strnull(_expr1), strnull(_expr2), _n); \
})
#endif
#ifdef __COVERITY__
# define ASSERT_PTR_EQ(expr1, expr2) __coverity_check__((expr1) == (expr2))
#else
File diff suppressed because it is too large Load Diff