mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 22:04:43 +00:00
Performance and speed optimization
This commit is contained in:
@@ -69,7 +69,7 @@ TOTAL_CHECKS=0
|
||||
|
||||
# Check 1: Keyboard input handling (restored to 1s for reliability)
|
||||
((TOTAL_CHECKS++))
|
||||
if grep -q "read -r -s -n 1 -t 1" lib/core/common.sh; then
|
||||
if grep -q "read -r -s -n 1 -t 1" lib/core/ui.sh; then
|
||||
echo -e "${GREEN} ✓ Keyboard timeout properly configured (1s)${NC}"
|
||||
((OPTIMIZATION_SCORE++))
|
||||
else
|
||||
@@ -78,7 +78,8 @@ fi
|
||||
|
||||
# Check 2: Single-pass drain_pending_input
|
||||
((TOTAL_CHECKS++))
|
||||
DRAIN_PASSES=$(grep -c "while IFS= read -r -s -n 1" lib/core/common.sh || echo 0)
|
||||
DRAIN_PASSES=$(grep -c "while IFS= read -r -s -n 1" lib/core/ui.sh 2> /dev/null || true)
|
||||
DRAIN_PASSES=${DRAIN_PASSES:-0}
|
||||
if [[ $DRAIN_PASSES -eq 1 ]]; then
|
||||
echo -e "${GREEN} ✓ drain_pending_input optimized (single-pass)${NC}"
|
||||
((OPTIMIZATION_SCORE++))
|
||||
@@ -88,7 +89,7 @@ fi
|
||||
|
||||
# Check 3: Log rotation once per session
|
||||
((TOTAL_CHECKS++))
|
||||
if grep -q "rotate_log_once" lib/core/common.sh && ! grep "rotate_log()" lib/core/common.sh | grep -v "rotate_log_once" > /dev/null 2>&1; then
|
||||
if grep -q "rotate_log_once" lib/core/log.sh; then
|
||||
echo -e "${GREEN} ✓ Log rotation optimized (once per session)${NC}"
|
||||
((OPTIMIZATION_SCORE++))
|
||||
else
|
||||
|
||||
112
scripts/run-tests.sh
Executable file
112
scripts/run-tests.sh
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
# Quick test runner script
|
||||
# Runs all tests before committing
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR/.."
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo "================================"
|
||||
echo " Mole Test Runner"
|
||||
echo "================================"
|
||||
echo ""
|
||||
|
||||
# Track failures
|
||||
FAILED=0
|
||||
|
||||
# 1. ShellCheck
|
||||
echo "1. Running ShellCheck..."
|
||||
if command -v shellcheck > /dev/null 2>&1; then
|
||||
if shellcheck mole bin/*.sh 2> /dev/null &&
|
||||
find lib -name "*.sh" -type f -exec shellcheck {} + 2> /dev/null; then
|
||||
echo -e "${GREEN}✓ ShellCheck passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ ShellCheck failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠ ShellCheck not installed, skipping${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 2. Syntax Check
|
||||
echo "2. Running syntax check..."
|
||||
if bash -n mole &&
|
||||
bash -n bin/*.sh 2> /dev/null &&
|
||||
find lib -name "*.sh" -type f -exec bash -n {} \; 2> /dev/null; then
|
||||
echo -e "${GREEN}✓ Syntax check passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Syntax check failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 3. Unit Tests
|
||||
echo "3. Running unit tests..."
|
||||
if command -v bats > /dev/null 2>&1; then
|
||||
if bats tests/*.bats; then
|
||||
echo -e "${GREEN}✓ Unit tests passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Unit tests failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Bats not installed, skipping unit tests${NC}"
|
||||
echo " Install with: brew install bats-core"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 4. Go Tests
|
||||
echo "4. Running Go tests..."
|
||||
if command -v go > /dev/null 2>&1; then
|
||||
if go build ./... && go vet ./cmd/...; then
|
||||
echo -e "${GREEN}✓ Go tests passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Go tests failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Go not installed, skipping Go tests${NC}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 5. Module Loading Test
|
||||
echo "5. Testing module loading..."
|
||||
if bash -c 'source lib/core/common.sh && echo "OK"' > /dev/null 2>&1; then
|
||||
echo -e "${GREEN}✓ Module loading passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Module loading failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# 6. Integration Tests
|
||||
echo "6. Running integration tests..."
|
||||
if ./bin/clean.sh --dry-run > /dev/null 2>&1; then
|
||||
echo -e "${GREEN}✓ Clean dry-run passed${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Clean dry-run failed${NC}"
|
||||
((FAILED++))
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Summary
|
||||
echo "================================"
|
||||
if [[ $FAILED -eq 0 ]]; then
|
||||
echo -e "${GREEN}All tests passed!${NC}"
|
||||
echo ""
|
||||
echo "You can now commit your changes."
|
||||
exit 0
|
||||
else
|
||||
echo -e "${RED}$FAILED test(s) failed!${NC}"
|
||||
echo ""
|
||||
echo "Please fix the failing tests before committing."
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user