Skip to content

Commit

Permalink
lib: tests - give the tests names, using the new macros
Browse files Browse the repository at this point in the history
The lists of test function declarations and of test functions to call was
basically the same list. Use the new test macros to squash them into one
list, and then chose to name all the tests, so that you can select which
ones to run. This can simplify the debug cycle when some of the tests are
lengthy.

e.g.:
  phil@phil:~/repos/dovecot-core$ src/lib/test-lib --match crc
  crc32 ................................................................ : ok
  0 / 1 tests failed

src/lib is clearly the most complicated case, conversions of others where
filtering would be useful should be trivial following this example.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
  • Loading branch information
Phil Carmody authored and GitLab committed Aug 8, 2016
1 parent d48ce43 commit 6335b1b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -49,6 +49,7 @@ Makefile.in
src/**/test-*
!src/**/test-*.c
!src/**/test-*.h
!src/**/test-*.inc

doc/man/doveadm-acl.1
doc/man/doveadm-altmove.1
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Makefile.am
Expand Up @@ -361,7 +361,8 @@ test_lib_SOURCES = \
test-wildcard-match.c

test_headers = \
test-lib.h
test-lib.h \
test-lib.inc

test_lib_LDADD = $(test_libs)
test_lib_DEPENDENCIES = $(test_libs)
Expand Down
86 changes: 20 additions & 66 deletions src/lib/test-lib.c
Expand Up @@ -2,73 +2,27 @@

#include "test-lib.h"

