From ea50e1a92c012a4a79acc05251260891f51e9517 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 7 May 2025 15:55:23 +1000 Subject: [PATCH] test: add litest_assert_str_in/not_in() helpers Part-of: --- test/litest.h | 22 ++++++++++++++++++++++ test/test-log.c | 5 +---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/litest.h b/test/litest.h index e037a904..cefe231f 100644 --- a/test/litest.h +++ b/test/litest.h @@ -285,6 +285,28 @@ litest_fail_comparison_str(const char *file, _a, _b); \ } while(0) +#define litest_assert_str_in(needle_, haystack_) \ + do { \ + const char *_needle = needle_; \ + const char *_haystack = haystack_; \ + if (!strstr(_haystack, _needle)) \ + litest_fail_comparison_str(__FILE__, __LINE__, __func__,\ + "'" #needle_ "' in: '" #haystack_ "'", \ + "in", \ + _needle, _haystack); \ + } while(0) + +#define litest_needlessert_str_not_in(needle_, haystack_) \ + do { \ + const char *_needle = needle_; \ + const char *_haystack = haystack_; \ + if (!strstr(_haystack, _needle)) \ + litest_fail_comparison_str(__FILE__, __LINE__, __func__,\ + "'" #needle_ "' not in: '" #haystack_ "'", \ + "not in", \ + _needle, _haystack); \ + } while(0) + #define LITEST_DEFAULT_EPSILON 0.001 #define litest_assert_double_eq_epsilon(a_, b_, epsilon_)\ diff --git a/test/test-log.c b/test/test-log.c index dc509b6c..4aff0f7f 100644 --- a/test/test-log.c +++ b/test/test-log.c @@ -142,13 +142,10 @@ axisrange_warning_log_handler(struct libinput *libinput, const char *format, va_list args) { - const char *substr; - axisrange_log_handler_called++; litest_assert_notnull(format); - substr = strstr(format, "is outside expected range"); - litest_assert_notnull(substr); + litest_assert_str_in("is outside expected range", format); } START_TEST(log_axisrange_warning)