001project_wildgrowth/ios/test-regression.sh

277 lines
7.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 回归测试脚本
# 用途:每次大规模代码移除后,自动运行回归测试,确保流程通畅
# 使用方法:./test-regression.sh
set -e # 遇到错误立即退出
echo "🧪 ========================================"
echo "🧪 开始回归测试"
echo "🧪 ========================================"
echo ""
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 测试结果统计
PASSED=0
FAILED=0
SKIPPED=0
# 测试函数
test_check() {
local test_name="$1"
local command="$2"
echo -n "$test_name... "
if eval "$command" > /dev/null 2>&1; then
echo -e "${GREEN}✅ 通过${NC}"
((PASSED++))
return 0
else
echo -e "${RED}❌ 失败${NC}"
((FAILED++))
return 1
fi
}
test_check_with_output() {
local test_name="$1"
local command="$2"
echo "$test_name..."
echo " 执行: $command"
if eval "$command" 2>&1; then
echo -e " ${GREEN}✅ 通过${NC}"
((PASSED++))
return 0
else
echo -e " ${RED}❌ 失败${NC}"
((FAILED++))
return 1
fi
}
# ========================================
# 1. 编译检查
# ========================================
echo "📦 阶段 1: 编译检查"
echo "----------------------------------------"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# 检查是否在 iOS 项目目录
if [ ! -d "$PROJECT_ROOT/ios/WildGrowth" ]; then
echo -e "${RED}❌ 错误: 未找到 iOS 项目目录${NC}"
exit 1
fi
cd "$PROJECT_ROOT/ios/WildGrowth"
# 检查 Xcode 项目文件
if [ ! -f "WildGrowth.xcodeproj/project.pbxproj" ]; then
echo -e "${YELLOW}⚠️ 警告: 未找到 Xcode 项目文件,跳过编译检查${NC}"
SKIPPED=$((SKIPPED + 1))
else
# 尝试编译(如果 xcodebuild 可用)
if command -v xcodebuild &> /dev/null; then
echo " ⏳ 编译项目..."
if xcodebuild -project WildGrowth.xcodeproj -scheme WildGrowth -destination 'platform=iOS Simulator,name=iPhone 15' clean build > /tmp/xcode_build.log 2>&1; then
echo -e " ${GREEN}✅ 编译成功${NC}"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌ 编译失败${NC}"
echo " 查看日志: tail -50 /tmp/xcode_build.log"
FAILED=$((FAILED + 1))
fi
else
echo -e " ${YELLOW}⚠️ xcodebuild 不可用,跳过编译检查${NC}"
SKIPPED=$((SKIPPED + 1))
fi
fi
echo ""
# ========================================
# 2. 文件存在性检查
# ========================================
echo "📁 阶段 2: 文件存在性检查"
echo "----------------------------------------"
cd "$PROJECT_ROOT/ios/WildGrowth/WildGrowth"
# 检查应该存在的文件
REQUIRED_FILES=(
"VerticalScreenPlayerView.swift"
"MapView.swift"
"HomeView.swift"
"Views/GrowthView.swift"
"ProfileView.swift"
"CourseModels.swift"
)
for file in "${REQUIRED_FILES[@]}"; do
if [ -f "$file" ]; then
echo -e " ${GREEN}$file 存在${NC}"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}$file 不存在${NC}"
FAILED=$((FAILED + 1))
fi
done
echo ""
# 检查应该删除的文件(不应该存在)
DELETED_FILES=(
"SummaryView.swift"
"GuestSummaryView.swift"
"FlatNodeButton.swift"
"ThreeDButton.swift"
"LessonPlayerView.swift"
"SlideImageView.swift"
)
for file in "${DELETED_FILES[@]}"; do
if [ -f "$file" ]; then
echo -e " ${YELLOW}⚠️ $file 仍然存在(应该已删除)${NC}"
SKIPPED=$((SKIPPED + 1))
else
echo -e " ${GREEN}$file 已删除${NC}"
PASSED=$((PASSED + 1))
fi
done
echo ""
# ========================================
# 3. 代码引用检查
# ========================================
echo "🔍 阶段 3: 代码引用检查"
echo "----------------------------------------"
cd "$PROJECT_ROOT/ios/WildGrowth/WildGrowth"
# 检查是否还有对已删除组件的引用
check_no_reference() {
local component="$1"
local pattern="$2"
echo -n " ⏳ 检查 $component 引用... "
if grep -r "$pattern" . --include="*.swift" > /dev/null 2>&1; then
echo -e "${RED}❌ 发现引用${NC}"
echo " 引用位置:"
grep -rn "$pattern" . --include="*.swift" | head -5 | sed 's/^/ /'
FAILED=$((FAILED + 1))
return 1
else
echo -e "${GREEN}✅ 无引用${NC}"
PASSED=$((PASSED + 1))
return 0
fi
}
# 检查已删除组件的引用
check_no_reference "SummaryView" "SummaryView"
check_no_reference "GuestSummaryView" "GuestSummaryView"
check_no_reference "FlatNodeButton" "FlatNodeButton"
check_no_reference "ThreeDButton" "ThreeDButton"
check_no_reference "LessonPlayerView" "LessonPlayerView\("
check_no_reference "SlideImageView" "SlideImageView"
echo ""
# ========================================
# 4. 关键逻辑检查
# ========================================
echo "🔧 阶段 4: 关键逻辑检查"
echo "----------------------------------------"
cd "$PROJECT_ROOT/ios/WildGrowth/WildGrowth"
# 检查 MapView 是否只使用 VerticalListLayout
echo -n " ⏳ 检查 MapView 布局... "
if grep -q "WindingPathLayout\|WindingNodeUnit" MapView.swift 2>/dev/null; then
echo -e "${RED}❌ 发现横版布局代码${NC}"
FAILED=$((FAILED + 1))
else
if grep -q "VerticalListLayout" MapView.swift 2>/dev/null; then
echo -e "${GREEN}✅ 只使用竖屏布局${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${YELLOW}⚠️ 未找到 VerticalListLayout${NC}"
SKIPPED=$((SKIPPED + 1))
fi
fi
# 检查 HomeView 是否只使用 VerticalScreenPlayerView
echo -n " ⏳ 检查 HomeView 播放器... "
if grep -q "LessonPlayerView" HomeView.swift 2>/dev/null; then
echo -e "${RED}❌ 发现 LessonPlayerView 引用${NC}"
FAILED=$((FAILED + 1))
else
if grep -q "VerticalScreenPlayerView" HomeView.swift 2>/dev/null; then
echo -e "${GREEN}✅ 只使用竖屏播放器${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${YELLOW}⚠️ 未找到 VerticalScreenPlayerView${NC}"
SKIPPED=$((SKIPPED + 1))
fi
fi
# 检查 CourseNavigation 是否还有 .player case
echo -n " ⏳ 检查 CourseNavigation 枚举... "
if grep -q "case.*player" HomeView.swift 2>/dev/null; then
echo -e "${YELLOW}⚠️ 发现 .player case可能需要移除${NC}"
SKIPPED=$((SKIPPED + 1))
else
echo -e "${GREEN}✅ 无 .player case${NC}"
PASSED=$((PASSED + 1))
fi
echo ""
# ========================================
# 5. 代码统计
# ========================================
echo "📊 阶段 5: 代码统计"
echo "----------------------------------------"
cd "$PROJECT_ROOT/ios/WildGrowth/WildGrowth"
# 统计 Swift 文件数量
SWIFT_FILES=$(find . -name "*.swift" -type f | wc -l | tr -d ' ')
echo " 📄 Swift 文件数量: $SWIFT_FILES"
# 统计代码行数(排除空行和注释)
CODE_LINES=$(find . -name "*.swift" -type f -exec cat {} \; | grep -v '^\s*$' | grep -v '^\s*//' | wc -l | tr -d ' ')
echo " 📝 代码行数(估算): $CODE_LINES"
echo ""
# ========================================
# 6. 测试总结
# ========================================
echo "📋 测试总结"
echo "========================================"
echo -e " ${GREEN}✅ 通过: $PASSED${NC}"
echo -e " ${RED}❌ 失败: $FAILED${NC}"
echo -e " ${YELLOW}⚠️ 跳过: $SKIPPED${NC}"
echo ""
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}🎉 所有测试通过!${NC}"
exit 0
else
echo -e "${RED}❌ 有测试失败,请检查${NC}"
exit 1
fi