From 9dc6b74058afd1206014d3cfca1574578a41268c Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 14 Jun 2022 16:39:00 +0200 Subject: [PATCH] tests: Switch to kyua/atf-test, add tests for functions.sh --- .gitignore | 1 + Makefile | 18 +++++++++++++++--- tests/functions_test | 27 +++++++++++++++++++++++++++ tests/test_env.sh | 15 +++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100755 tests/functions_test create mode 100644 tests/test_env.sh diff --git a/.gitignore b/.gitignore index b1c34f7..f617c8e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.o *.1 *.5 +Kyuafile abuild abuild-fetch abuild-gzsplit diff --git a/Makefile b/Makefile index ef9bbd5..e02eb5a 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ P=$(PACKAGE)-$(VERSION) all: $(USR_BIN_FILES) $(MAN_PAGES) functions.sh clean: - @rm -f $(USR_BIN_FILES) $(MAN_PAGES) *.o functions.sh + @rm -f $(USR_BIN_FILES) $(MAN_PAGES) *.o functions.sh Kyuafile tests/Kyuafile %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS-$@) -o $@ -c $< @@ -102,8 +102,20 @@ help: @echo "$(P) makefile" @echo "usage: make install [ DESTDIR= ]" -check: $(USR_BIN_FILE) functions.sh - cd tests && bats $${FILTER:+ --filter $$FILTER} *.bats +tests/Kyuafile: $(wildcard tests/*_test) + echo "syntax(2)" > $@ + echo "test_suite('abuild')" >> $@ + for i in $(notdir $(wildcard tests/*_test)); do \ + echo "atf_test_program{name='$$i',timeout=5}" >> $@ ; \ + done + +Kyuafile: tests/Kyuafile + echo "syntax(2)" > $@ + echo "test_suite('abuild')" >> $@ + echo "include('tests/Kyuafile')" >> $@ + +check: $(SCRIPTS) $(USR_BIN_FILES) functions.sh tests/Kyuafile Kyuafile + kyua test || (kyua report --verbose && exit 1) install: $(USR_BIN_FILES) $(SAMPLES) $(MAN_PAGES) abuild.conf functions.sh install -d $(DESTDIR)/$(bindir) $(DESTDIR)/$(sysconfdir) \ diff --git a/tests/functions_test b/tests/functions_test new file mode 100755 index 0000000..e3f044c --- /dev/null +++ b/tests/functions_test @@ -0,0 +1,27 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh +init_tests \ + funcs_check_CBUILD \ + funcs_check_missing_gcc \ + funcs_check_missing_apk + +FUNCS=$(atf_get_srcdir)/../functions.sh + +funcs_check_CBUILD_body() { + atf_check -s exit:0 \ + -o not-empty \ + -e empty \ + sh -e -c " . $FUNCS; echo \"\$CBUILD\"" +} + +funcs_check_missing_gcc_body() { + atf_check -s exit:0 \ + sh -e -c "CC=false; . $FUNCS && test -z \"$CBUILD\"" +} + +funcs_check_missing_apk_body() { + atf_check -s exit:1 \ + -e match:"Unable to deduce build architecture" \ + sh -e -c "APK=false; . $FUNCS && test -z \"$CBUILD\"" +} diff --git a/tests/test_env.sh b/tests/test_env.sh new file mode 100644 index 0000000..737d8df --- /dev/null +++ b/tests/test_env.sh @@ -0,0 +1,15 @@ +PATH=$(atf_get_srcdir)/..:$PATH + +init_tests() { + 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 +}