diff --git a/test/litest.c b/test/litest.c index e60e57c4..624611e0 100644 --- a/test/litest.c +++ b/test/litest.c @@ -4840,6 +4840,32 @@ litest_logcapture_remove(struct libinput *li, struct litest_logcapture *capture) return NULL; } +#define litest_with_logcapture(li_, capture_) \ + for (struct litest_logcapture *capture_ = litest_logcapture_setup(li_); \ + capture_ != NULL; \ + capture_ = litest_logcapture_remove(li_, capture_)) + +void +_litest_assert_strv_substring(char **strv, + char *substring, + const char *file, + const char *func, + int line) +{ + if (!strv) { + _litest_abort_msg(file, line, func, + "Expected substring '%s' but strv is NULL", substring); + } + + bool found = strv_find_substring(strv, substring, NULL); + if (!found) { + _autofree_ char *strv_str = strv_join(strv, "', '"); + _litest_abort_msg(file, line, func, + "Expected substring '%s' not found in strv: ['%s']", + substring, strv_str); + } +} + void litest_push_event_frame(struct litest_device *dev) { diff --git a/test/litest.h b/test/litest.h index 7f54176b..a0639858 100644 --- a/test/litest.h +++ b/test/litest.h @@ -398,6 +398,16 @@ litest_fail_comparison_str(const char *file, #define litest_assert_double_ge(a_, b_)\ litest_assert_double_ge_epsilon((a_), (b_),LITEST_DEFAULT_EPSILON) +void +_litest_assert_strv_substring(char **strv, + char *substring, + const char *file, + const char *func, + int line); + +#define litest_assert_strv_substring(strv_, substring_) \ + _litest_assert_strv_substring(strv_, substring_, __FILE__, __func__, __LINE__) + void litest_backtrace(const char *func); enum litest_device_type {