diff options
| author | kartofen <mladenovnasko0@gmail.com> | 2023-04-28 00:54:59 +0300 |
|---|---|---|
| committer | kartofen <mladenovnasko0@gmail.com> | 2023-04-28 00:54:59 +0300 |
| commit | 7395f6ec5385cd4895755c0c48e878a01214ef1c (patch) | |
| tree | 179d108430d6a6e580ab846f0ea0ea2af26921ae /src/tests/framework.sh | |
| parent | 2c0f30c29b4b70a45ba01a0c32ae31ac7f75625b (diff) | |
added testing framework
Diffstat (limited to 'src/tests/framework.sh')
| -rwxr-xr-x | src/tests/framework.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tests/framework.sh b/src/tests/framework.sh new file mode 100755 index 0000000..d6b7854 --- /dev/null +++ b/src/tests/framework.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# $1 is the number of total tests +function plan { + TESTS=$1 + FAILED=0 + CUR_TEST=1 + + echo "1..$TESTS" +} + +function conclude { + if [ $FAILED -ne 0 ]; then + exit 1 + fi +} + +# $1 is the value to be tested +function ok { + if [ $1 -eq 0 ]; then + echo "ok $CUR_TEST" + else + echo "not ok $CUR_TEST" + FAILED=$((FAILED + 1)) + fi + + CUR_TEST=$((CUR_TEST + 1)) +} + +# $1 is the expected value +# $2 is the actual value +function is { + if [ "$1" = "$2" ]; then + echo "ok $CUR_TEST" + else + echo "not ok $CUR_TEST - expected '$1', but got '$2'" + FAILED=$((FAILED + 1)) + fi + + CUR_TEST=$((CUR_TEST + 1)) +} |
