aboutsummaryrefslogtreecommitdiff
path: root/src/libs/testing-library
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-04-28 20:39:42 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-04-28 20:39:42 +0300
commita78c52265d755a2294a743e186ad5a6b5456d9f1 (patch)
tree3606129e28526dca6c2726712c755700b912895d /src/libs/testing-library
parent7395f6ec5385cd4895755c0c48e878a01214ef1c (diff)
testing structure done
Diffstat (limited to 'src/libs/testing-library')
-rwxr-xr-xsrc/libs/testing-library53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/libs/testing-library b/src/libs/testing-library
new file mode 100755
index 0000000..a1cf3c1
--- /dev/null
+++ b/src/libs/testing-library
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+function description {
+ echo "# DESCRIPTION: $1"
+}
+
+# $1 is the number of total tests
+function plan {
+ TESTS=$1; FAILED=0; CUR_TEST=0
+ echo "1..$TESTS"
+}
+
+function conclude {
+ PERC=$(echo "scale=2;100 * $FAILED / $TESTS" | bc)
+ echo "# CONCLUSION: ($PERC%) $FAILED out of $TESTS tests failed"
+
+ if [ $TESTS -ne $CUR_TEST ]; then
+ echo -e "# expected $TESTS, but got $CUR_TEST tests"
+ fi
+
+ if [ $FAILED -ne 0 ]; then
+ exit 1
+ fi
+}
+
+# $1 is the value to be tested
+# $2 description
+function ok {
+ CUR_TEST=$((CUR_TEST + 1))
+
+ if [ $1 -eq 0 ]; then
+ echo "ok $CUR_TEST - $2"
+ else
+ echo "not ok $CUR_TEST - $2"
+ echo -e " returned '$1'"
+ FAILED=$((FAILED + 1))
+ fi
+}
+
+# $1 is the expected value
+# $2 is the actual value
+# $3 description
+function is {
+ CUR_TEST=$((CUR_TEST + 1))
+
+ if [ "$1" = "$2" ]; then
+ echo "ok $CUR_TEST - $3"
+ else
+ echo "not ok $CUR_TEST - $3"
+ echo -e " exptected '$2', but got '$1'"
+ FAILED=$((FAILED + 1))
+ fi
+}