Z / libzen 0.0.0
Header-only C99 library
Loading...
Searching...
No Matches
testing.h File Reference

Minimal header-only test runner shared by all test modules. More...

#include "zen/detail/inline.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  zen_test_context_t
struct  zen_test_case_t

Macros

#define ZEN_CHECK(context, condition)
#define ZEN_CHECK_UINT(context, expected, actual)

Typedefs

typedef struct zen_test_context_t zen_test_context_t
typedef void(*) zen_test_fn_t(zen_test_context_t *const context)
typedef struct zen_test_case_t zen_test_case_t

Functions

ZEN_STATIC_INLINE void zen_test_report_failure (zen_test_context_t *const context, const char *const file, const unsigned int line, const char *const expression)
ZEN_STATIC_INLINE void zen_test_report_failure_uint (zen_test_context_t *const context, const char *const file, const unsigned int line, const char *const expression, const uintmax_t expected, const uintmax_t actual)
ZEN_STATIC_INLINE int zen_test_run_cases (const char *const suite, const zen_test_case_t *const cases, const size_t case_count, const char *const requested_case)
ZEN_STATIC_INLINE int zen_test_main (const int argc, char *const *const argv, const char *const suite, const zen_test_case_t *const cases, const size_t case_count)

Detailed Description

Minimal header-only test runner shared by all test modules.

Macro Definition Documentation

◆ ZEN_CHECK

#define ZEN_CHECK ( context,
condition )
Value:
do { \
if (!(condition)) { \
zen_test_report_failure((context), __FILE__, (unsigned int)__LINE__, #condition); \
return; \
} \
} while (0)

Fail the current case when condition is false.

◆ ZEN_CHECK_UINT

#define ZEN_CHECK_UINT ( context,
expected,
actual )
Value:
do { \
const uintmax_t _expected_k = (uintmax_t)(expected); \
const uintmax_t _actual_k = (uintmax_t)(actual); \
if (_expected_k != _actual_k) { \
zen_test_report_failure_uint((context), __FILE__, (unsigned int)__LINE__, #actual, \
_expected_k, _actual_k); \
return; \
} \
} while (0)

Fail the current case when two unsigned values differ.

Typedef Documentation

◆ zen_test_case_t

typedef struct zen_test_case_t zen_test_case_t

Name and implementation of one test case.

◆ zen_test_context_t

typedef struct zen_test_context_t zen_test_context_t

Mutable state for one test case; no shared globals are used.

◆ zen_test_fn_t

typedef void(*) zen_test_fn_t(zen_test_context_t *const context)

Signature of a single test case.

Function Documentation

◆ zen_test_main()

ZEN_STATIC_INLINE int zen_test_main ( const int argc,
char *const *const argv,
const char *const suite,
const zen_test_case_t *const cases,
const size_t case_count )

Test executable entry point; accepts –case NAME to select one case.

◆ zen_test_report_failure()

ZEN_STATIC_INLINE void zen_test_report_failure ( zen_test_context_t *const context,
const char *const file,
const unsigned int line,
const char *const expression )

Record a failed boolean check and print its source location.

◆ zen_test_report_failure_uint()

ZEN_STATIC_INLINE void zen_test_report_failure_uint ( zen_test_context_t *const context,
const char *const file,
const unsigned int line,
const char *const expression,
const uintmax_t expected,
const uintmax_t actual )

Record a failed integer check and print expected and actual values.

◆ zen_test_run_cases()

ZEN_STATIC_INLINE int zen_test_run_cases ( const char *const suite,
const zen_test_case_t *const cases,
const size_t case_count,
const char *const requested_case )

Run every case, or only the case named by requested_case.