-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.sh
More file actions
143 lines (131 loc) · 5.2 KB
/
Copy pathtest.sh
File metadata and controls
143 lines (131 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# ================================================================
# One-click unit test runner for l4s5_Anbo (Linux / WSL / macOS)
#
# Fully self-bootstrapping: auto-installs Ruby, gcc, and Ceedling
# via system package manager if missing. Ceedling gem is installed
# locally in tools/gems — no global gem pollution.
#
# Usage:
# ./test.sh run all tests
# ./test.sh test:anbo_rb run a single test module
# ./test.sh clean clean test build artifacts
# ================================================================
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
TOOLS="$ROOT/tools"
# ---- Versions ----
CEEDLING_VER="0.31.1"
MIN_RUBY="2.4"
# ================================================================
# Helper: detect package manager and install packages
# ================================================================
pkg_install() {
local pkg_apt="$1"
local pkg_brew="${2:-$1}"
local pkg_pacman="${3:-$1}"
local pkg_dnf="${4:-$1}"
if command -v apt-get &>/dev/null; then
echo " -> sudo apt-get install -y $pkg_apt"
sudo apt-get update -qq
sudo apt-get install -y -qq $pkg_apt
elif command -v brew &>/dev/null; then
echo " -> brew install $pkg_brew"
brew install $pkg_brew
elif command -v pacman &>/dev/null; then
echo " -> sudo pacman -S --noconfirm $pkg_pacman"
sudo pacman -S --noconfirm $pkg_pacman
elif command -v dnf &>/dev/null; then
echo " -> sudo dnf install -y $pkg_dnf"
sudo dnf install -y $pkg_dnf
else
return 1
fi
}
# ================================================================
# 1. Ensure Ruby
# ================================================================
if ! command -v ruby &>/dev/null; then
echo ""
echo "============================================================"
echo " Ruby not found — installing via package manager ..."
echo "============================================================"
if ! pkg_install "ruby ruby-dev" "ruby" "ruby" "ruby ruby-devel"; then
echo ""
echo "ERROR: No supported package manager found (apt/brew/pacman/dnf)."
echo " Please install Ruby >= ${MIN_RUBY} manually."
exit 1
fi
hash -r # refresh command cache
fi
RUBY_OK=$(ruby -e "puts (Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('${MIN_RUBY}')) ? 'yes' : 'no'")
if [ "$RUBY_OK" != "yes" ]; then
echo "ERROR: Ruby >= ${MIN_RUBY} required. Current: $(ruby --version)"
exit 1
fi
echo "[OK] Ruby: $(ruby --version)"
# ================================================================
# 2. Ensure gcc
# ================================================================
if ! command -v gcc &>/dev/null; then
echo ""
echo "============================================================"
echo " gcc not found — installing via package manager ..."
echo "============================================================"
if ! pkg_install "build-essential" "gcc" "base-devel" "gcc gcc-c++"; then
echo ""
echo "ERROR: No supported package manager found."
echo " Please install gcc manually."
exit 1
fi
hash -r
fi
echo "[OK] gcc: $(gcc --version | head -1)"
# ================================================================
# 3. Install Ceedling gem locally (GEM_HOME = tools/gems)
# ================================================================
export GEM_HOME="$TOOLS/gems"
export GEM_PATH="$GEM_HOME"
export PATH="$GEM_HOME/bin:$PATH"
if ! "$GEM_HOME/bin/ceedling" version &>/dev/null 2>&1; then
echo ""
echo "============================================================"
echo " Ceedling not found — installing gem v${CEEDLING_VER} ..."
echo "============================================================"
gem install ceedling -v "$CEEDLING_VER" --no-document
echo "Ceedling ready."
fi
echo "[OK] Ceedling: $GEM_HOME/bin/ceedling"
# ================================================================
# 4. Auto-clean stale build cache (cross-platform .o mismatch)
# ================================================================
BUILD_TEST="$ROOT/build/test"
if [ -d "$BUILD_TEST" ]; then
# Pick any .o file and check if it matches the current host
stale_obj=$(find "$BUILD_TEST" -name '*.o' -print -quit 2>/dev/null || true)
if [ -n "$stale_obj" ] && command -v file &>/dev/null; then
obj_arch=$(file -b "$stale_obj")
case "$(uname -m)" in
x86_64|amd64) expected="ELF 64-bit" ;;
i*86) expected="ELF 32-bit" ;;
aarch64|arm64) expected="ELF 64-bit" ;;
*) expected="ELF" ;;
esac
if ! echo "$obj_arch" | grep -q "$expected"; then
echo "[CLEAN] Stale build cache detected (wrong arch) — cleaning..."
rm -rf "$BUILD_TEST"
fi
fi
fi
# ================================================================
# 5. Run Ceedling
# ================================================================
echo ""
cd "$ROOT"
if [ $# -eq 0 ]; then
echo "Running: ceedling test:all"
ceedling test:all
else
echo "Running: ceedling $*"
ceedling "$@"
fi