-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·178 lines (159 loc) · 5.03 KB
/
test.sh
File metadata and controls
executable file
·178 lines (159 loc) · 5.03 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
#!/usr/bin/env bash
# testall.sh — Run all sql5 tests
# 一個指令測試全部
set -uo pipefail
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
BINARY="$PROJECT_DIR/target/release/sql5"
# 顏色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
RESET='\033[0m'
echo ""
echo "=============================================="
echo -e "${BLUE}sql5 全端測試 ${RESET}(全部測試)"
echo "=============================================="
echo ""
# ============================================
# 1. Build Rust binary
# ============================================
echo -e "${BLUE}[1/6] Building Rust binary...${RESET}"
echo " Building release binary..."
cd "$PROJECT_DIR" && cargo build --release
if [[ ! -x "$BINARY" ]]; then
echo -e "${RED}ERROR: Build failed${RESET}"
exit 1
fi
echo -e " ${GREEN}Binary: $BINARY${RESET}"
echo ""
# ============================================
# 2. Rust unit tests (cargo test)
# ============================================
echo -e "${BLUE}[2/5] Running Rust unit tests...${RESET}"
echo ""
cd "$PROJECT_DIR"
cargo test 2>&1 | tail -30
CARGO_STATUS=$?
echo ""
if [[ $CARGO_STATUS -eq 0 ]]; then
echo -e " ${GREEN}Rust unit tests: PASSED${RESET}"
else
echo -e " ${RED}Rust unit tests: FAILED${RESET}"
fi
echo ""
# ============================================
# 3. CLI integration tests (shtest.sh)
# ============================================
echo -e "${BLUE}[3/6] Running CLI integration tests...${RESET}"
echo ""
cd "$PROJECT_DIR"
SHTEST_OUTPUT=$(./shtest.sh "$BINARY" 2>&1)
echo "$SHTEST_OUTPUT" | tail -30
FAIL_COUNT=$(echo "$SHTEST_OUTPUT" | grep -c "^FAIL" || echo "0")
CLI_STATUS=0
if [[ $FAIL_COUNT -gt 0 ]]; then
CLI_STATUS=1
elif echo "$SHTEST_OUTPUT" | grep -q "[1-9] failed"; then
CLI_STATUS=1
fi
echo ""
if [[ $CLI_STATUS -eq 0 ]]; then
echo -e " ${GREEN}CLI integration tests: PASSED${RESET}"
else
echo -e " ${YELLOW}CLI integration tests: some failures${RESET}"
fi
echo ""
# ============================================
# 4. Python pytest tests (all files in tests/)
# ============================================
echo -e "${BLUE}[4/5] Running Python pytest tests...${RESET}"
echo ""
export SQL5_BINARY="$BINARY"
cd "$PROJECT_DIR/sql5_pypi"
export PYTHONPATH="${PWD}:${PYTHONPATH:-}"
uv run pytest tests/ -v 2>&1 | tail -30
PYTEST_STATUS=$?
echo ""
if [[ $PYTEST_STATUS -eq 0 ]]; then
echo -e " ${GREEN}Python pytest tests: PASSED${RESET}"
else
echo -e " ${RED}Python pytest tests: FAILED${RESET}"
fi
echo ""
# ============================================
# 5. Python client integration test (sql5test.py)
# ============================================
echo -e "${BLUE}[5/6] Running Python client test...${RESET}"
echo ""
cd "$PROJECT_DIR/sql5_pypi/examples"
rm -f mydb.db
uv run python sql5test.py 2>&1
PYCLIENT_STATUS=$?
echo ""
if [[ $PYCLIENT_STATUS -eq 0 ]]; then
echo -e " ${GREEN}Python client test (subprocess): PASSED${RESET}"
else
echo -e " ${RED}Python client test (subprocess): FAILED${RESET}"
fi
rm -f mydb.db
echo ""
# ============================================
# 6. WebSocket test (v3.0 new)
# ============================================
echo -e "${BLUE}[6/6] Running WebSocket test...${RESET}"
echo ""
cd "$PROJECT_DIR/sql5_pypi/examples"
rm -f ws_test.db ws_test.db-wal ws_test.db-shm 2>/dev/null
export SQL5_BINARY="$BINARY"
uv run python websocket_test.py 2>&1
WEBSOCKET_STATUS=$?
echo ""
if [[ $WEBSOCKET_STATUS -eq 0 ]]; then
echo -e " ${GREEN}WebSocket test: PASSED${RESET}"
else
echo -e " ${RED}WebSocket test: FAILED${RESET}"
fi
rm -f ws_test.db ws_test.db-wal ws_test.db-shm 2>/dev/null
echo ""
# ============================================
# Summary
# ============================================
echo "=============================================="
echo -e "${BLUE}測試結果總覽${RESET}"
echo "=============================================="
if [[ $CARGO_STATUS -eq 0 ]]; then
echo -e " ${GREEN}[PASS]${RESET} Rust unit tests (cargo test)"
else
echo -e " ${RED}[FAIL]${RESET} Rust unit tests (cargo test)"
fi
if [[ $CLI_STATUS -eq 0 ]]; then
echo -e " ${GREEN}[PASS]${RESET} CLI integration tests (shtest.sh)"
else
echo -e " ${YELLOW}[PARTIAL]${RESET} CLI integration tests (shtest.sh)"
fi
if [[ $PYTEST_STATUS -eq 0 ]]; then
echo -e " ${GREEN}[PASS]${RESET} Python pytest tests"
else
echo -e " ${RED}[FAIL]${RESET} Python pytest tests"
fi
if [[ $PYCLIENT_STATUS -eq 0 ]]; then
echo -e " ${GREEN}[PASS]${RESET} Python client test (subprocess)"
else
echo -e " ${RED}[FAIL]${RESET} Python client test (subprocess)"
fi
if [[ $WEBSOCKET_STATUS -eq 0 ]]; then
echo -e " ${GREEN}[PASS]${RESET} WebSocket test (v3.0)"
else
echo -e " ${RED}[FAIL]${RESET} WebSocket test (v3.0)"
fi
echo ""
echo "=============================================="
echo "測試完成!"
echo "=============================================="
echo ""
# Exit with failure if any test failed
if [[ $CARGO_STATUS -ne 0 ]] || [[ $PYTEST_STATUS -ne 0 ]] || [[ $PYCLIENT_STATUS -ne 0 ]] || [[ $WEBSOCKET_STATUS -ne 0 ]]; then
exit 1
fi
exit 0