From cb1991c58fd61f01b650d32d0a61ce482f14a87c Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 24 Apr 2021 10:10:49 +0900 Subject: [PATCH] test: Add script and Makefile target for test-suite execution This commit adds the "test" target to the Makefile and adds a script that executes all test cases. --- Makefile | 5 ++++- test.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 test.sh diff --git a/Makefile b/Makefile index 1d779a7..4ff0c7a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PHONY = install uninstall +PHONY = install uninstall test ifeq ($(PREFIX), ) PREFIX = /usr @@ -8,6 +8,9 @@ all: clean: +test: + ./test.sh + install: mkdir -p $(DESTDIR)/$(PREFIX)/share/toolbox mkdir -p $(DESTDIR)/$(PREFIX)/bin diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ad0cf81 --- /dev/null +++ b/test.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +main() { + local tests + local missing + local modules + local failed + local module + local test + local err + + tests=() + missing=() + modules=() + failed=() + + while read -r module; do + test="test/${module#*include/}" + + if ! [ -f "$test" ]; then + missing+=("$module") + else + tests+=("$test") + fi + done < <(find "include" -type f -iname "*.sh") + + if (( ${#missing[@]} > 0 )); then + echo "There are no tests for these modules:" + + for module in "${missing[@]}"; do + echo " $module" + done + + return 1 + fi + + for test in "${tests[@]}"; do + if ! "$test"; then + failed+=("$test") + fi + done + + if (( ${#failed[@]} > 0 )); then + echo "The following unit tests failed:" + + for test in "${failed[@]}"; do + echo " $test" + done + + return 1 + fi + + echo "All unit tests passed" + return 0 +} + +{ + main "$@" + exit "$?" +} -- 2.47.3