diff options
Diffstat (limited to 'tests/ls_test.h')
| -rw-r--r-- | tests/ls_test.h | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/tests/ls_test.h b/tests/ls_test.h index 5dda4aa..2077477 100644 --- a/tests/ls_test.h +++ b/tests/ls_test.h @@ -1,6 +1,6 @@ /* Lion's Standard (LS) test harness. * - * Version: 1.1 + * Version: 1.3 * Website: https://libls.org * Repo: https://github.com/libls/test * SPDX-License-Identifier: MIT @@ -20,6 +20,8 @@ * you use asserts other than `ASSERT` (e.g. ASSERT_EQ), and the constructor * attribute __attribute__((destructor)) for automatic test registration. * + * Supports string comparisons using ASSERT_STR_EQ and ASSERT_STR_NEQ. + * * ==== 2. HOW TO USE ==== * * 1. Copy this file into your project and include it: @@ -96,6 +98,8 @@ _func += 6; \ fprintf(stderr, "%s: FAILED: %s (%s:%d)\n", _func, #cond, \ __FILE__, __LINE__); \ + ++lst_fail; \ + return 1; \ } \ } while (0) @@ -115,7 +119,38 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ + } while (0) + +#define ASSERT_STR_EQ(a, b) \ + do { \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + if (strcmp(_a, _b) != 0) { \ + const char* _func = __func__; \ + if (strncmp(_func, "lst_t_", 6) == 0) \ + _func += 6; \ + fprintf(stderr, \ + "%s: FAILED: %s == %s (actual: \"%s\" != \"%s\") (%s:%d)\n", \ + _func, #a, #b, _a, _b, __FILE__, __LINE__); \ + ++lst_fail; \ + return 1; \ + } \ + } while (0) + +#define ASSERT_STR_NEQ(a, b) \ + do { \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + if (strcmp(_a, _b) == 0) { \ + const char* _func = __func__; \ + if (strncmp(_func, "lst_t_", 6) == 0) \ + _func += 6; \ + fprintf(stderr, \ + "%s: FAILED: %s != %s (actual: \"%s\" == \"%s\") (%s:%d)\n", \ + _func, #a, #b, _a, _b, __FILE__, __LINE__); \ + ++lst_fail; \ + return 1; \ + } \ } while (0) #define ASSERT_NEQ(a, b, fmt) \ @@ -132,7 +167,6 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ } while (0) #define ASSERT_LT(a, b, fmt) \ @@ -149,7 +183,6 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ } while (0) #define ASSERT_LE(a, b, fmt) \ @@ -166,7 +199,6 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ } while (0) #define ASSERT_GT(a, b, fmt) \ @@ -183,7 +215,6 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ } while (0) #define ASSERT_GE(a, b, fmt) \ @@ -200,7 +231,6 @@ ++lst_fail; \ return 1; \ } \ - ++lst_ok; \ } while (0) #define LS_CAT2(a, b) a##b #define LS_CAT(a, b) LS_CAT2(a, b) @@ -217,7 +247,6 @@ extern lst_func* lst_funcs; extern int lst_n; extern int lst_cap; extern int lst_fail; -extern int lst_ok; void lst_reg(lst_func f); @@ -229,7 +258,6 @@ lst_func* lst_funcs; int lst_n; int lst_cap; int lst_fail = 0; -int lst_ok = 0; void lst_reg(lst_func f) { if (lst_n == lst_cap) { @@ -276,8 +304,8 @@ static int ls_test_main(int argc, char** argv) { } end: - fprintf(stderr, "%d succeeded, %d failed, %d total\n", lst_ok, lst_fail, - lst_ok + lst_fail); + fprintf(stderr, "%d succeeded, %d failed, %d total\n", lst_n - lst_fail, + lst_fail, lst_n); free(lst_funcs); if (lst_fail > 0) { |
