-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·213 lines (187 loc) · 6 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·213 lines (187 loc) · 6 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
#!/usr/bin/env bash
# Main test runner for dotfiles repository
# Runs all test suites or specific tests based on arguments
set -euo pipefail
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TESTS_DIR="$SCRIPT_DIR/tests"
# Test categories
declare -A TEST_SUITES=(
["bootstrap"]="$TESTS_DIR/test-bootstrap.sh"
["configs"]="$TESTS_DIR/test-configs.sh"
["scripts"]="$TESTS_DIR/test-scripts.sh"
["mcp"]="$TESTS_DIR/test-mcp.sh"
)
# Track results
SUITES_RUN=0
SUITES_PASSED=0
SUITES_FAILED=0
declare -a FAILED_SUITES
# Print usage
usage() {
echo "Usage: $0 [OPTIONS] [TEST_SUITE...]"
echo ""
echo "Run dotfiles test suites"
echo ""
echo "Test Suites:"
echo " bootstrap Test bootstrap and installation scripts"
echo " configs Test configuration file validity"
echo " scripts Test utility scripts"
echo " mcp Test MCP server installations"
echo " all Run all test suites (default)"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -v, --verbose Enable verbose output"
echo " -q, --quiet Minimal output (only failures)"
echo " -l, --list List available test suites"
echo ""
echo "Examples:"
echo " $0 # Run all tests"
echo " $0 bootstrap # Run only bootstrap tests"
echo " $0 configs scripts # Run configs and scripts tests"
echo " $0 -v all # Run all tests with verbose output"
}
# List available test suites
list_suites() {
echo "Available test suites:"
echo ""
for suite in "${!TEST_SUITES[@]}"; do
test_file="${TEST_SUITES[$suite]}"
if [[ -f "$test_file" ]]; then
echo -e " ${GREEN}✓${NC} $suite"
else
echo -e " ${RED}✗${NC} $suite (file missing)"
fi
done
}
# Run a single test suite
run_suite() {
local suite_name="$1"
local test_file="${TEST_SUITES[$suite_name]}"
SUITES_RUN=$((SUITES_RUN + 1))
echo ""
echo -e "${BOLD}╔════════════════════════════════════════╗${NC}"
echo -e "${BOLD}║ Running: $(printf "%-28s" "$suite_name") ║${NC}"
echo -e "${BOLD}╚════════════════════════════════════════╝${NC}"
echo ""
if [[ ! -f "$test_file" ]]; then
echo -e "${RED}Error: Test file not found: $test_file${NC}"
((SUITES_FAILED++))
FAILED_SUITES+=("$suite_name")
return 1
fi
if [[ ! -x "$test_file" ]]; then
echo -e "${YELLOW}Warning: Test file not executable, making it executable${NC}"
chmod +x "$test_file"
fi
if "$test_file"; then
SUITES_PASSED=$((SUITES_PASSED + 1))
return 0
else
SUITES_FAILED=$((SUITES_FAILED + 1))
FAILED_SUITES+=("$suite_name")
return 1
fi
}
# Print final summary
print_summary() {
echo ""
echo ""
echo -e "${BOLD}╔════════════════════════════════════════╗${NC}"
echo -e "${BOLD}║ OVERALL TEST SUMMARY ║${NC}"
echo -e "${BOLD}╚════════════════════════════════════════╝${NC}"
echo ""
echo -e "Total test suites: $SUITES_RUN"
echo -e "${GREEN}Passed suites: $SUITES_PASSED${NC}"
if [[ $SUITES_FAILED -gt 0 ]]; then
echo -e "${RED}Failed suites: $SUITES_FAILED${NC}"
echo ""
echo -e "${RED}Failed suites:${NC}"
for suite in "${FAILED_SUITES[@]}"; do
echo -e " ${RED}✗${NC} $suite"
done
else
echo -e "Failed suites: $SUITES_FAILED"
fi
echo ""
if [[ $SUITES_FAILED -eq 0 ]]; then
echo -e "${GREEN}${BOLD}🎉 All test suites passed!${NC}"
return 0
else
echo -e "${RED}${BOLD}❌ Some test suites failed!${NC}"
return 1
fi
}
# Main execution
main() {
local verbose=false
local quiet=false
local run_all=true
declare -a suites_to_run
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--verbose)
verbose=true
shift
;;
-q|--quiet)
quiet=true
shift
;;
-l|--list)
list_suites
exit 0
;;
all)
run_all=true
shift
;;
bootstrap|configs|scripts|mcp)
run_all=false
suites_to_run+=("$1")
shift
;;
*)
echo -e "${RED}Error: Unknown argument: $1${NC}"
echo ""
usage
exit 1
;;
esac
done
# Print header
echo -e "${BLUE}${BOLD}"
echo "╔═══════════════════════════════════════════╗"
echo "║ Dotfiles Repository Test Runner ║"
echo "╚═══════════════════════════════════════════╝"
echo -e "${NC}"
# Determine which suites to run
if $run_all || [[ ${#suites_to_run[@]} -eq 0 ]]; then
suites_to_run=("${!TEST_SUITES[@]}")
fi
# Sort suites for consistent ordering
IFS=$'\n' sorted_suites=($(sort <<<"${suites_to_run[*]}"))
unset IFS
# Run test suites
for suite in "${sorted_suites[@]}"; do
run_suite "$suite" || true
done
# Print summary
print_summary
exit $?
}
# Run main
main "$@"