diff options
author | dakkar <dakkar@thenautilus.net> | 2023-07-22 12:26:18 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2023-07-22 12:26:18 +0100 |
commit | ef2ab079df0a0971dee99547a31a021874e95077 (patch) | |
tree | 90794d43988e1056d757471665b5199c873e9c17 | |
parent | notes for next steps (diff) | |
download | bash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.tar.gz bash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.tar.bz2 bash-object-system-ef2ab079df0a0971dee99547a31a021874e95077.zip |
move tests to actual test programs
yes, TAP
-rw-r--r-- | minitap.sh | 59 | ||||
-rw-r--r-- | t/inherit.t | 46 | ||||
-rw-r--r-- | t/testlib.sh | 12 | ||||
-rw-r--r-- | test.sh | 48 |
4 files changed, 117 insertions, 48 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 +} diff --git a/t/inherit.t b/t/inherit.t new file mode 100644 index 0000000..58f7e22 --- /dev/null +++ b/t/inherit.t @@ -0,0 +1,46 @@ +#!/bin/bash + +. t/testlib.sh + +class A; do + + function thing() { + echo "<$self> A/thing ($*)" + } + +done + +class B; do + extends A + + function other() { + echo "<$self> B/other ($*)" + } + +done + +class C; do + extends B + + function thing() { + echo "<$self> C/thing ($*)" + + $self next/method "$@" + } + +done + +A new-into objA +B new-into objB +C new-into objC + +[[ -n "$objA" ]]; should-succeed simple instantiation +[[ -n "$objB" ]]; should-succeed instantiation with inheritance + +is "$($objA thing 1 2 3)" "<*A*> A/thing (1 2 3)" direct call +is "$($objB other a b c)" "<*B*> B/other (a b c)" direct call +is "$($objB thing 4 5 6)" "<*B*> A/thing (4 5 6)" inherited call +is "$($objC thing 7 8 9)" $'<*C*> C/thing (7 8 9)\n<*C*> A/thing (7 8 9)' next/method + + +done-testing diff --git a/t/testlib.sh b/t/testlib.sh new file mode 100644 index 0000000..6da46f5 --- /dev/null +++ b/t/testlib.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +PS4='[${#FUNCNAME[*]}] ${BASH_SOURCE[0]}:${LINENO} (${FUNCNAME[0]}) +' + +. bos-namespaces.sh +. bos-object-id.sh +. bos-mop.sh +. bos-dispatch.sh +. bos-mop-inheritance.sh +. bos-sugar.sh + +. minitap.sh diff --git a/test.sh b/test.sh deleted file mode 100644 index 1a4371e..0000000 --- a/test.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -PS4='[${#FUNCNAME[*]}] ${BASH_SOURCE[0]}:${LINENO} (${FUNCNAME[0]}) +' - -. bos-namespaces.sh -. bos-object-id.sh -. bos-mop.sh -. bos-dispatch.sh -. bos-mop-inheritance.sh -. bos-sugar.sh - -class A; do - - function thing() { - echo "<$self> A/thing ($*)" - } - -done - -class B; do - extends A - - function other() { - echo "<$self> B/other ($*)" - } - -done - -class C; do - extends B - - function thing() { - echo "<$self> C/thing ($*)" - - $self next/method "$@" - } - -done - -A new-into objA -B new-into objB -C new-into objC - -$objA thing 1 2 3 -$objB thing 4 5 6 -$objC thing 7 8 9 -$objB other a b c - |