sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 4593bfb3596df8e69a178329283c9d07ed0eddbd
parent 931eb042009af6d402a9a80f3d03e37f5dfa6749
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed,  5 Nov 2025 18:41:15 +0100

tests: Add initial support for tests

Diffstat:
M.gitignore | 2++
MMakefile | 9+++++++--
Atests/0001-echo.sh | 23+++++++++++++++++++++++
Atests/Makefile | 6++++++
Atests/runtests.sh | 22++++++++++++++++++++++
5 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -104,3 +104,5 @@ /xargs /xinstall /yes +/tests/test.log +/tests/test.lst diff --git a/Makefile b/Makefile @@ -202,7 +202,7 @@ MAKEOBJ =\ OBJ = $(LIBUTFOBJ) $(LIBUTILOBJ) $(MAKEOBJ) all: scripts/make - $(SMAKE) $(BIN) + +@$(SMAKE) $(BIN) scripts/make: $(CC) -o $@ make/*.c @@ -252,9 +252,13 @@ sbase-box-uninstall: sbase-box proto $(DESTDIR)$(PREFIX)/bin/sbase-box -d $(DESTDIR)$(PREFIX)/bin/ scripts/uninstall proto +tests: all + @cd $@ && $(MAKE) + dist: clean mkdir -p sbase - cp -R LICENSE Makefile README TODO config.mk *.c *.1 *.h libutf libutil make scripts sbase + cp LICENSE Makefile README TODO config.mk *.c *.1 *.h sbase + cp -R libutf libutil make scripts tests sbase mv sbase sbase-$(VERSION) tar -cf sbase-$(VERSION).tar sbase-$(VERSION) gzip sbase-$(VERSION).tar @@ -265,6 +269,7 @@ sbase-box: $(BIN) $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ build/*.c $(LIB) clean: + @cd tests && $(MAKE) clean rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz rm -f scripts/make rm -f getconf.h diff --git a/tests/0001-echo.sh b/tests/0001-echo.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +tmp1=tmp1.$$ +tmp2=tmp2.$$ + +cleanup() +{ + st=$? + rm -f $tmp1 $tmp2 + exit $st +} + +trap cleanup EXIT HUP INT TERM + +cat <<'EOF' | tr -d '\n' > $tmp1 +--hello-- --world--! +EOF + +../echo -n --hello-- --world--! > $tmp2 + +diff -u $tmp1 $tmp2 diff --git a/tests/Makefile b/tests/Makefile @@ -0,0 +1,6 @@ +all: + @./runtests.sh + +clean: + rm -f test.log + rm -f tmp* diff --git a/tests/runtests.sh b/tests/runtests.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +export TZ=UTC + +cleanup() +{ + st=$? + rm -f test.res + exit $st +} + +trap cleanup EXIT HUP INT TERM + +for i in *-*.sh +do + printf "Test: %s\n\n" $i >> test.log + (./$i >> test.log 2>&1 && printf '[PASS]\t' || printf '[FAIL]\t' + echo "$i") | tee -a test.log +done | +tee test.res + +! grep FAIL test.res >/dev/null