htils 1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
test.h File Reference
#include <stdlib.h>
#include <h2o/memory.h>
#include <htils/basictypes.h>

Go to the source code of this file.

Macros

#define COLOR_GREEN   "\x1b[32m"
 
#define COLOR_CYAN   "\x1b[36m"
 
#define COLOR_RED   "\x1b[31m"
 
#define COLOR_RESET   "\x1b[0m"
 
#define H2OTILS_TEST_ASSERT(cond, msg)
 
#define H2OTILS_TEST(name)    static const cstr *h2otils_test_##name(h2o_mem_pool_t *pool)
 
#define H2OTILS_TEST_RUN(name)
 
#define H2OTILS_TEST_RESULT()
 
#define H2OTILS_TEST_PASS   null
 
#define H2OTILS_TEST_SKIP   "@"
 

Macro Definition Documentation

◆ COLOR_CYAN

#define COLOR_CYAN   "\x1b[36m"

◆ COLOR_GREEN

#define COLOR_GREEN   "\x1b[32m"

◆ COLOR_RED

#define COLOR_RED   "\x1b[31m"

◆ COLOR_RESET

#define COLOR_RESET   "\x1b[0m"

◆ H2OTILS_TEST

#define H2OTILS_TEST (   name)     static const cstr *h2otils_test_##name(h2o_mem_pool_t *pool)

The test macro for test declarations.

◆ H2OTILS_TEST_ASSERT

#define H2OTILS_TEST_ASSERT (   cond,
  msg 
)
Value:
do { \
if (!(cond)) { \
fprintf(stderr, " %sFAIL%s: %s:%d: %s\n", COLOR_RED, COLOR_RESET, \
__FILE__, __LINE__, msg); \
return (msg); \
} \
} while (0)
#define COLOR_RESET
Definition test.h:21
#define COLOR_RED
Definition test.h:20

The test assertion, basically signals if condition is false, the test fails.

◆ H2OTILS_TEST_PASS

#define H2OTILS_TEST_PASS   null

Lil macro that makes test passes more opaque

◆ H2OTILS_TEST_RESULT

#define H2OTILS_TEST_RESULT ( )
Value:
do { \
if (failures > 0) { \
fprintf(stderr, "\n%u Tests %sFAILED%s.\n", failures, COLOR_RED, \
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
skips); \
return 1; \
} \
\
fprintf(stderr, "\nAll %u tests %sPASSED%s.\n", test_count, COLOR_GREEN, \
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
skips); \
return 0; \
} while (0)
#define COLOR_CYAN
Definition test.h:19
#define COLOR_GREEN
Definition test.h:18

Handle the test results, prints the results and returns 0 if all tests pass, returns 1 if any test fails.

◆ H2OTILS_TEST_RUN

#define H2OTILS_TEST_RUN (   name)
Value:
do { \
test_count++; \
\
h2o_mem_pool_t pool; \
h2o_mem_init_pool(&pool); \
fprintf(stderr, "Running test: %s...\n", #name); \
const cstr *result = h2otils_test_##name(&pool); \
\
if (!result) \
fprintf(stderr, " %sPASS%s: %s\n", COLOR_GREEN, COLOR_RESET, #name); \
else if (result[0] == '@') { \
fprintf(stderr, " %sSKIPPED%s: %s\n", COLOR_CYAN, COLOR_RESET, #name); \
skips++; \
} else \
(failures)++; \
} while (0)
char cstr
Definition basictypes.h:50

The runtime for the tests, uses temporary arenas.

◆ H2OTILS_TEST_SKIP

#define H2OTILS_TEST_SKIP   "@"

Lil macro to tell the test suite to skip a test