]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
testsuite: add missing components for the suite to be able to run
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 3 Nov 2021 09:14:25 +0000 (10:14 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 3 Nov 2021 13:10:28 +0000 (14:10 +0100)
Makefile.am
configure.ac
src/random-int.c
tests/Kyuafile.in [new file with mode: 0644]
tests/Makefile.am [new file with mode: 0644]
tests/mlmmj-list.sh [new file with mode: 0644]
tests/mlmmj-process.sh [new file with mode: 0644]
tests/mlmmj.c [new file with mode: 0644]
tests/test_env.sh [new file with mode: 0644]
tests/test_env.sh.in [new file with mode: 0644]

index 33ff3920f9aa4da12e6b0a90488c686ea167f1d8..2fa7aa43a3c0dc0a25e4d1abe439c3060f420dec 100644 (file)
@@ -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
index 4d633d136d373183f19765c3de73d7cbd5270917..f1f16c45607f2ae026b6576ab018553d01302190 100644 (file)
@@ -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
index 6a91ef82571396f3caf2be0160252911c3ab49e0..a0d0770fba22f9a914aee36fef87e34db49876c9 100644 (file)
@@ -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 (file)
index 0000000..66ee5aa
--- /dev/null
@@ -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 (file)
index 0000000..49bc19b
--- /dev/null
@@ -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 (file)
index 0000000..570600c
--- /dev/null
@@ -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 (file)
index 0000000..8647b83
--- /dev/null
@@ -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 (file)
index 0000000..7eb9bde
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 Baptiste Daroussin <bapt@FreeBSD.org>
+ *
+ * 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 <atf-c.h>
+#include <wrappers.h>
+#include <inttypes.h>
+#include <sys/limits.h>
+
+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 (file)
index 0000000..b80ed59
--- /dev/null
@@ -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 (file)
index 0000000..4681fea
--- /dev/null
@@ -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
+}