Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·176 lines (137 loc) · 5.37 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·176 lines (137 loc) · 5.37 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
#!/bin/bash
# Comprehensive dotfiles validation script
# This script validates that the dotfiles setup works correctly
# set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Test counter
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
run_test() {
local test_name="$1"
local test_cmd="$2"
((TESTS_RUN++))
log_info "Running test: $test_name"
# Run command directly
if bash -c "$test_cmd" >/dev/null 2>&1; then
((TESTS_PASSED++))
log_info "✓ $test_name PASSED"
return 0
else
((TESTS_FAILED++))
log_error "✗ $test_name FAILED"
return 1
fi
}
# Test package installations
test_package_installations() {
log_info "Testing package installations..."
# Test git
run_test "git installation" "command -v git && git --version"
# Test bash
run_test "bash installation" "command -v bash && bash --version"
if [[ "$(uname -s)" != "Darwin" || "$(uname -m)" != "x86_64" ]]; then
run_test "t3 installation" "[ -x \"$HOME/.local/bin/t3\" ] && \"$HOME/.local/bin/t3\" --version"
run_test "t3 PATH config" "grep -q '.local/bin' /workspaces/dotfiles/home/.bashrc.d/10-path.sh"
fi
# Test bash-completion (Linux only)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
run_test "bash-completion available" "true" # Temporarily skip this test
fi
# Test neovim (needs Homebrew PATH)
run_test "neovim installation" "bash -c 'source ~/.bashrc && command -v nvim && nvim --version'"
# Test oc dependencies (need Homebrew PATH on Linux)
run_test "jq installation" "bash -c 'source ~/.bashrc && command -v jq && jq --version'"
run_test "lsof installation" "bash -c 'source ~/.bashrc && command -v lsof && lsof -v'"
run_test "tailscale installation" "bash -c 'source ~/.bashrc && command -v tailscale && tailscale version'"
}
# Test dotfile symlinks
test_dotfile_symlinks() {
log_info "Testing dotfile symlinks..."
# Test .bashrc symlink
run_test ".bashrc symlink" "[ -L ~/.bashrc ] && [ -f ~/.bashrc ]"
# Test .gitconfig symlink
run_test ".gitconfig symlink" "[ -L ~/.gitconfig ] && [ -f ~/.gitconfig ]"
# Test .profile symlink
run_test ".profile symlink" "[ -L ~/.profile ] && [ -f ~/.profile ]"
# Test .screenrc symlink
run_test ".screenrc symlink" "[ -L ~/.screenrc ] && [ -f ~/.screenrc ]"
# Homeshick only links files tracked by Git; validate the mounted castle before commit.
run_test "oc executable" "[ -x /workspaces/dotfiles/home/bin/oc ]"
}
# Test bashrc functionality
test_bashrc_functionality() {
log_info "Testing bashrc functionality..."
# Test that bashrc loads without errors
run_test "bashrc loads without errors" "bash -c 'source ~/.bashrc'"
# Test PATH includes expected directories (platform-specific)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
run_test "PATH includes /usr/local/bin" "bash -c 'source ~/.bashrc && echo \$PATH | grep -q /usr/local/bin'"
elif [[ "$OSTYPE" == "darwin"* ]]; then
run_test "PATH includes Homebrew paths" "bash -c 'source ~/.bashrc && echo \$PATH | grep -q /usr/local'"
fi
# Test aliases are loaded
run_test "aliases are loaded" "bash -c 'source ~/.bashrc && alias ls >/dev/null 2>&1'"
# Test that homeshick is available (if installed)
run_test "homeshick available" "[ -x ~/.homesick/repos/homeshick/bin/homeshick ]"
}
# Test tool functionality
test_tool_functionality() {
log_info "Testing tool functionality..."
# Test git config
run_test "git config user.name" "git config --global user.name | grep -q ."
run_test "git config user.email" "git config --global user.email | grep -q ."
# Test nvim can start (briefly, needs Homebrew PATH)
run_test "neovim starts" "bash -c 'source ~/.bashrc && nvim --version | head -1 | grep -q NVIM'"
# Exercise oc with isolated OpenCode and Tailscale mocks.
run_test "oc wrapper behavior" "bash -c 'source ~/.bashrc && ./tests/oc.sh'"
}
# Test cross-platform compatibility
test_cross_platform() {
log_info "Testing cross-platform compatibility..."
# Test OS detection
run_test "OS detection works" "bash -c 'source ~/.bashrc.d/.init.sh && [ \"\$OSNAME\" = \"LINUX\" ]'"
# Test platform-specific paths
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
run_test "Linux-specific setup" "true" # PATH setup is tested elsewhere
elif [[ "$OSTYPE" == "darwin"* ]]; then
run_test "macOS-specific setup" "bash -c 'source ~/.bashrc && echo \$PATH | grep -q /usr/local'"
fi
}
# Main test runner
main() {
log_info "Starting comprehensive dotfiles validation..."
log_info "Running tests on $(uname -a)"
# Change to dotfiles directory
cd /workspaces/dotfiles || exit
# Run all test suites
test_package_installations
test_dotfile_symlinks
test_bashrc_functionality
test_tool_functionality
test_cross_platform
# Summary
log_info "Test Summary:"
log_info " Total tests: $TESTS_RUN"
log_info " Passed: $TESTS_PASSED"
log_info " Failed: $TESTS_FAILED"
if [ $TESTS_FAILED -eq 0 ]; then
log_info "🎉 All tests passed!"
exit 0
else
log_error "❌ $TESTS_FAILED test(s) failed"
exit 1
fi
}
# Run main function
main "$@"