EXPECT(3) Library Functions Manual EXPECT(3)

KS_expect_true, KS_expect_false, KS_expect_int, KS_expect_str, KS_expect_str_n, KS_expect_ptr, KS_expect_scopeunit test macros

#include <libks/expect.h>

KS_expect_true(expression);

KS_expect_false(expression);

KS_expect_int(expect, actual);

KS_expect_str(const char *expect, const char *actual);

KS_expect_str_n(const char *expect, const char *actual, size_t actual_len);

KS_expect_ptr(void *expect, void *actual);

KS_expect_scope(const char *func, int lno, varname);

The expect macros are intended to be used to construct unit tests. All macros causes the current process to exit non-zero if any unexpected outcome is encountered.

The () macro expects expression to be non-zero.

The () macro expects expression to be zero.

The () macro expects the two integers expect and actual to be equal. Note that expect and actual are not required to be of the same type.

The () macro expects expect and actual to be identical as determined using strcmp(3).

The () macro behaves like KS_expect_str() but allows the length of actual to be specified using actual_len. Intended to be used with strings lacking NUL-terminators.

The () expects the two pointers expect and actual to be equal.

The () allows the function and line used in expect error messages to be overridden, effectively taking higher precedence than the defaults __func__ and __LINE__. The override remains active until varname goes out of lexical scope.

Anton Lindqvist <anton@basename.se>

OpenBSD 7.8 February 15, 2024 EXPECT(3)