From: Baptiste Daroussin Date: Wed, 3 Nov 2021 09:14:25 +0000 (+0100) Subject: testsuite: add missing components for the suite to be able to run X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53b5aefd96d025c40b84c53cb5d02addc5707e98;p=thirdparty%2Fmlmmj.git testsuite: add missing components for the suite to be able to run --- diff --git a/Makefile.am b/Makefile.am index 33ff3920..2fa7aa43 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,19 +11,4 @@ man1_MANS = man/mlmmj-bounce.1 man/mlmmj-make-ml.1 man/mlmmj-receive.1 \ man/mlmmj-sub.1 man/mlmmj-maintd.1 man/mlmmj-process.1 \ man/mlmmj-send.1 man/mlmmj-unsub.1 man/mlmmj-list.1 -SUBDIRS = src listtexts contrib - -test_scripts = tests/mlmmj-list.sh \ - tests/mlmmj-send.sh \ - tests/mlmmj-sub.sh - -check_SCRIPTS=$(test_scripts:.sh=) -SUFFIXES=.sh - -check: $(check_SCRIPTS) - kyua --config=none test --kyuafile='$(top_builddir)/Kyuafile' \ - --build-root='$(top_builddir)' - -.sh: - install -m 755 $< $@ - +SUBDIRS = src listtexts contrib tests diff --git a/configure.ac b/configure.ac index 4d633d13..f1f16c45 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,7 @@ AC_FUNC_MALLOC AC_CHECK_FUNCS([ftruncate memset socket strerror strncasecmp snprintf fcntl]) AC_CHECK_FUNCS([nanosleep time strftime syslog regcomp regexec]) AC_CHECK_FUNCS([arc4random_uniform]) +PKG_CHECK_MODULES([ATF], [atf-c]) AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([src/Makefile]) @@ -53,6 +54,7 @@ AC_CONFIG_FILES([listtexts/Makefile]) AC_CONFIG_FILES([contrib/Makefile]) AC_CONFIG_FILES([contrib/receivestrip/Makefile]) AC_CONFIG_FILES([Kyuafile]) +AC_CONFIG_FILES([tests/Makefile]) AC_CONFIG_FILES([tests/Kyuafile]) AC_CONFIG_FILES([tests/test_env.sh]) AC_OUTPUT diff --git a/src/random-int.c b/src/random-int.c index 6a91ef82..a0d0770f 100644 --- a/src/random-int.c +++ b/src/random-int.c @@ -61,7 +61,7 @@ int random_int() return rand(); #else - return arc4random_uniform(sizeof(int)); + return arc4random_uniform(INT_MAX); #endif } #if 0 diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in new file mode 100644 index 00000000..66ee5aa6 --- /dev/null +++ b/tests/Kyuafile.in @@ -0,0 +1,8 @@ +syntax(2) + +test_suite('mlmmj') + +atf_test_program{name='mlmmj'} +atf_test_program{name='mlmmj-list'} +atf_test_program{name='mlmmj-send'} +atf_test_program{name='mlmmj-sub'} diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 00000000..49bc19b5 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,25 @@ +AUTOMAKE_OPTIONS = foreign + +check_PROGRAMS = mlmmj + +mlmmj_SOURCES = mlmmj.c $(top_srcdir)/src/prepstdreply.c $(top_srcdir)/include/prepstdreply.h \ + $(top_srcdir)/src/memory.c $(top_srcdir)/src/controls.c $(top_srcdir)/src/utils.c \ + $(top_srcdir)/src/strgen.c $(top_srcdir)/src/random-int.c $(top_srcdir)/src/readn.c \ + $(top_srcdir)/src/log_error.c $(top_srcdir)/src/chomp.c $(top_srcdir)/src/mygetline.c $(top_srcdir)/src/unistr.c +mlmmj_CFLAGS = @ATF_CFLAGS@ -g -Wall -pedantic -Wsign-compare -DDEFAULTTEXTDIR='"@textlibdir@"' -I$(top_srcdir)/include +mlmmj_LDADD = @ATF_LIBS@ + +test_scripts = mlmmj-list.sh \ + mlmmj-send.sh \ + mlmmj-sub.sh + +check_SCRIPTS=$(test_scripts:.sh=) +SUFFIXES=.sh + +check: $(check_SCRIPTS) $(check_PROGRAMS) + kyua --config=none test --kyuafile='$(builddir)/Kyuafile' \ + --build-root='$(builddir)' + +.sh: + install -m 755 $< $@ + diff --git a/tests/mlmmj-list.sh b/tests/mlmmj-list.sh new file mode 100644 index 00000000..570600cf --- /dev/null +++ b/tests/mlmmj-list.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh + +tests_init \ + normail \ + nomail \ + digest \ + moderators \ + owner + +normail_body() +{ + init_ml ml + echo "john@doe.org" > ml/subscribers.d/j + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml -s + atf_check -o "inline:1\n" mlmmj-list -L ml -s -c + + # check the default + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml + atf_check -o "inline:1\n" mlmmj-list -L ml -c +} + +nomail_body() +{ + init_ml ml + echo "john@doe.org" > ml/nomailsubs.d/j + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml -n + atf_check -o "inline:1\n" mlmmj-list -L ml -n -c +} + +digest_body() +{ + init_ml ml + echo "john@doe.org"> ml/digesters.d/j + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml -d + atf_check -o "inline:1\n" mlmmj-list -L ml -d -c +} + +moderators_body() +{ + init_ml ml + echo "john@doe.org"> ml/control/moderators + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml -m + atf_check -o "inline:1\n" mlmmj-list -L ml -m -c +} + +owner_body() +{ + init_ml ml + echo "john@doe.org"> ml/control/owner + atf_check -o "inline:john@doe.org\n" mlmmj-list -L ml -o + atf_check -o "inline:1\n" mlmmj-list -L ml -o -c +} diff --git a/tests/mlmmj-process.sh b/tests/mlmmj-process.sh new file mode 100644 index 00000000..8647b83e --- /dev/null +++ b/tests/mlmmj-process.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh + +tests_init \ + mlmmj-makeml + diff --git a/tests/mlmmj.c b/tests/mlmmj.c new file mode 100644 index 00000000..7eb9bde5 --- /dev/null +++ b/tests/mlmmj.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 Baptiste Daroussin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include +#include + +ATF_TC(random_int); + +ATF_TC_HEAD(random_int, tc) { } + +ATF_TC_BODY(random_int, tc) +{ + intmax_t val = random_int(); + + ATF_CHECK_MSG(val < INT_MAX, "Invalid integer"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, random_int); + return (atf_no_error()); +} diff --git a/tests/test_env.sh b/tests/test_env.sh new file mode 100644 index 00000000..b80ed59c --- /dev/null +++ b/tests/test_env.sh @@ -0,0 +1,37 @@ +srcdir="$(atf_get_srcdir)" +export PATH="$srcdir/../src:${PATH}" + +selfdir="/home/bapt/dev/mlmmjng/tests" +LIBRARY_PATH_ENV="LIBRARY_PATH" +SYSROOT_DIR="${selfdir}" + +prefix="/usr/local" +exec_prefix="${prefix}" +datarootdir="${prefix}/share" +pcpath="@PKG_DEFAULT_PATH@" + +tests_init() +{ + TESTS="$@" + export TESTS + for t ; do + atf_test_case $t + done +} + +atf_init_test_cases() { + for t in ${TESTS}; do + atf_add_test_case $t + done +} + +init_ml() +{ + local ml="$1" + mkdir "$ml" + for d in incoming queue queue/discarded archive text subconf unsubconf \ + bounce control moderation subscribers.d digesters.d requeue \ + nomailsubs.d; do + mkdir $ml/$d + done +} diff --git a/tests/test_env.sh.in b/tests/test_env.sh.in new file mode 100644 index 00000000..4681fea3 --- /dev/null +++ b/tests/test_env.sh.in @@ -0,0 +1,37 @@ +srcdir="$(atf_get_srcdir)" +export PATH="$srcdir/../src:${PATH}" + +selfdir="@abs_top_srcdir@/tests" +LIBRARY_PATH_ENV="LIBRARY_PATH" +SYSROOT_DIR="${selfdir}" + +prefix="@prefix@" +exec_prefix="@exec_prefix@" +datarootdir="@datarootdir@" +pcpath="@PKG_DEFAULT_PATH@" + +tests_init() +{ + TESTS="$@" + export TESTS + for t ; do + atf_test_case $t + done +} + +atf_init_test_cases() { + for t in ${TESTS}; do + atf_add_test_case $t + done +} + +init_ml() +{ + local ml="$1" + mkdir "$ml" + for d in incoming queue queue/discarded archive text subconf unsubconf \ + bounce control moderation subscribers.d digesters.d requeue \ + nomailsubs.d; do + mkdir $ml/$d + done +}