From bc3e83f463915fc89e8c574981546624b5c2f242 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sun, 15 Jan 2023 18:22:19 +0900 Subject: [PATCH] test/toolbox: Add test cases for interface/implements mechanism 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 | 21 +++++++++++++++++++++ test/include/invaliface.sh | 7 +++++++ test/include/trabant.sh | 13 +++++++++++++ test/include/vehicle.sh | 9 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 test/include/car.sh create mode 100644 test/include/invaliface.sh create mode 100644 test/include/trabant.sh create mode 100644 test/include/vehicle.sh diff --git a/test/include/car.sh b/test/include/car.sh new file mode 100644 index 0000000..ca2710a --- /dev/null +++ b/test/include/car.sh @@ -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 index 0000000..36c717c --- /dev/null +++ b/test/include/invaliface.sh @@ -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 index 0000000..6616d08 --- /dev/null +++ b/test/include/trabant.sh @@ -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 index 0000000..c0c3e3d --- /dev/null +++ b/test/include/vehicle.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +__init() { + if ! interface "get_name"; then + return 1 + fi + + return 0 +} -- 2.47.3