automerge/rust/automerge-c/test/cmocka_utils.h
Jason Kankiewicz edbb33522d Replaced the C string (*const libc::c_char)
value of the `AMresult::Error` variant with a UTF-8 string view
(`AMbyteSpan`).
2022-11-27 23:52:47 -08:00

22 lines
508 B
C

#ifndef CMOCKA_UTILS_H
#define CMOCKA_UTILS_H
#include <string.h>
/* third-party */
#include <cmocka.h>
/**
* \brief Forces the test to fail immediately and quit, printing the reason.
*
* \param[in] view A string view as an `AMbyteSpan` struct.
*/
#define fail_msg_view(msg, view) do { \
char* const c_str = test_calloc(1, view.count + 1); \
strncpy(c_str, view.src, view.count); \
print_error(msg, c_str); \
test_free(c_str); \
fail(); \
} while (0)
#endif /* CMOCKA_UTILS_H */