Libecoli 0.5.0
Extensible COmmand LIne library
Loading...
Searching...
No Matches
Test

Helpers for unit tests. More...

Data Structures

struct  ec_test

Macros

#define EC_TEST_REGISTER(t)
#define EC_TEST_ERR(fmt, ...)
#define EC_TEST_CHECK(cond, fmt, ...)
#define EC_TEST_CHECK_PARSE(node, args...)
#define EC_TEST_CHECK_COMPLETE(node, args...)
#define EC_TEST_CHECK_COMPLETE_PARTIAL(node, args...)

Typedefs

typedef int ec_test_t(void)

Functions

int ec_test_register (struct ec_test *test)
int ec_test_all (void)
int ec_test_one (const char *name)
int ec_test_check_parse (struct ec_node *node, int expected,...)
int ec_test_check_complete (struct ec_node *node, enum ec_comp_type type,...)

Detailed Description

Helpers for unit tests.

Macro Definition Documentation

◆ EC_TEST_REGISTER

#define EC_TEST_REGISTER ( t)
Value:
static void ec_test_init_##t(void); \
static void __attribute__((constructor, used)) \
ec_test_init_##t(void) \
{ \
if (ec_test_register(&t) < 0) \
fprintf(stderr, "cannot register test %s\n", \
t.name); \
}
int ec_test_register(struct ec_test *test)

Register a test case.

Parameters
tA pointer to a ec_test structure describing the test to be registered.

Definition at line 32 of file ecoli_test.h.

◆ EC_TEST_ERR

#define EC_TEST_ERR ( fmt,
... )
Value:
EC_LOG(EC_LOG_ERR, "%s:%d: error: " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); \
#define EC_LOG(level, args...)
Definition ecoli_log.h:171

Fail a test with a message.

Definition at line 105 of file ecoli_test.h.

◆ EC_TEST_CHECK

#define EC_TEST_CHECK ( cond,
fmt,
... )
Value:
({ \
int ret_ = 0; \
if (!(cond)) { \
EC_TEST_ERR("(" #cond ") is wrong. " fmt \
##__VA_ARGS__); \
ret_ = -1; \
} \
ret_; \
})

Verify a condition or fail a test with a message.

Definition at line 114 of file ecoli_test.h.

◆ EC_TEST_CHECK_PARSE

#define EC_TEST_CHECK_PARSE ( node,
args... )
Value:
({ \
int ret_ = ec_test_check_parse(node, args, EC_VA_END); \
if (ret_) \
EC_TEST_ERR("parse test failed"); \
ret_; \
})
int ec_test_check_parse(struct ec_node *node, int expected,...)
#define EC_VA_END
Definition ecoli_utils.h:27

node, input, [expected1, expected2, ...]

Definition at line 129 of file ecoli_test.h.

◆ EC_TEST_CHECK_COMPLETE

#define EC_TEST_CHECK_COMPLETE ( node,
args... )
Value:
({ \
int ret_ = ec_test_check_complete(node, EC_COMP_FULL, args); \
if (ret_) \
EC_TEST_ERR("complete test failed"); \
ret_; \
})

Definition at line 141 of file ecoli_test.h.

◆ EC_TEST_CHECK_COMPLETE_PARTIAL

#define EC_TEST_CHECK_COMPLETE_PARTIAL ( node,
args... )
Value:
({ \
int ret_ = ec_test_check_complete(node, EC_COMP_PARTIAL, args); \
if (ret_) \
EC_TEST_ERR("complete test failed"); \
ret_; \
})

Definition at line 149 of file ecoli_test.h.

Typedef Documentation

◆ ec_test_t

typedef int ec_test_t(void)

Type of test function. Return 0 on success, -1 on error.

Definition at line 47 of file ecoli_test.h.

Function Documentation

◆ ec_test_register()

int ec_test_register ( struct ec_test * test)

Register a test case.

◆ ec_test_all()

int ec_test_all ( void )

Run all tests.

◆ ec_test_one()

int ec_test_one ( const char * name)

Run one test.

◆ ec_test_check_parse()

int ec_test_check_parse ( struct ec_node * node,
int expected,
... )

expected == -1 means no match