TAP (Test Anything Protocol)

Warning

This file must be included before (or instead of) ``ymo_assert.h``.

YMO_TAP_STREAM_OUT

Output stream for TAP results.

Definition
#define YMO_TAP_STREAM_OUT      stdout
YMO_TAP_STATUS_PASS

Value to return from passing unit tests.

(NOTE: YMO_TAP_PASS is preferred)

Definition
#define YMO_TAP_STATUS_PASS 0
YMO_TAP_STATUS_FAIL

Value to return from failing unit tests (any non-zero value will work — errno is always a safe bet).

(NOTE: YMO_TAP_FAIL is preferred)

Definition
#define YMO_TAP_STATUS_FAIL 1

This module overrides ymo_assert_test_fail to return YMO_TAP_STATUS_FAIL.

The assertion conditional will be reported as test output, e.g.:

int x = 1;
int y = 2;
ymo_assert(x == y);

Will result in:

not ok 1 - assertion failed!
   assertion: x == y
   location:  my_source.c:test_my_test:3

The override (included in ymo_tap.h!) looks like this:

YMO_TAP_PASS

Pass a unit test with the given message.

Definition
#define YMO_TAP_PASS(msg) \
        fprintf(YMO_TAP_STREAM_OUT, "ok %zu - %s\n", \
        tap_test_num, msg); \
        return YMO_TAP_STATUS_PASS
YMO_TAP_FAIL

Pass a unit test with the given message.

Definition
#define YMO_TAP_FAIL(msg) \
        fprintf(YMO_TAP_STREAM_OUT, "not ok %zu - %s\n", \
        tap_test_num, msg); \
        return YMO_TAP_STATUS_FAIL
type ymo_tap_test_fn_t

Individual unit test signature.

Definition
typedef int (*ymo_tap_test_fn_t)(void);
type ymo_tap_test_t

Struct used to represent individual unit tests.

Definition
typedef struct ymo_tap_test ymo_tap_test_t;
type ymo_tap_setup_fn_t

Test setup/teardown callback signature.

Definition
typedef int (*ymo_tap_setup_fn_t)(void);
YMO_TAP_NO_INIT

Pass as the first argument to YMO_TAP_TEST if no setup/teardown callbacks are required.

Definition
#define YMO_TAP_NO_INIT() NULL, NULL, NULL
YMO_TAP_TEST_FN

Macro used to pass a ymo_test_fn_t as an argument to ymo_tap_run() or YMO_TAP_RUN.

Definition
#define YMO_TAP_TEST_FN(fn) \
        ((ymo_tap_test_t) { .name = #fn, .test_fn = fn })
YMO_TAP_TEST_END

Macro used to terminate the list of arguments to ymo_tap_run() or YMO_TAP_RUN.

Definition
#define YMO_TAP_TEST_END() \
        ((ymo_tap_test_t) { .name = NULL, .test_fn = NULL })
int ymo_tap_run(ymo_tap_setup_fn_t setup_suite, ymo_tap_setup_fn_t setup_test, ymo_tap_setup_fn_t cleanup, ...);
Parameters
  • ymo_tap_test_fn_t – an initialization function to run before each test (may be NULL)

  • ... – a NULL terminated list of ymo_tap_test_t.

Returns

zero on success; non-zero on failure

YMO_TAP_RUN

Define a main function which invokes :ymo_tap_run() with the input arguments.

Definition
#define YMO_TAP_RUN(...) \
        int main(int argc, char** argv) { \
            ymo_tap_exec = argv[0]; \
            ymo_log_init(); \
            return ymo_tap_run(__VA_ARGS__); \
        }