summaryrefslogtreecommitdiff
path: root/minitap.sh
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2023-07-22 12:26:18 +0100
committerdakkar <dakkar@thenautilus.net>2023-07-22 12:26:18 +0100
commitef2ab079df0a0971dee99547a31a021874e95077 (patch)
tree90794d43988e1056d757471665b5199c873e9c17 /minitap.sh
parentnotes for next steps (diff)
downloadbash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.tar.gz
bash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.tar.bz2
bash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.zip
move tests to actual test programs
yes, TAP
Diffstat (limited to 'minitap.sh')
-rw-r--r--minitap.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/minitap.sh b/minitap.sh
new file mode 100644
index 0000000..d5bb4f8
--- /dev/null
+++ b/minitap.sh
@@ -0,0 +1,59 @@
+minitap_started=0
+minitap_counter=0
+
+function ok() {
+ minitap/maybe-start
+ (( ++minitap_counter ))
+ echo "ok ${minitap_counter} - $*"
+}
+
+function nok() {
+ minitap/maybe-start
+ (( ++minitap_counter ))
+ echo "not ok ${minitap_counter} - $*"
+}
+
+function diag() {
+ echo "# $*"
+}
+
+function is() {
+ local got="$1";shift
+ local expect="$1";shift
+
+ if [[ "$got" == $expect ]]; then
+ ok "$@"
+ else
+ diag "got <$got>, expected <$expect>";
+ nok "$@"
+ fi
+}
+
+function should-succeed() {
+ local last_status="$?"
+ if [[ "$last_status" -eq 0 ]]; then
+ ok "$@"
+ else
+ nok "$@"
+ fi
+}
+
+function should-fail() {
+ local last_status="$?"
+ if [[ "$last_status" -eq 0 ]]; then
+ nok "$@"
+ else
+ ok "$@"
+ fi
+}
+
+function done-testing() {
+ echo "1..${minitap_counter}"
+}
+
+function minitap/maybe-start() {
+ if [[ "$minitap_started" == 0 ]]; then
+ echo "TAP version 13"
+ minitap_started=1
+ fi
+}