#!/bin/bash
+get_module_names() {
+ local path="$1"
+
+ local candidate
+
+ while read -r candidate; do
+ local filename
+
+ # No constructor -> no module
+ if ! grep "^__init\(\)" < "$candidate" &>/dev/null; then
+ continue
+ fi
+
+ filename="${candidate#$path/}"
+ echo "${filename%.sh}"
+ done < <(find "$path" -type f -iname "*.sh")
+
+ return 0
+}
+
+get_test_names() {
+ local path="$1"
+
+ local candidate
+
+ while read -r candidate; do
+ echo "${candidate#$path/}"
+ done < <(find "$path" -type f -iname "*_spec.sh")
+
+ return 0
+}
+
main() {
local tests
local missing
modules=()
failed=()
- while read -r module; do
- test="test/${module#*include/}"
+ readarray -t modules < <(get_module_names "include")
+ readarray -t tests < <(get_test_names "test")
- if ! [ -f "$test" ]; then
+ for module in "${modules[@]}"; do
+ if ! array_contains "${module}_spec.sh" "${tests[@]}"; then
missing+=("$module")
- else
- tests+=("$test")
fi
- done < <(find "include" -type f -iname "*.sh")
+ done
if (( ${#missing[@]} > 0 )); then
echo "There are no tests for these modules:"
fi
for test in "${tests[@]}"; do
- if ! "$test"; then
+ if ! shellspec --shell bash --format d "test/$test"; then
failed+=("$test")
fi
done
}
{
+ if ! . toolbox.sh; then
+ exit 1
+ fi
+
+ if ! include "array"; then
+ exit 1
+ fi
+
main "$@"
exit "$?"
}