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
1515REPO_ROOT=" $( cd " $( dirname " $0 " ) /.." && pwd) "
1616TESTS_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.
2935require_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# ---------------------------------------------------------------------------
3948echo " ╔══════════════════════════════════════╗"
4049echo " ║ LiaScript Course Builder Test Suite ║"
4150echo " ╚══════════════════════════════════════╝"
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# ---------------------------------------------------------------------------
4661section " 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 ))
5973fi
6074
6175# ---------------------------------------------------------------------------
6276# 2. cram – CLI integration tests
6377# ---------------------------------------------------------------------------
6478section " 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 ))
7489fi
7590
7691# ---------------------------------------------------------------------------
7792# 3. remake – Makefile tests
7893# ---------------------------------------------------------------------------
7994section " 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
8697else
87- overall_failed= $(( overall_failed + 1 ))
98+ remake_failed=1
8899fi
89100
90101# ---------------------------------------------------------------------------
102+ # Final summary
103+ # ---------------------------------------------------------------------------
104+ overall_failed=$(( bats_failed + cram_failed + remake_failed ))
105+
91106echo " "
92107echo " ╔══════════════════════════════════════╗"
93108if [ " $overall_failed " -eq 0 ]; then
94109 echo " ║ ✅ All test suites passed ║"
95110else
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 ║"
97114fi
98115echo " ╚══════════════════════════════════════╝"
99116exit " $overall_failed "
0 commit comments