blob: 112796aaabc454766d7191c994b87bbb8e9bca47 (
plain)
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
# Quick Prompt Test - Fast validation
# Simple test for immediate feedback
# shellcheck disable=SC1090,SC2034,SC2155
set -e
# Logging
log_info() { echo "[INFO] $*"; }
log_error() { echo "[ERROR] $*"; }
log_success() { echo "[SUCCESS] $*"; }
# Configuration
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Basic colors fallback
setup_colors() {
RESET='\033[0m'
BOLD='\033[1m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
CYAN='\033[36m'
WHITE='\033[37m'
GREY='\033[90m'
}
# Load functions
load_functions() {
log_info "Loading HyperTerm functions"
# Load colors if available
local colors_file="$PROJECT_ROOT/hyperterm/core/colors.sh"
if [[ -f "$colors_file" ]]; then
source "$colors_file"
else
setup_colors
fi
# Load git functions
local git_file="$PROJECT_ROOT/hyperterm/core/git.sh"
if [[ -f "$git_file" ]]; then
source "$git_file"
log_success "Git functions loaded"
return 0
else
log_error "Git functions not found"
return 1
fi
}
# Test in current directory
test_current_directory() {
if git rev-parse --git-dir >/dev/null 2>&1; then
log_success "Current directory is a git repository"
echo "Current git state:"
echo -n " Branch: "
_get_git_branch
echo ""
echo -n " Status: "
if command -v _get_git_status_fast >/dev/null 2>&1; then
_get_git_status_fast
else
_prompt_get_git_status
fi
echo ""
echo -n " Full prompt: "
__prompt_git
echo ""
return 0
else
log_info "Current directory is not a git repository"
return 1
fi
}
# Create temporary test
test_with_temp_repo() {
log_info "Creating temporary git repository for testing"
local temp_dir="/tmp/quick_test_$$"
mkdir -p "$temp_dir"
(
cd "$temp_dir"
git init --quiet
git config user.name "Test User"
git config user.email "test@example.com"
echo "# Quick Test" > README.md
echo "test content" > file.txt
git add README.md
git commit -m "Initial commit" --quiet
# Create changes
echo "modified" >> file.txt
echo "untracked" > new.txt
log_success "Temporary repository created with changes"
echo "Test results:"
echo -n " Branch: "
_get_git_branch
echo ""
echo -n " Status: "
if command -v _get_git_status_fast >/dev/null 2>&1; then
_get_git_status_fast
else
_prompt_get_git_status
fi
echo ""
echo -n " Full prompt: "
__prompt_git
echo ""
)
rm -rf "$temp_dir"
log_info "Temporary repository cleaned up"
}
# Performance check
quick_performance_check() {
log_info "Running quick performance check"
local iterations=10
local start_time end_time duration
start_time=$(date +%s%N)
for ((i=1; i<=iterations; i++)); do
__prompt_git >/dev/null 2>&1
done
end_time=$(date +%s%N)
duration=$(( (end_time - start_time) / 1000000 ))
local avg_duration=$(( duration / iterations ))
echo "Performance: ${avg_duration}ms average (${iterations} iterations)"
if [[ $avg_duration -lt 50 ]]; then
log_success "Performance is good"
elif [[ $avg_duration -lt 100 ]]; then
log_info "Performance is acceptable"
else
log_error "Performance may need optimization"
fi
}
# Main execution
main() {
log_info "HyperTerm Quick Test"
if ! load_functions; then
exit 1
fi
if ! test_current_directory; then
test_with_temp_repo
fi
quick_performance_check
log_success "Quick test completed"
}
# Execute if run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
|