Skip to content

Commit b392c24

Browse files
Copilotvgoehler
andauthored
tests: require_tool aborts immediately on missing dependency
- Upfront dependency check for all three tools (bats, cram, remake) at the start of run_tests.sh; any missing tool calls exit 1 immediately and prints a clear install hint. - Track failures per framework (bats_failed/cram_failed/remake_failed) instead of per bats-file, so the final summary correctly names which framework(s) failed. - Fix nullglob edge case: use array + `[ ! -e "${arr[0]}" ]` guard so an empty bats/ or cram/ directory is handled gracefully. Agent-Logs-Url: https://github.com/TUBAF-IfI-LiaScript/TUBAF-IfI-LiaScript.github.io/sessions/3da2da68-a840-4f39-9d3e-a329500bbdbb Co-authored-by: vgoehler <1705385+vgoehler@users.noreply.github.com>
1 parent 60e7f30 commit b392c24

1 file changed

Lines changed: 44 additions & 27 deletions

File tree

tests/run_tests.sh

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# Run the full test suite.
33
#
4-
# Prerequisites
4+
# Prerequisites (all must be installed – any missing tool aborts immediately)
55
# bats ≥ 1.0 (https://github.com/bats-core/bats-core)
66
# cram ≥ 0.7 (pip install cram)
77
# remake ≥ 4.3 (apt install remake)
@@ -14,7 +14,11 @@ set -euo pipefail
1414

1515
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1616
TESTS_DIR="$REPO_ROOT/tests"
17-
overall_failed=0
17+
18+
# Per-framework pass/fail tracking (0 = passed, 1 = failed)
19+
bats_failed=0
20+
cram_failed=0
21+
remake_failed=0
1822

1923
# ---------------------------------------------------------------------------
2024
# helpers
@@ -26,74 +30,87 @@ section() {
2630
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
2731
}
2832

33+
# require_tool <name> <install-hint>
34+
# Exits the entire script immediately if <name> is not on PATH.
2935
require_tool() {
3036
if ! command -v "$1" >/dev/null 2>&1; then
31-
echo " ⚠️ '$1' not found – skipping those tests"
32-
echo " Install: $2"
33-
return 1
37+
echo ""
38+
echo "❌ Required tool '$1' not found."
39+
echo " Install with: $2"
40+
echo " All three tools (bats, cram, remake) must be installed before running the suite."
41+
exit 1
3442
fi
35-
return 0
3643
}
3744

45+
# ---------------------------------------------------------------------------
46+
# Dependency check – fails fast if any tool is missing
3847
# ---------------------------------------------------------------------------
3948
echo "╔══════════════════════════════════════╗"
4049
echo "║ LiaScript Course Builder Test Suite ║"
4150
echo "╚══════════════════════════════════════╝"
4251

52+
section "Checking prerequisites"
53+
require_tool bats "https://github.com/bats-core/bats-core (or: npm install -g bats)"
54+
require_tool cram "pip install cram"
55+
require_tool remake "apt install remake"
56+
echo " ✅ bats, cram, remake all found"
57+
4358
# ---------------------------------------------------------------------------
4459
# 1. bats – shell script unit tests
4560
# ---------------------------------------------------------------------------
4661
section "bats (shell script unit tests)"
47-
if require_tool bats "https://github.com/bats-core/bats-core"; then
48-
for bats_file in "$TESTS_DIR"/bats/*.bats; do
62+
bats_files=("$TESTS_DIR"/bats/*.bats)
63+
if [ ! -e "${bats_files[0]}" ]; then
64+
echo " ⚠️ No .bats files found in tests/bats/ – nothing to run"
65+
else
66+
for bats_file in "${bats_files[@]}"; do
4967
echo ""
5068
echo "$(basename "$bats_file")"
51-
if bats "$bats_file"; then
52-
: # success
53-
else
54-
overall_failed=$((overall_failed + 1))
69+
if ! bats "$bats_file"; then
70+
bats_failed=1
5571
fi
5672
done
57-
else
58-
overall_failed=$((overall_failed + 1))
5973
fi
6074

6175
# ---------------------------------------------------------------------------
6276
# 2. cram – CLI integration tests
6377
# ---------------------------------------------------------------------------
6478
section "cram (CLI integration tests)"
65-
if require_tool cram "pip install cram"; then
79+
cram_files=("$TESTS_DIR"/cram/*.t)
80+
if [ ! -e "${cram_files[0]}" ]; then
81+
echo " ⚠️ No .t files found in tests/cram/ – nothing to run"
82+
else
6683
export REPO_ROOT
67-
if cram --shell=bash "$TESTS_DIR"/cram/*.t; then
84+
if cram --shell=bash "${cram_files[@]}"; then
6885
echo " cram: all tests passed"
6986
else
70-
overall_failed=$((overall_failed + 1))
87+
cram_failed=1
7188
fi
72-
else
73-
overall_failed=$((overall_failed + 1))
7489
fi
7590

7691
# ---------------------------------------------------------------------------
7792
# 3. remake – Makefile tests
7893
# ---------------------------------------------------------------------------
7994
section "remake (Makefile tests)"
80-
if require_tool remake "apt install remake"; then
81-
if remake -f "$TESTS_DIR/remake/Makefile.test" test; then
82-
: # success – remake already prints a summary
83-
else
84-
overall_failed=$((overall_failed + 1))
85-
fi
95+
if remake -f "$TESTS_DIR/remake/Makefile.test" test; then
96+
: # success – remake already prints a summary
8697
else
87-
overall_failed=$((overall_failed + 1))
98+
remake_failed=1
8899
fi
89100

90101
# ---------------------------------------------------------------------------
102+
# Final summary
103+
# ---------------------------------------------------------------------------
104+
overall_failed=$(( bats_failed + cram_failed + remake_failed ))
105+
91106
echo ""
92107
echo "╔══════════════════════════════════════╗"
93108
if [ "$overall_failed" -eq 0 ]; then
94109
echo "║ ✅ All test suites passed ║"
95110
else
96-
echo "║ ❌ $overall_failed suite(s) had failures ║"
111+
[ "$bats_failed" -eq 1 ] && echo "║ ❌ bats suite FAILED ║"
112+
[ "$cram_failed" -eq 1 ] && echo "║ ❌ cram suite FAILED ║"
113+
[ "$remake_failed" -eq 1 ] && echo "║ ❌ remake suite FAILED ║"
97114
fi
98115
echo "╚══════════════════════════════════════╝"
99116
exit "$overall_failed"

0 commit comments

Comments
 (0)