int main(void)
int main(int argc, char **argv)
{
static void (*test_functions[])(void) = {
test_aqueue,
test_array,
test_base32,
test_base64,
test_bits,
test_bsearch_insert_pos,
test_buffer,
test_crc32,
test_data_stack,
test_failures,
test_guid,
test_hash,
test_hash_format,
test_hash_method,
test_hex_binary,
test_ioloop,
test_iso8601_date,
test_iostream_temp,
test_istream,
test_istream_base64_decoder,
test_istream_base64_encoder,
test_istream_chain,
test_istream_concat,
test_istream_crlf,
test_istream_failure_at,
test_istream_seekable,
test_istream_tee,
test_istream_unix,
test_json_parser,
test_json_tree,
test_llist,
test_log_throttle,
test_mempool_alloconly,
test_net,
test_numpack,
test_pkcs5_pbkdf2,
test_ostream_escaped,
test_ostream_failure_at,
test_ostream_file,
test_primes,
test_printf_format_fix,
test_priorityq,
test_seq_range_array,
test_str,
test_strescape,
test_strfuncs,
test_strnum,
test_str_find,
test_str_sanitize,
test_str_table,
test_time_util,
test_timing,
test_unichar,
test_utc_mktime,
test_var_expand,
test_wildcard_match,
NULL
const char *match = "";
if (argc > 2 && strcmp(argv[1], "--match") == 0)
match = argv[2];

static struct named_test test_functions[] = {
#define TEST(x) TEST_NAMED(x)
#define FATAL(x)
#include "test-lib.inc"
#undef TEST
#undef FATAL
{ NULL, NULL }
};
static enum fatal_test_state (*fatal_functions[])(int) = {
fatal_array,
fatal_data_stack,
fatal_mempool,
fatal_printf_format_fix,
NULL
static struct named_fatal fatal_functions[] = {
#define TEST(x)
#define FATAL(x) FATAL_NAMED(x)
#include "test-lib.inc"
#undef TEST
#undef FATAL
{ NULL, NULL }
};
return test_run_with_fatals(test_functions, fatal_functions);
return test_run_named_with_fatals(match, test_functions, fatal_functions);
}
65 changes: 5 additions & 60 deletions src/lib/test-lib.h
Expand Up @@ -4,65 +4,10 @@
#include "lib.h"
#include "test-common.h"

void test_aqueue(void);
void test_array(void);
enum fatal_test_state fatal_array(int);
void test_base32(void);
void test_base64(void);
void test_bits(void);
void test_bsearch_insert_pos(void);
void test_buffer(void);
void test_crc32(void);
void test_data_stack(void);
enum fatal_test_state fatal_data_stack(int);
void test_failures(void);
void test_guid(void);
void test_hash(void);
void test_hash_format(void);
void test_hash_method(void);
void test_hex_binary(void);
void test_ioloop(void);
void test_iso8601_date(void);
void test_iostream_temp(void);
void test_istream(void);
void test_istream_base64_decoder(void);
void test_istream_base64_encoder(void);
void test_istream_chain(void);
void test_istream_concat(void);
void test_istream_crlf(void);
void test_istream_failure_at(void);
void test_istream_seekable(void);
void test_istream_tee(void);
void test_istream_unix(void);
void test_json_parser(void);
void test_json_tree(void);
void test_llist(void);
void test_log_throttle(void);
void test_mempool_alloconly(void);
enum fatal_test_state fatal_mempool(int);
void test_pkcs5_pbkdf2(void);
void test_net(void);
void test_numpack(void);
void test_ostream_escaped(void);
void test_ostream_failure_at(void);
void test_ostream_file(void);
void test_primes(void);
void test_printf_format_fix(void);
enum fatal_test_state fatal_printf_format_fix(int);
void test_priorityq(void);
void test_seq_range_array(void);
void test_str(void);
void test_strescape(void);
void test_strfuncs(void);
void test_strnum(void);
void test_str_find(void);
void test_str_sanitize(void);
void test_str_table(void);
void test_time_util(void);
void test_timing(void);
void test_unichar(void);
void test_utc_mktime(void);
void test_var_expand(void);
void test_wildcard_match(void);
#define TEST(x) TEST_DECL(x)
#define FATAL(x) FATAL_DECL(x)
#include "test-lib.inc"
#undef TEST
#undef FATAL

#endif
64 changes: 64 additions & 0 deletions src/lib/test-lib.inc
@@ -0,0 +1,64 @@
/* This file may be multiply-included, with different definitions of
'TEST()' macro. This is sometimes called "the X trick" (as the
macro is often imaginatively called X(). */

TEST(test_aqueue)
TEST(test_array)
FATAL(fatal_array)
TEST(test_base32)
TEST(test_base64)
TEST(test_bits)
TEST(test_bsearch_insert_pos)
TEST(test_buffer)
TEST(test_crc32)
TEST(test_data_stack)
FATAL(fatal_data_stack)
TEST(test_failures)
TEST(test_guid)
TEST(test_hash)
TEST(test_hash_format)
TEST(test_hash_method)
TEST(test_hex_binary)
TEST(test_ioloop)
TEST(test_iso8601_date)
TEST(test_iostream_temp)
TEST(test_istream)
TEST(test_istream_base64_decoder)
TEST(test_istream_base64_encoder)
TEST(test_istream_chain)
TEST(test_istream_concat)
TEST(test_istream_crlf)
TEST(test_istream_failure_at)
TEST(test_istream_seekable)
TEST(test_istream_tee)
TEST(test_istream_unix)
TEST(test_json_parser)
TEST(test_json_tree)
TEST(test_llist)
TEST(test_log_throttle)
TEST(test_mempool_alloconly)
FATAL(fatal_mempool)
TEST(test_net)
TEST(test_numpack)
TEST(test_ostream_escaped)
TEST(test_ostream_failure_at)
TEST(test_ostream_file)
TEST(test_pkcs5_pbkdf2)
TEST(test_primes)
TEST(test_printf_format_fix)
FATAL(fatal_printf_format_fix)
TEST(test_priorityq)
TEST(test_seq_range_array)
TEST(test_str)
TEST(test_strescape)
TEST(test_strfuncs)
TEST(test_strnum)
TEST(test_str_find)
TEST(test_str_sanitize)
TEST(test_str_table)
TEST(test_time_util)
TEST(test_timing)
TEST(test_unichar)
TEST(test_utc_mktime)
TEST(test_var_expand)
TEST(test_wildcard_match)

0 comments on commit 6335b1b

Please sign in to comment.