Z / libzlang 0.29.0
C99 runtime library and the Zlang 0.29 source-to-source compiler
Loading...
Searching...
No Matches
testing.h File Reference

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

#include "zlang/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  zlang_test_context_t
struct  zlang_test_case_t

Macros

#define ZLANG_CHECK(context, condition)
#define ZLANG_CHECK_UINT(context, expected, actual)

Typedefs

typedef struct zlang_test_context_t zlang_test_context_t
typedef void(*) zlang_test_fn_t(zlang_test_context_t *const context)
typedef struct zlang_test_case_t zlang_test_case_t

Functions

ZLANG_STATIC_INLINE void zlang_test_report_failure (zlang_test_context_t *const context, const char *const file, const unsigned int line, const char *const expression)
ZLANG_STATIC_INLINE void zlang_test_report_failure_uint (zlang_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)
ZLANG_STATIC_INLINE int zlang_test_run_cases (const char *const suite, const zlang_test_case_t *const cases, const size_t case_count, const char *const requested_case)
ZLANG_STATIC_INLINE int zlang_test_main (const int argc, char *const *const argv, const char *const suite, const zlang_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

◆ ZLANG_CHECK

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

Fail the current case when condition is false.

◆ ZLANG_CHECK_UINT

#define ZLANG_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) { \
zlang_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

◆ zlang_test_case_t

typedef struct zlang_test_case_t zlang_test_case_t

Name and implementation of one test case.

◆ zlang_test_context_t

typedef struct zlang_test_context_t zlang_test_context_t

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

◆ zlang_test_fn_t

typedef void(*) zlang_test_fn_t(zlang_test_context_t *const context)

Signature of a single test case.

Function Documentation

◆ zlang_test_main()

ZLANG_STATIC_INLINE int zlang_test_main ( const int argc,
char *const *const argv,
const char *const suite,
const zlang_test_case_t *const cases,
const size_t case_count )

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

◆ zlang_test_report_failure()

ZLANG_STATIC_INLINE void zlang_test_report_failure ( zlang_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.

◆ zlang_test_report_failure_uint()

ZLANG_STATIC_INLINE void zlang_test_report_failure_uint ( zlang_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.

◆ zlang_test_run_cases()

ZLANG_STATIC_INLINE int zlang_test_run_cases ( const char *const suite,
const zlang_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.