Optimized git
Some checks failed
Some checks failed
This commit is contained in:
176
tests/quick_test.sh
Normal file
176
tests/quick_test.sh
Normal file
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user