-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·241 lines (204 loc) · 8 KB
/
run-tests.sh
File metadata and controls
executable file
·241 lines (204 loc) · 8 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
# run-tests.sh — Run fsociety plugin test suite with colored per-plugin output
# Usage:
# ./run-tests.sh Run all plugins
# ./run-tests.sh elliot Run specific plugin(s)
# ./run-tests.sh -v Verbose mode (show individual test names)
# ./run-tests.sh -q Quiet mode (summary only)
set -eo pipefail
# ── Colors ──────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
DIM='\033[2m'
BOLD='\033[1m'
RESET='\033[0m'
# ── Plugin metadata (bash 3 compatible) ────────────────────
plugin_color() {
case "$1" in
elliot) echo "$RED" ;;
romero) echo "$MAGENTA" ;;
trenton) echo "$CYAN" ;;
tyrell) echo "$YELLOW" ;;
fsociety) echo "$GREEN" ;;
*) echo "$WHITE" ;;
esac
}
plugin_icon() {
case "$1" in
elliot) printf "⚡" ;;
romero) printf "🔬" ;;
trenton) printf "🛡 " ;;
tyrell) printf "🕵 " ;;
fsociety) printf "💀" ;;
*) printf "📦" ;;
esac
}
# ── Parse args ─────────────────────────────────────────────
VERBOSE=0
QUIET=0
PLUGINS=""
for arg in "$@"; do
case "$arg" in
-v|--verbose) VERBOSE=1 ;;
-q|--quiet) QUIET=1 ;;
-h|--help)
echo -e "${BOLD}Usage:${RESET} ./run-tests.sh [options] [plugin ...]"
echo ""
echo "Options:"
echo " -v, --verbose Show individual test names"
echo " -q, --quiet Summary only (no per-plugin details)"
echo " -h, --help Show this help"
echo ""
echo "Plugins: elliot, romero, trenton, tyrell, fsociety"
echo "If no plugins specified, runs all."
exit 0
;;
*) PLUGINS="$PLUGINS $arg" ;;
esac
done
if [ -z "$PLUGINS" ]; then
PLUGINS="elliot romero trenton tyrell fsociety"
fi
# ── Paths ──────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_DIR="$SCRIPT_DIR/__tests__"
# ── Banner ─────────────────────────────────────────────────
echo ""
echo -e "${BOLD}${WHITE} ╔═══════════════════════════════════════════╗${RESET}"
echo -e "${BOLD}${WHITE} ║ ${RED}f${GREEN}s${YELLOW}o${BLUE}c${MAGENTA}i${CYAN}e${RED}t${GREEN}y${WHITE} test suite ║${RESET}"
echo -e "${BOLD}${WHITE} ╚═══════════════════════════════════════════╝${RESET}"
echo ""
# ── Run tests per plugin ──────────────────────────────────
TOTAL_PASS=0
TOTAL_FAIL=0
TOTAL_SKIP=0
TOTAL_DURATION=0
PLUGIN_COUNT=0
FAILED_PLUGINS=""
TABLE_ROWS=""
for plugin in $PLUGINS; do
plugin_dir="$TEST_DIR/$plugin"
color=$(plugin_color "$plugin")
icon=$(plugin_icon "$plugin")
if [ ! -d "$plugin_dir" ]; then
echo -e " ${YELLOW}⚠ ${plugin}${RESET} — no tests found at $plugin_dir"
echo ""
continue
fi
# Collect test files
test_files=""
file_count=0
for f in "$plugin_dir"/*.test.js; do
[ -f "$f" ] || continue
test_files="$test_files $f"
file_count=$((file_count + 1))
done
if [ $file_count -eq 0 ]; then
echo -e " ${YELLOW}⚠ ${plugin}${RESET} — no .test.js files"
echo ""
continue
fi
PLUGIN_COUNT=$((PLUGIN_COUNT + 1))
if [ $QUIET -eq 0 ]; then
echo -e " ${color}${icon} ${BOLD}${plugin}${RESET}${DIM} (${file_count} files)${RESET}"
fi
# Run tests and capture output
output=$(node --test $test_files 2>&1) || true
# Parse results from TAP output
pass=$(echo "$output" | grep -E '^# pass' | awk '{print $3}')
fail=$(echo "$output" | grep -E '^# fail' | awk '{print $3}')
skip=$(echo "$output" | grep -E '^# skipped' | awk '{print $3}')
duration=$(echo "$output" | grep -E '^# duration_ms' | awk '{print $3}')
pass=${pass:-0}
fail=${fail:-0}
skip=${skip:-0}
duration=${duration:-0}
TOTAL_PASS=$((TOTAL_PASS + pass))
TOTAL_FAIL=$((TOTAL_FAIL + fail))
TOTAL_SKIP=$((TOTAL_SKIP + skip))
# Duration math (handle decimals by truncating)
duration_int=${duration%%.*}
duration_int=${duration_int:-0}
TOTAL_DURATION=$((TOTAL_DURATION + duration_int))
if [ "$fail" -gt 0 ] 2>/dev/null; then
FAILED_PLUGINS="$FAILED_PLUGINS $plugin"
status="${RED}✗ FAIL${RESET}"
else
status="${GREEN}✓ PASS${RESET}"
fi
# Format duration
if [ "$duration_int" -ge 1000 ] 2>/dev/null; then
duration_fmt="$((duration_int / 1000)).$((duration_int % 1000 / 100))s"
else
duration_fmt="${duration_int}ms"
fi
TABLE_ROWS="${TABLE_ROWS}${plugin}|${pass}|${fail}|${skip}|${duration_fmt}|${status}
"
if [ $QUIET -eq 0 ]; then
echo -e " ${status} ${WHITE}${pass} passed${RESET}${DIM}, ${fail} failed, ${skip} skipped (${duration_fmt})${RESET}"
# Verbose: show individual test suites
if [ $VERBOSE -eq 1 ]; then
echo "$output" | grep -E '^\s*(ok|not ok)\s+\d+\s+-\s+' | while read -r line; do
if echo "$line" | grep -q "^not ok"; then
echo -e " ${RED}✗${RESET} ${line#*- }"
else
echo -e " ${GREEN}✓${RESET}${DIM} ${line#*- }${RESET}"
fi
done
fi
# Show failures in non-quiet mode
if [ "$fail" -gt 0 ] 2>/dev/null; then
echo ""
echo -e " ${RED}${BOLD}Failures:${RESET}"
echo "$output" | grep -A 5 "^not ok" | head -30 | while read -r line; do
echo -e " ${RED} $line${RESET}"
done
fi
echo ""
fi
done
# ── Summary ────────────────────────────────────────────────
# Format total duration
if [ "$TOTAL_DURATION" -ge 1000 ] 2>/dev/null; then
total_fmt="$((TOTAL_DURATION / 1000)).$((TOTAL_DURATION % 1000 / 100))s"
else
total_fmt="${TOTAL_DURATION}ms"
fi
echo -e " ${DIM}─────────────────────────────────────────────${RESET}"
echo ""
if [ -z "$FAILED_PLUGINS" ]; then
echo -e " ${GREEN}${BOLD} ALL PASSING${RESET} ${WHITE}${TOTAL_PASS} tests${RESET}${DIM} across ${PLUGIN_COUNT} plugins (${total_fmt})${RESET}"
else
echo -e " ${RED}${BOLD} FAILURES${RESET} ${WHITE}${TOTAL_PASS} passed, ${RED}${TOTAL_FAIL} failed${RESET}${DIM} across ${PLUGIN_COUNT} plugins (${total_fmt})${RESET}"
echo -e " ${RED}Failed:${FAILED_PLUGINS}${RESET}"
fi
if [ "$TOTAL_SKIP" -gt 0 ]; then
echo -e " ${YELLOW} ${TOTAL_SKIP} skipped${RESET}"
fi
echo ""
# ── Per-plugin table ───────────────────────────────────────
echo -e " ${BOLD}${WHITE}Plugin Pass Fail Skip Time Status${RESET}"
echo -e " ${DIM}──────────── ───── ───── ───── ─────── ──────${RESET}"
echo "$TABLE_ROWS" | while IFS='|' read -r p_name p_pass p_fail p_skip p_time p_status; do
[ -z "$p_name" ] && continue
color=$(plugin_color "$p_name")
icon=$(plugin_icon "$p_name")
printf " ${color}${icon} %-10s${RESET}" "$p_name"
printf " ${GREEN}%-5s${RESET}" "$p_pass"
if [ "$p_fail" -gt 0 ] 2>/dev/null; then
printf " ${RED}%-5s${RESET}" "$p_fail"
else
printf " ${DIM}%-5s${RESET}" "$p_fail"
fi
printf " ${DIM}%-5s${RESET}" "$p_skip"
printf " ${DIM}%-7s${RESET}" "$p_time"
echo -e " $p_status"
done
echo ""
# Exit with failure if any plugin failed
[ -z "$FAILED_PLUGINS" ]