From: Timo Sirainen Date: Sat, 9 May 2009 20:20:41 +0000 (-0400) Subject: Tests are now run on "make check". Added initial tests for lib-index. X-Git-Tag: 2.0.alpha1~794 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=40a5aeebf6b4858b93f0ddff0bf12fba769cf903;p=thirdparty%2Fdovecot%2Fcore.git Tests are now run on "make check". Added initial tests for lib-index. Moved old tests away from tests/ to libraries' individual directories. --HG-- branch : HEAD --- diff --git a/.hgignore b/.hgignore index 8c5340ced1..7dbfc7d086 100644 --- a/.hgignore +++ b/.hgignore @@ -61,9 +61,13 @@ src/lda/dovecot-lda src/dict/dict src/imap-login/imap-login src/imap/imap +src/lib/test-lib src/lib/unicodemap.c src/lib/UnicodeData.txt src/lib-dict/dict-drivers-register.c +src/lib-index/test-index +src/lib-imap/test-imap +src/lib-mail/test-mail src/lib-sql/sql-drivers-register.c src/lib-storage/register/mail-storage-register.c src/lib-storage/register/mailbox-list-register.c @@ -76,9 +80,6 @@ src/plugins/expire/expire-tool src/plugins/fts-squat/squat-test src/pop3-login/pop3-login src/pop3/pop3 -src/tests/test-lib -src/tests/test-mail -src/tests/test-imap src/util/doveadm src/util/dovecotpw src/util/gdbhelper diff --git a/configure.in b/configure.in index 02c4c11e2a..11d46bc271 100644 --- a/configure.in +++ b/configure.in @@ -2442,6 +2442,7 @@ src/lib-ntlm/Makefile src/lib-otp/Makefile src/lib-dovecot/Makefile src/lib-settings/Makefile +src/lib-test/Makefile src/lib-storage/Makefile src/lib-storage/list/Makefile src/lib-storage/index/Makefile @@ -2465,7 +2466,6 @@ src/login-common/Makefile src/master/Makefile src/pop3/Makefile src/pop3-login/Makefile -src/tests/Makefile src/util/Makefile src/plugins/Makefile src/plugins/acl/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 950496cf7f..b5627da4e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ LIBDOVECOT_SUBDIRS = \ lib-settings SUBDIRS = \ + lib-test \ $(LIBDOVECOT_SUBDIRS) \ lib-dovecot \ lib-index \ @@ -30,6 +31,10 @@ SUBDIRS = \ lmtp \ log \ config \ - tests \ util \ plugins + +test: + for dir in $(SUBDIRS); do \ + cd $$dir && if ! $(MAKE) test; then exit 1; fi; cd ..; \ + done diff --git a/src/lib-imap/Makefile.am b/src/lib-imap/Makefile.am index 4920bc9625..61e1eb8dfc 100644 --- a/src/lib-imap/Makefile.am +++ b/src/lib-imap/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libimap.la AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-charset \ -I$(top_srcdir)/src/lib-mail @@ -38,3 +39,23 @@ if INSTALL_HEADERS else noinst_HEADERS = $(headers) endif + +test_programs = test-imap +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + libimap.la \ + ../lib-test/libtest.la \ + ../lib/liblib.la + +test_imap_SOURCES = \ + test-imap.c + +test_imap_LDADD = $(test_libs) +test_imap_DEPENDENCIES = $(test_libs) + +check: check-am check-test +check-test: $(test_programs) + for bin in $(test_programs); do \ + if ! ./$$bin; then exit 1; fi \ + done diff --git a/src/tests/test-imap.c b/src/lib-imap/test-imap.c similarity index 97% rename from src/tests/test-imap.c rename to src/lib-imap/test-imap.c index 7605f100e1..195d27ab77 100644 --- a/src/tests/test-imap.c +++ b/src/lib-imap/test-imap.c @@ -168,9 +168,11 @@ end: int main(void) { - test_init(); + static void (*test_functions[])(void) = { + test_imap_match, + test_imap_utf7, - test_imap_match(); - test_imap_utf7(); - return test_deinit(); + NULL + }; + return test_run(test_functions); } diff --git a/src/lib-index/Makefile.am b/src/lib-index/Makefile.am index 92b4ae8703..e453001e76 100644 --- a/src/lib-index/Makefile.am +++ b/src/lib-index/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libindex.la AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-mail libindex_la_SOURCES = \ @@ -54,9 +55,34 @@ headers = \ mailbox-list-index.h \ mailbox-list-index-private.h +test_programs = test-index +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + libindex.la \ + ../lib-test/libtest.la \ + ../lib-mail/libmail.la \ + ../lib/liblib.la + +test_index_SOURCES = \ + test-index.c \ + test-transaction-log-view.c + +test_headers = \ + test-index.h + +test_index_LDADD = $(test_libs) +test_index_DEPENDENCIES = $(test_libs) + +check: check-am check-test +check-test: $(test_programs) + for bin in $(test_programs); do \ + if ! ./$$bin; then exit 1; fi \ + done + if INSTALL_HEADERS pkginc_libdir=$(pkgincludedir) - pkginc_lib_HEADERS = $(headers) + pkginc_lib_HEADERS = $(headers) $(test_headers) else - noinst_HEADERS = $(headers) + noinst_HEADERS = $(headers) $(test_headers) endif diff --git a/src/lib-index/mail-index-transaction-export.c b/src/lib-index/mail-index-transaction-export.c index 9fb2a1ffde..d1df5fcfb6 100644 --- a/src/lib-index/mail-index-transaction-export.c +++ b/src/lib-index/mail-index-transaction-export.c @@ -16,7 +16,8 @@ static void log_append_buffer(struct mail_index_export_context *ctx, const buffer_t *buf, enum mail_transaction_type type) { - mail_transaction_log_append_add(ctx->append_ctx, type, buf); + mail_transaction_log_append_add(ctx->append_ctx, type, + buf->data, buf->used); } static const buffer_t * diff --git a/src/lib-index/mail-index-transaction.c b/src/lib-index/mail-index-transaction.c index c082910339..eafc3093cc 100644 --- a/src/lib-index/mail-index-transaction.c +++ b/src/lib-index/mail-index-transaction.c @@ -267,12 +267,13 @@ mail_transaction_log_file_refresh(struct mail_index_transaction *t, static int mail_index_transaction_commit_real(struct mail_index_transaction *t) { struct mail_transaction_log *log = t->view->index->log; + bool external = (t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0; struct mail_transaction_log_append_ctx *ctx; uint32_t log_seq1, log_seq2; uoff_t log_offset1, log_offset2; int ret; - if (mail_transaction_log_append_begin(t, &ctx) < 0) + if (mail_transaction_log_append_begin(log->index, external, &ctx) < 0) return -1; ret = mail_transaction_log_file_refresh(t, ctx); if (ret > 0) { diff --git a/src/lib-index/mail-transaction-log-append.c b/src/lib-index/mail-transaction-log-append.c index 013c9f80e3..c844997ece 100644 --- a/src/lib-index/mail-transaction-log-append.c +++ b/src/lib-index/mail-transaction-log-append.c @@ -8,14 +8,14 @@ void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx, enum mail_transaction_type type, - const buffer_t *buf) + const void *data, size_t size) { struct mail_transaction_header hdr; i_assert((type & MAIL_TRANSACTION_TYPE_MASK) != 0); - i_assert((buf->used % 4) == 0); + i_assert((size % 4) == 0); - if (buf->used == 0) + if (size == 0) return; memset(&hdr, 0, sizeof(hdr)); @@ -24,15 +24,15 @@ void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT; if (ctx->external) hdr.type |= MAIL_TRANSACTION_EXTERNAL; - hdr.size = sizeof(hdr) + buf->used; + hdr.size = sizeof(hdr) + size; hdr.size = mail_index_uint32_to_offset(hdr.size); buffer_append(ctx->output, &hdr, sizeof(hdr)); - buffer_append(ctx->output, buf->data, buf->used); + buffer_append(ctx->output, data, size); - if (mail_transaction_header_has_modseq(buf->data, - CONST_PTR_OFFSET(buf->data, sizeof(hdr)), - ctx->new_highest_modseq)) + if (mail_transaction_header_has_modseq(data, + CONST_PTR_OFFSET(data, sizeof(hdr)), + ctx->new_highest_modseq)) ctx->new_highest_modseq++; } @@ -158,7 +158,7 @@ log_append_sync_offset_if_needed(struct mail_transaction_log_append_ctx *ctx) buffer_append(buf, &offset, sizeof(offset)); mail_transaction_log_append_add(ctx, MAIL_TRANSACTION_HEADER_UPDATE, - buf); + buf->data, buf->used); } static int @@ -189,13 +189,11 @@ mail_transaction_log_append_locked(struct mail_transaction_log_append_ctx *ctx) return 0; } -int mail_transaction_log_append_begin(struct mail_index_transaction *t, +int mail_transaction_log_append_begin(struct mail_index *index, bool external, struct mail_transaction_log_append_ctx **ctx_r) { struct mail_transaction_log_append_ctx *ctx; - struct mail_index *index; - index = mail_index_view_get_index(t->view); if (!index->log_locked) { if (mail_transaction_log_lock_head(index->log) < 0) return -1; @@ -203,7 +201,7 @@ int mail_transaction_log_append_begin(struct mail_index_transaction *t, ctx = i_new(struct mail_transaction_log_append_ctx, 1); ctx->log = index->log; ctx->output = buffer_create_dynamic(default_pool, 1024); - ctx->external = (t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0; + ctx->external = external; *ctx_r = ctx; return 0; diff --git a/src/lib-index/mail-transaction-log.h b/src/lib-index/mail-transaction-log.h index 3aaa0380ee..2a44cd43c4 100644 --- a/src/lib-index/mail-transaction-log.h +++ b/src/lib-index/mail-transaction-log.h @@ -224,11 +224,11 @@ mail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view); void mail_transaction_log_views_close(struct mail_transaction_log *log); -int mail_transaction_log_append_begin(struct mail_index_transaction *t, +int mail_transaction_log_append_begin(struct mail_index *index, bool external, struct mail_transaction_log_append_ctx **ctx_r); void mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx, enum mail_transaction_type type, - const buffer_t *buf); + const void *data, size_t size); int mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx); /* Lock transaction log for index synchronization. Log cannot be read or diff --git a/src/lib-index/test-index.c b/src/lib-index/test-index.c new file mode 100644 index 0000000000..b55a8a1176 --- /dev/null +++ b/src/lib-index/test-index.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */ + +#include "test-index.h" + +int main(void) +{ + static void (*test_functions[])(void) = { + test_transaction_log_view, + NULL + }; + return test_run(test_functions); +} diff --git a/src/lib-index/test-index.h b/src/lib-index/test-index.h new file mode 100644 index 0000000000..b6d1ac0d55 --- /dev/null +++ b/src/lib-index/test-index.h @@ -0,0 +1,9 @@ +#ifndef TEST_INDEX_H +#define TEST_INDEX_H + +#include "lib.h" +#include "test-common.h" + +void test_transaction_log_view(void); + +#endif diff --git a/src/lib-index/test-transaction-log-view.c b/src/lib-index/test-transaction-log-view.c new file mode 100644 index 0000000000..ab76866080 --- /dev/null +++ b/src/lib-index/test-transaction-log-view.c @@ -0,0 +1,148 @@ +/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */ + +#include "test-index.h" +#include "array.h" +#include "mail-index-private.h" +#include "mail-transaction-log-view-private.h" + +static struct mail_transaction_log *log; +static struct mail_transaction_log_view *view; + +static void +test_transaction_log_file_add(uint32_t file_seq) +{ + struct mail_transaction_log_file **p, *file; + + file = i_new(struct mail_transaction_log_file, 1); + file->hdr.file_seq = file_seq; + file->hdr.hdr_size = file->sync_offset = sizeof(file->hdr); + file->hdr.prev_file_seq = file_seq - 1; + file->hdr.indexid = 1; + file->log = log; + file->fd = -1; + + /* files must be sorted by file_seq */ + for (p = &log->files; *p != NULL; p = &(*p)->next) { + if ((*p)->hdr.file_seq > file->hdr.file_seq) + break; + i_assert((*p)->hdr.file_seq < file->hdr.file_seq); + } + *p = file; + log->head = file; +} + +static bool view_is_file_refed(uint32_t file_seq) +{ + struct mail_transaction_log_file *const *files; + unsigned int i, count; + bool ret = FALSE; + + files = array_get(&view->file_refs, &count); + for (i = 0; i < count; i++) { + if (files[i]->hdr.file_seq == file_seq) { + i_assert(!ret); /* could be a test too.. */ + ret = TRUE; + } + } + return ret; +} + +void test_transaction_log_view(void) +{ + const struct mail_transaction_header *hdr; + struct mail_transaction_log_append_ctx *append_ctx; + struct mail_index_record append_rec; + const struct mail_index_record *rec; + const void *data; + uint32_t seq; + uoff_t offset, last_log_size; + bool reset; + + test_begin("init"); + log = i_new(struct mail_transaction_log, 1); + log->index = i_new(struct mail_index, 1); + log->index->log = log; + log->index->log_locked = TRUE; + test_transaction_log_file_add(1); + test_transaction_log_file_add(2); + test_transaction_log_file_add(3); + + /* add an append record to the 3rd log file */ + memset(&append_rec, 0, sizeof(append_rec)); + append_rec.uid = 1; + test_assert(mail_transaction_log_append_begin(log->index, TRUE, &append_ctx) == 0); + mail_transaction_log_append_add(append_ctx, MAIL_TRANSACTION_APPEND, + &append_rec, sizeof(append_rec)); + test_assert(mail_transaction_log_append_commit(&append_ctx) == 0); + last_log_size = sizeof(struct mail_transaction_log_header) + + sizeof(struct mail_transaction_header) + sizeof(append_rec); + + view = mail_transaction_log_view_open(log); + test_assert(view != NULL && log->views == view && + !view_is_file_refed(1) && !view_is_file_refed(2) && + view_is_file_refed(3)); + test_end(); + + /* we have files 1-3 opened */ + test_begin("set all"); + test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 1 && + reset && view_is_file_refed(1) && view_is_file_refed(2) && + view_is_file_refed(3) && + !mail_transaction_log_view_is_corrupted(view)); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header)); + test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 1); + test_assert(hdr->type == (MAIL_TRANSACTION_APPEND | MAIL_TRANSACTION_EXTERNAL)); + rec = data; + test_assert(memcmp(rec, &append_rec, sizeof(*rec)) == 0); + test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0); + test_assert(mail_transaction_log_view_is_last(view)); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 3 && offset == last_log_size); + test_end(); + + test_begin("set first"); + test_assert(mail_transaction_log_view_set(view, 0, 0, 0, 0, &reset) == 1); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header)); + test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 1 && offset == sizeof(struct mail_transaction_log_header)); + test_end(); + + test_begin("set end"); + test_assert(mail_transaction_log_view_set(view, 3, last_log_size, (uint32_t)-1, (uoff_t)-1, &reset) == 1); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 3 && offset == last_log_size); + test_assert(mail_transaction_log_view_next(view, &hdr, &data) == 0); + mail_transaction_log_view_get_prev_pos(view, &seq, &offset); + test_assert(seq == 3 && offset == last_log_size); + test_end(); + + test_begin("log clear"); + mail_transaction_log_view_clear(view, 2); + test_assert(!view_is_file_refed(1) && view_is_file_refed(2) && + view_is_file_refed(3)); + test_end(); + + /* --- first file has been removed --- */ + + test_begin("removed first"); + mail_transaction_logs_clean(log); + test_assert(log->files->hdr.file_seq == 2); + test_end(); + + test_begin("set 2-3"); + test_assert(mail_transaction_log_view_set(view, 2, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 1); + test_end(); + + test_begin("missing log handing"); + test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == 0); + test_end(); + + test_begin("closed log handling"); + view->log = NULL; + test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, (uoff_t)-1, &reset) == -1); + view->log = log; + test_end(); +} diff --git a/src/lib-mail/Makefile.am b/src/lib-mail/Makefile.am index 96558dfad0..3bf92bcc43 100644 --- a/src/lib-mail/Makefile.am +++ b/src/lib-mail/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libmail.la AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-charset libmail_la_SOURCES = \ @@ -47,3 +48,23 @@ if INSTALL_HEADERS else noinst_HEADERS = $(headers) endif + +test_programs = test-mail +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + libmail.la \ + ../lib-test/libtest.la \ + ../lib/liblib.la + +test_mail_SOURCES = \ + test-mail.c + +test_mail_LDADD = $(test_libs) +test_mail_DEPENDENCIES = $(test_libs) + +check: check-am check-test +check-test: $(test_programs) + for bin in $(test_programs); do \ + if ! ./$$bin; then exit 1; fi \ + done diff --git a/src/tests/test-mail.c b/src/lib-mail/test-mail.c similarity index 97% rename from src/tests/test-mail.c rename to src/lib-mail/test-mail.c index ab2b135c6b..339052a739 100644 --- a/src/tests/test-mail.c +++ b/src/lib-mail/test-mail.c @@ -356,12 +356,14 @@ static void test_istream_filter(void) int main(void) { - test_init(); - - test_message_address(); - test_message_date_parse(); - test_message_parser(); - test_rfc2231_parser(); - test_istream_filter(); - return test_deinit(); + static void (*test_functions[])(void) = { + test_message_address, + test_message_date_parse, + test_message_parser, + test_rfc2231_parser, + test_istream_filter, + + NULL + }; + return test_run(test_functions); } diff --git a/src/lib-test/Makefile.am b/src/lib-test/Makefile.am new file mode 100644 index 0000000000..0be31e3201 --- /dev/null +++ b/src/lib-test/Makefile.am @@ -0,0 +1,18 @@ +noinst_LTLIBRARIES = libtest.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-charset + +libtest_la_SOURCES = \ + test-common.c + +headers = \ + test-common.h + +if INSTALL_HEADERS + pkginc_libdir=$(pkgincludedir) + pkginc_lib_HEADERS = $(headers) +else + noinst_HEADERS = $(headers) +endif diff --git a/src/tests/test-common.c b/src/lib-test/test-common.c similarity index 58% rename from src/tests/test-common.c rename to src/lib-test/test-common.c index 630cc7124f..641c4b167f 100644 --- a/src/tests/test-common.c +++ b/src/lib-test/test-common.c @@ -6,8 +6,10 @@ #include -#define OUT_NAME_ALIGN 30 +#define OUT_NAME_ALIGN 70 +static char *test_prefix; +static bool test_success; static unsigned int failure_count; static unsigned int total_count; @@ -47,6 +49,28 @@ void test_istream_set_allow_eof(struct istream *input, bool allow) input->real_stream->read = allow ? test_read : test_noread; } +void test_begin(const char *name) +{ + i_assert(test_prefix == NULL); + test_prefix = i_strdup(name); + test_success = TRUE; +} + +void test_assert_failed(const char *code, const char *file, unsigned int line) +{ + printf("%s:%u: Assert failed: %s\n", file, line, code); + test_success = FALSE; +} + +void test_end(void) +{ + i_assert(test_prefix != NULL); + + test_out("", test_success); + i_free_and_null(test_prefix); + test_success = FALSE; +} + void test_out(const char *name, bool success) { test_out_reason(name, success, NULL); @@ -54,17 +78,31 @@ void test_out(const char *name, bool success) void test_out_reason(const char *name, bool success, const char *reason) { - int i; - - fputs(name, stdout); - putchar(' '); - for (i = strlen(name) + 1; i < OUT_NAME_ALIGN; i++) + int i = 0; + + if (test_prefix != NULL) { + fputs(test_prefix, stdout); + i += strlen(test_prefix); + if (*name != '\0') { + putchar(':'); + i++; + } + putchar(' '); + i++; + } + if (*name != '\0') { + fputs(name, stdout); + putchar(' '); + i += strlen(name) + 1; + } + for (; i < OUT_NAME_ALIGN; i++) putchar('.'); fputs(" : ", stdout); if (success) fputs("ok", stdout); else { fputs("FAILED", stdout); + test_success = FALSE; failure_count++; } if (reason != NULL && *reason != '\0') @@ -73,16 +111,31 @@ void test_out_reason(const char *name, bool success, const char *reason) total_count++; } -void test_init(void) +static void test_init(void) { + test_prefix = NULL; failure_count = 0; total_count = 0; lib_init(); } -int test_deinit(void) +static int test_deinit(void) { + i_assert(test_prefix == NULL); printf("%u / %u tests failed\n", failure_count, total_count); return failure_count == 0 ? 0 : 1; } + +int test_run(void (*test_functions[])(void)) +{ + unsigned int i; + + test_init(); + for (i = 0; test_functions[i] != NULL; i++) { + T_BEGIN { + test_functions[i](); + } T_END; + } + return test_deinit(); +} diff --git a/src/tests/test-common.h b/src/lib-test/test-common.h similarity index 54% rename from src/tests/test-common.h rename to src/lib-test/test-common.h index a97b8d466b..4978ee2a4e 100644 --- a/src/tests/test-common.h +++ b/src/lib-test/test-common.h @@ -5,10 +5,16 @@ struct istream *test_istream_create(const char *data); void test_istream_set_size(struct istream *input, uoff_t size); void test_istream_set_allow_eof(struct istream *input, bool allow); +void test_begin(const char *name); +#define test_assert(code) STMT_START { \ + if (!(code)) test_assert_failed(#code, __FILE__, __LINE__); \ + } STMT_END +void test_assert_failed(const char *code, const char *file, unsigned int line); +void test_end(void); + void test_out(const char *name, bool success); void test_out_reason(const char *name, bool success, const char *reason); -void test_init(void); -int test_deinit(void); +int test_run(void (*test_functions[])(void)); #endif diff --git a/src/lib-test/test-common.lo b/src/lib-test/test-common.lo new file mode 100644 index 0000000000..da3d93e960 --- /dev/null +++ b/src/lib-test/test-common.lo @@ -0,0 +1,12 @@ +# test-common.lo - a libtool object file +# Generated by ltmain.sh (GNU libtool) 2.2.6 Debian-2.2.6a-1ubuntu1 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/test-common.o' + +# Name of the non-PIC object +non_pic_object='test-common.o' + diff --git a/src/lib-test/test-common.o b/src/lib-test/test-common.o new file mode 100644 index 0000000000..8faad3ed62 Binary files /dev/null and b/src/lib-test/test-common.o differ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index f8cf132ca5..0453b9a71e 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -198,9 +198,36 @@ headers = \ var-expand.h \ write-full.h +test_programs = test-lib +noinst_PROGRAMS = $(test_programs) + +test_lib_CPPFLAGS = \ + -I$(top_srcdir)/src/lib-test + +test_libs = \ + ../lib-test/libtest.la \ + liblib.la + +test_lib_SOURCES = \ + test-lib.c \ + test-istream.c + +test_headers = \ + test-lib.h + +test_lib_LDADD = $(test_libs) +test_lib_DEPENDENCIES = $(test_libs) + +check: check-am check-test +check-test: $(test_programs) + for bin in $(test_programs); do \ + if ! ./$$bin; then exit 1; fi \ + done + if INSTALL_HEADERS pkginc_libdir=$(pkgincludedir) pkginc_lib_HEADERS = $(headers) + noinst_HEADERS = $(test_headers) else - noinst_HEADERS = $(headers) + noinst_HEADERS = $(headers) $(test_headers) endif diff --git a/src/tests/test-istream.c b/src/lib/test-istream.c similarity index 100% rename from src/tests/test-istream.c rename to src/lib/test-istream.c diff --git a/src/tests/test-lib.c b/src/lib/test-lib.c similarity index 99% rename from src/tests/test-lib.c rename to src/lib/test-lib.c index f937fc7623..ea19d241ee 100644 --- a/src/tests/test-lib.c +++ b/src/lib/test-lib.c @@ -919,13 +919,5 @@ int main(void) test_istreams }; - unsigned int i; - - test_init(); - for (i = 0; i < N_ELEMENTS(test_functions); i++) { - T_BEGIN { - test_functions[i](); - } T_END; - } - return test_deinit(); + return test_run(test_functions); } diff --git a/src/tests/test-lib.h b/src/lib/test-lib.h similarity index 100% rename from src/tests/test-lib.h rename to src/lib/test-lib.h diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am deleted file mode 100644 index f57a4b9411..0000000000 --- a/src/tests/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -noinst_PROGRAMS = test-lib test-mail test-imap - -noinst_LIBRARIES = libtest.a - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/lib \ - -I$(top_srcdir)/src/lib-mail \ - -I$(top_srcdir)/src/lib-imap \ - -I$(top_srcdir)/src/lib-index \ - -I$(top_srcdir)/src/lib-storage - -libtest_a_SOURCES = \ - test-common.c - -libs = \ - libtest.a \ - $(LIBDOVECOT) - -test_lib_SOURCES = \ - test-istream.c \ - test-lib.c - -test_lib_LDADD = $(libs) -test_lib_DEPENDENCIES = $(libs) - -test_mail_SOURCES = \ - test-mail.c - -test_mail_LDADD = $(libs) -test_mail_DEPENDENCIES = $(libs) - -test_imap_SOURCES = \ - test-imap.c - -noinst_HEADERS = \ - test-common.h \ - test-lib.h - -test_imap_LDADD = $(libs) -test_imap_DEPENDENCIES = $(libs)