commit edb4c964489bdf862bf0db918ebe264bf12bb3e3
parent 2ad04dbba5e70dd1ce9ebef8c492ec846371e42b
Author: Amitai Schleier <schmonz-web-git@schmonz.com>
Date: Tue, 10 Sep 2019 10:35:50 -0400
Add a test target and one unit test, using Check.
Diffstat:
5 files changed, 97 insertions(+), 2 deletions(-)
diff --git a/.cirrus.yml b/.cirrus.yml
@@ -13,11 +13,13 @@ task:
NROFF: true
pkginstall_script:
- - pkg install -y groff
+ - pkg install -y groff pkgconf check
configure_script:
- echo "clang -O2 -Wall" > conf-cc
compile_script:
- make it man
+ test_script:
+ - make test
install_script:
- env DESTDIR=/tmp/qmail make package
- make package
diff --git a/.travis.yml b/.travis.yml
@@ -8,10 +8,16 @@ env:
compiler:
- gcc
- clang
+addons:
+ apt:
+ packages:
+ - pkg-config
+ - check
script:
- echo "${CC} -O2 -Wall" > conf-cc
- if [ -n "${FORCE_UTMP}" ]; then cp qtmp.h1 qtmp.h; fi
- make ${MAKEFLAGS} it man
+ - make test
- env DESTDIR=/tmp/qmail make ${MAKEFLAGS} package
- sudo make ${MAKEFLAGS} package
- sudo groupadd -g 200 nofiles
diff --git a/Makefile b/Makefile
@@ -5,7 +5,7 @@ NROFF=nroff
default: it
-.PHONY: check clean default it man
+.PHONY: check clean default it man test
%.0:
$(NROFF) -man $^ > $@
@@ -352,6 +352,7 @@ exit.h auto_spawn.h
clean: \
TARGETS
rm -f `cat TARGETS`
+ $(MAKE) -C tests clean
coe.o: \
compile coe.c coe.h
@@ -2003,6 +2004,9 @@ tcpto_clean.o: \
compile tcpto_clean.c tcpto.h open.h substdio.h readwrite.h
./compile tcpto_clean.c
+test: it
+ @$(MAKE) -C tests test
+
timeoutconn.o: \
compile timeoutconn.c ndelay.h select.h error.h readwrite.h ip.h \
byte.h timeoutconn.h
diff --git a/tests/Makefile b/tests/Makefile
@@ -0,0 +1,32 @@
+# Tests require
+# 1. <https://pkg-config.freedesktop.org>
+# (or <https://github.com/pkgconf/pkgconf>)
+# 2. <https://libcheck.github.io/check/>
+
+SHELL=/bin/sh
+
+default: it
+
+.PHONY: clean default it test
+
+TESTBINS = unittest_stralloc
+
+clean:
+ rm -f $(TESTBINS) *.o
+
+it: $(TESTBINS)
+
+test: it
+ @for tbin in $(TESTBINS); do \
+ ./$$tbin || exit 1 ; \
+ done
+
+unittest_stralloc: \
+../load unittest_stralloc.o ../stralloc.a ../alloc.a ../str.a ../error.a
+ ../load unittest_stralloc ../stralloc.a ../alloc.a ../str.a ../error.a \
+ `pkg-config --libs check`
+
+unittest_stralloc.o: \
+../compile unittest_stralloc.c ../alloc.h ../stralloc.h
+ ../compile unittest_stralloc.c -I.. \
+ `pkg-config --cflags check`
diff --git a/tests/unittest_stralloc.c b/tests/unittest_stralloc.c
@@ -0,0 +1,51 @@
+#include <check.h>
+
+#include "alloc.h"
+#include "stralloc.h"
+
+START_TEST(test_stralloc_thingy)
+{
+ stralloc thingy = {0};
+ const char *input = "thingy";
+
+ stralloc_copys(&thingy,input);
+ stralloc_0(&thingy);
+
+ ck_assert_str_eq(input, thingy.s);
+
+ alloc_free(thingy.s);
+}
+END_TEST
+
+TCase
+*stralloc_something(void)
+{
+ TCase *tc = tcase_create("basic operations");
+
+ tcase_add_test(tc, test_stralloc_thingy);
+
+ return tc;
+}
+
+Suite
+*stralloc_suite(void)
+{
+ Suite *s = suite_create("notqmail stralloc");
+
+ suite_add_tcase(s, stralloc_something());
+
+ return s;
+}
+
+int
+main(void)
+{
+ int number_failed;
+
+ SRunner *sr = srunner_create(stralloc_suite());
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return number_failed;
+}