-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-all.sh
More file actions
executable file
·183 lines (154 loc) · 4.31 KB
/
test-all.sh
File metadata and controls
executable file
·183 lines (154 loc) · 4.31 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
#!/bin/bash
# Test script for all LiveTemplate examples
# Usage: ./test-all.sh [--skip-disabled]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Change to script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Use local go.work when present (dev mode with local module overrides),
# otherwise disable workspace to force published module versions.
if [[ -f "$SCRIPT_DIR/go.work" ]]; then
export GOWORK="$SCRIPT_DIR/go.work"
else
export GOWORK=off
fi
# Track results
declare -a PASSED=()
declare -a FAILED=()
declare -a SKIPPED=()
# Working examples
WORKING_EXAMPLES=(
"counter"
"chat"
"todos"
"live-preview"
"ws-disabled"
"login"
"shared-notepad"
"flash-messages"
"avatar-upload"
"progressive-enhancement"
"dialog-patterns"
"patterns"
)
# Disabled examples
DISABLED_EXAMPLES=(
)
echo "================================================"
echo " LiveTemplate Examples Test Suite"
echo "================================================"
echo ""
# Parse arguments
SKIP_DISABLED=false
if [[ "$1" == "--skip-disabled" ]]; then
SKIP_DISABLED=true
fi
# Download dependencies once at the root
echo "Downloading dependencies..."
echo "----------------------------------------"
go mod download
echo ""
# Test a single example
test_example() {
local example=$1
local is_disabled=$2
echo "Testing: $example"
echo "----------------------------------------"
if [[ ! -d "$example" ]]; then
echo -e "${RED}✗ Directory not found: $example${NC}"
FAILED+=("$example")
return 1
fi
# Change to example directory (tests expect to run from their directory)
cd "$example"
# Build
echo " → Building..."
if ! go build -v ./... 2>&1 | sed 's/^/ /'; then
echo -e "${RED}✗ Build failed${NC}"
cd "$SCRIPT_DIR"
FAILED+=("$example")
return 1
fi
# Skip tests for disabled examples unless explicitly requested
if [[ "$is_disabled" == "true" ]] && [[ "$SKIP_DISABLED" == "true" ]]; then
echo -e "${YELLOW}⊘ Tests skipped (disabled example)${NC}"
cd "$SCRIPT_DIR"
SKIPPED+=("$example")
return 0
fi
# Run tests from example directory (tests use relative paths like "main.go")
echo " → Running tests..."
set +e # Temporarily disable exit on error
(set -o pipefail; go test -v -race -timeout=5m ./... 2>&1 | sed 's/^/ /')
local test_exit=$?
set -e # Re-enable exit on error
# Return to script directory
cd "$SCRIPT_DIR"
if [ $test_exit -eq 0 ]; then
echo -e "${GREEN}✓ All tests passed${NC}"
PASSED+=("$example")
return 0
else
echo -e "${RED}✗ Tests failed${NC}"
FAILED+=("$example")
return 1
fi
}
# Test all working examples
echo ""
echo "Testing working examples..."
echo "================================================"
echo ""
for example in "${WORKING_EXAMPLES[@]}"; do
test_example "$example" "false"
echo ""
done
# Test disabled examples
if [[ "$SKIP_DISABLED" == "false" ]]; then
echo ""
echo "Testing disabled examples (require internal/observe)..."
echo "================================================"
echo ""
for example in "${DISABLED_EXAMPLES[@]}"; do
test_example "$example" "true"
echo ""
done
fi
# Print summary
echo ""
echo "================================================"
echo " Test Summary"
echo "================================================"
echo ""
if [ ${#PASSED[@]} -gt 0 ]; then
echo -e "${GREEN}✓ Passed (${#PASSED[@]}):${NC}"
for example in "${PASSED[@]}"; do
echo " - $example"
done
echo ""
fi
if [ ${#SKIPPED[@]} -gt 0 ]; then
echo -e "${YELLOW}⊘ Skipped (${#SKIPPED[@]}):${NC}"
for example in "${SKIPPED[@]}"; do
echo " - $example"
done
echo ""
fi
if [ ${#FAILED[@]} -gt 0 ]; then
echo -e "${RED}✗ Failed (${#FAILED[@]}):${NC}"
for example in "${FAILED[@]}"; do
echo " - $example"
done
echo ""
echo "================================================"
exit 1
fi
echo "================================================"
echo -e "${GREEN}All tests passed!${NC}"
echo "================================================"
exit 0