diff options
author | davidovski <david@davidovski.xyz> | 2022-06-27 01:14:42 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-06-27 01:14:42 +0100 |
commit | 7bba6cd7612293796e905885f9ed3072877798ab (patch) | |
tree | dd01942dbdd474a4df62ecf74479f5e78d83f1c8 /src/shtests.sh | |
parent | 79fb6f41104cd0d88891598ddfc3c30d1bb0352d (diff) |
added shmk, building all with shmk
Diffstat (limited to 'src/shtests.sh')
-rw-r--r-- | src/shtests.sh | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/shtests.sh b/src/shtests.sh deleted file mode 100644 index a899f3c..0000000 --- a/src/shtests.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh -# -# Simple shell test suite -# -# will run all functions with a name starting with test_ -# the return value of said function will determine if its a pass or fail -# -# to run a shell file full of unit tests, run: -# shtests [FILE] -# - -[ -f /usr/lib/colors.sh ] && . /usr/lib/colors.sh -[ -f colors.sh ] && . colors.sh - -PASS="${BLUE}[ ${GREEN}PASS${BLUE} ]${RESET}" -FAIL="${BLUE}[ ${RED}FAIL${BLUE} ]${RESET}" - -V=false - -runtest () { - test_name=$(echo $1 | sed "s/_/ /g") - test_func="$2" - printf "${BLUE}[ ] ${RESET}$test_name "; - if "$test_func" ; then - printf "\r$PASS\n" - return 0 - else - printf "\r$FAIL\n" - return 1 - fi -} - -# TODO use getopt for this -if [ "$1" = "-v" ]; then - shift - V=true -fi - -if [ $# = "0" ]; then - printf "${RED}No tests file has been provided\n" - exit 1; -else - . $@ -fi - -tests=$(sed -n "s/^test_\(.*\)\s*()\s*{/\1/p" $@) -total=$(echo $tests | wc -w) -passed=0 -failed=0 - -printf "${BLUE}Running $total tests: \n" -for name in $tests; do - if runtest "$name" "test_$name"; then - passed=$((passed+1)) - else - failed=$((failed+1)) - fi -done - -printf "\n${BLUE}Summary for $total tests:\n" -printf "\t${PASS} $passed\n" -printf "\t${FAIL} $failed\n" -printf "\n" - -[ "$passed" = "$total" ] || exit 1 - - |