]> git.corax.cc Git - toolbox/commitdiff
test/toolbox: Add test cases for interface/implements mechanism
authorMatthias Kruk <m@m10k.eu>
Sun, 15 Jan 2023 09:22:19 +0000 (18:22 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 15 Jan 2023 09:22:19 +0000 (18:22 +0900)
There are no test cases for the interface/implements mechanism, making
it hard to tell if it works as intended, and if there are regressions.

This commit adds shellspec test cases for the behavior of `interface()'
and `implements()'.

test/include/car.sh [new file with mode: 0644]
test/include/invaliface.sh [new file with mode: 0644]
test/include/trabant.sh [new file with mode: 0644]
test/include/vehicle.sh [new file with mode: 0644]

diff --git a/test/include/car.sh b/test/include/car.sh
new file mode 100644 (file)
index 0000000..ca2710a
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+__init() {
+       if ! implements "vehicle"; then
+               return 1
+       fi
+
+       if ! interface "get_name" "get_speed"; then
+               return 1
+       fi
+
+       return 0
+}
+
+car_get_name() {
+       echo "car"
+}
+
+car_get_speed() {
+       echo "30"
+}
diff --git a/test/include/invaliface.sh b/test/include/invaliface.sh
new file mode 100644 (file)
index 0000000..36c717c
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+__init() {
+       if ! implements "missinginterface"; then
+               return 1
+       fi
+}
diff --git a/test/include/trabant.sh b/test/include/trabant.sh
new file mode 100644 (file)
index 0000000..6616d08
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+__init() {
+       if ! implements "car"; then
+               return 1
+       fi
+
+       return 0
+}
+
+trabant_get_name() {
+       echo "trabant"
+}
diff --git a/test/include/vehicle.sh b/test/include/vehicle.sh
new file mode 100644 (file)
index 0000000..c0c3e3d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+__init() {
+       if ! interface "get_name"; then
+               return 1
+       fi
+
+       return 0
+}