From 7395f6ec5385cd4895755c0c48e878a01214ef1c Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 28 Apr 2023 00:54:59 +0300 Subject: added testing framework --- src/tests/framework.sh | 41 +++++++++++++++++++++++++++++++++++++++++ src/tests/run-tests | 4 ++++ src/tests/test1.sh | 12 ++++++++++++ 3 files changed, 57 insertions(+) create mode 100755 src/tests/framework.sh create mode 100755 src/tests/run-tests create mode 100755 src/tests/test1.sh (limited to 'src/tests') 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)) +} diff --git a/src/tests/run-tests b/src/tests/run-tests new file mode 100755 index 0000000..f109b8c --- /dev/null +++ b/src/tests/run-tests @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Test 1" +./test1.sh diff --git a/src/tests/test1.sh b/src/tests/test1.sh new file mode 100755 index 0000000..52c2ba3 --- /dev/null +++ b/src/tests/test1.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +. ./framework.sh + +plan 2 + +is "$(cat /proc/_test_module)" "You have no previous messages" + +echo kek > /proc/_test_module +is "$(cat /proc/_test_module)" "Your last message was: kek" + +conclude -- cgit v1.2.3