aboutsummaryrefslogtreecommitdiff
path: root/tests/ls_test.h
diff options
context:
space:
mode:
authorLion Kortlepel <[email protected]>2026-01-25 16:22:45 +0000
committerLion Kortlepel <[email protected]>2026-01-25 16:22:45 +0000
commitc781f2c7a4a41fad1a7e5e66ebb258c1fc8a415a (patch)
treef56f9198b5edf96269c3fc1d13726c4f7bcc0a80 /tests/ls_test.h
parent4ad26f81a127d7be032bbe53d8141d6bc6f20e40 (diff)
downloadargs-c781f2c7a4a41fad1a7e5e66ebb258c1fc8a415a.tar.zst
args-c781f2c7a4a41fad1a7e5e66ebb258c1fc8a415a.zip
feat: implement required arguments, add tests
bump ls_test to 1.3 for ASSERT_STR_{EQ, NEQ}
Diffstat (limited to 'tests/ls_test.h')
-rw-r--r--tests/ls_test.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/ls_test.h b/tests/ls_test.h
index 31d87f8..2077477 100644
--- a/tests/ls_test.h
+++ b/tests/ls_test.h
@@ -1,6 +1,6 @@
/* Lion's Standard (LS) test harness.
*
- * Version: 1.2
+ * 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:
@@ -119,6 +121,38 @@
} \
} 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) \
do { \
__typeof__(a) _a = (a); \