-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·185 lines (154 loc) · 5.08 KB
/
test.sh
File metadata and controls
executable file
·185 lines (154 loc) · 5.08 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
#!/bin/bash
# Static analysis test suite for all Pebble apps
# Requires: cppcheck (brew install cppcheck)
# Optional: pebble SDK for full build tests
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PASS=0
FAIL=0
ERRORS=""
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m'
echo "======================================"
echo " Pebble Apps Test Suite"
echo "======================================"
echo ""
# Check for cppcheck
if ! command -v cppcheck &> /dev/null; then
echo -e "${RED}ERROR: cppcheck not found. Install with: brew install cppcheck${NC}"
exit 1
fi
echo "Using cppcheck $(cppcheck --version 2>&1 | head -1)"
echo ""
# Test 1: cppcheck static analysis on all apps
echo "--- Static Analysis (cppcheck) ---"
for app_dir in "$SCRIPT_DIR"/*/; do
app=$(basename "$app_dir")
src="$app_dir/src/main.c"
# Skip non-app directories
[ ! -f "$src" ] && continue
output=$(cppcheck --enable=warning,performance,portability \
--suppress=missingIncludeSystem \
--suppress=missingInclude \
--suppress=unusedFunction \
--suppress=checkersReport \
--suppress=constParameterCallback \
--suppress=constParameterPointer \
--suppress=normalCheckLevelMaxBranches \
--suppress=unmatchedSuppression \
--error-exitcode=1 \
"$src" 2>&1)
if [ $? -eq 0 ]; then
echo -e " ${GREEN}PASS${NC} $app"
PASS=$((PASS + 1))
else
echo -e " ${RED}FAIL${NC} $app"
ERRORS="$ERRORS\n--- $app ---\n$output"
FAIL=$((FAIL + 1))
fi
done
echo ""
# Test 2: Verify project structure
echo "--- Project Structure ---"
for app_dir in "$SCRIPT_DIR"/*/; do
app=$(basename "$app_dir")
[ ! -f "$app_dir/src/main.c" ] && continue
missing=""
[ ! -f "$app_dir/package.json" ] && missing="$missing package.json"
[ ! -f "$app_dir/wscript" ] && missing="$missing wscript"
[ ! -f "$app_dir/CLAUDE.md" ] && missing="$missing CLAUDE.md"
[ ! -f "$app_dir/src/main.c" ] && missing="$missing src/main.c"
if [ -z "$missing" ]; then
echo -e " ${GREEN}PASS${NC} $app — all files present"
PASS=$((PASS + 1))
else
echo -e " ${RED}FAIL${NC} $app — missing:$missing"
FAIL=$((FAIL + 1))
fi
done
echo ""
# Test 3: Verify package.json has correct target platforms
echo "--- Platform Targeting ---"
for app_dir in "$SCRIPT_DIR"/*/; do
app=$(basename "$app_dir")
pkg="$app_dir/package.json"
[ ! -f "$pkg" ] && continue
has_diorite=$(grep -c '"diorite"' "$pkg" || true)
has_basalt=$(grep -c '"basalt"' "$pkg" || true)
has_emery=$(grep -c '"emery"' "$pkg" || true)
if [ "$has_diorite" -ge 1 ] && [ "$has_basalt" -ge 1 ] && [ "$has_emery" -ge 1 ]; then
echo -e " ${GREEN}PASS${NC} $app — targets diorite, basalt, emery"
PASS=$((PASS + 1))
else
echo -e " ${RED}FAIL${NC} $app — missing platform targets"
FAIL=$((FAIL + 1))
fi
done
echo ""
# Test 4: Check for common C issues
echo "--- Code Quality Checks ---"
for app_dir in "$SCRIPT_DIR"/*/; do
app=$(basename "$app_dir")
src="$app_dir/src/main.c"
[ ! -f "$src" ] && continue
issues=""
# Check that every _create has a matching _destroy
creates=$(grep -co '_create(' "$src" || true)
destroys=$(grep -co '_destroy(' "$src" || true)
if [ "$creates" -ne "$destroys" ]; then
issues="$issues create/destroy mismatch($creates/$destroys)"
fi
# Check for main() entry point
has_main=$(grep -c 'int main(void)' "$src" || true)
if [ "$has_main" -lt 1 ]; then
issues="$issues missing-main"
fi
# Check for app_event_loop
has_loop=$(grep -c 'app_event_loop()' "$src" || true)
if [ "$has_loop" -lt 1 ]; then
issues="$issues missing-app_event_loop"
fi
if [ -z "$issues" ]; then
echo -e " ${GREEN}PASS${NC} $app"
PASS=$((PASS + 1))
else
echo -e " ${YELLOW}WARN${NC} $app —$issues"
# Warnings don't count as failures
PASS=$((PASS + 1))
fi
done
echo ""
# Test 5: SDK build test (only if pebble CLI is available)
if command -v pebble &> /dev/null; then
echo "--- SDK Build Test ---"
for app_dir in "$SCRIPT_DIR"/*/; do
app=$(basename "$app_dir")
[ ! -f "$app_dir/src/main.c" ] && continue
cd "$app_dir"
if pebble build 2>&1 | grep -q "finished successfully"; then
echo -e " ${GREEN}PASS${NC} $app — build succeeded"
PASS=$((PASS + 1))
else
echo -e " ${RED}FAIL${NC} $app — build failed"
FAIL=$((FAIL + 1))
fi
cd "$SCRIPT_DIR"
done
echo ""
else
echo -e "${YELLOW}SKIP${NC} SDK build tests (pebble CLI not installed)"
echo " Install with: uv tool install pebble-tool --python 3.13"
echo ""
fi
# Summary
echo "======================================"
echo -e " Results: ${GREEN}$PASS passed${NC}, ${RED}$FAIL failed${NC}"
echo "======================================"
if [ -n "$ERRORS" ]; then
echo ""
echo "--- Error Details ---"
echo -e "$ERRORS"
fi
exit $FAIL