#!/bin/bash # 颜色定义 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # 测试的可执行文件路径 TEST_AST="./build/arch-company/test_ast" # TEST_AST="./build/arch-person/test_ast" # 需要测试的目录列表(可以自行添加) DIRECTORIES=( "/mnt/c/Programs/Tinysoft/TSLGen2/funcext" # "./another_directory" ) # 检查test_ast是否存在 if [ ! -f "$TEST_AST" ]; then echo -e "${RED}错误: 找不到 test_ast 可执行文件${NC}" echo "请确保 test_ast 在当前目录下,或修改脚本中的 TEST_AST 变量" exit 1 fi # 统计变量 total_files=0 tested_files=0 failed_files=0 echo -e "${BLUE}========================================${NC}" echo -e "${BLUE}开始测试 TSF 文件${NC}" echo -e "${BLUE}========================================${NC}" echo "" # 遍历每个目录 for dir in "${DIRECTORIES[@]}"; do if [ ! -d "$dir" ]; then echo -e "${YELLOW}警告: 目录不存在: $dir${NC}" continue fi echo -e "${BLUE}扫描目录: $dir${NC}" # 递归查找所有.tsf文件 while IFS= read -r -d '' file; do ((total_files++)) echo -e "${YELLOW}[测试]${NC} $file" # 运行test_ast,隐藏输出 if "$TEST_AST" "$file" > /dev/null 2>&1; then ((tested_files++)) echo -e "${GREEN} ✓ 通过${NC}" else ((failed_files++)) echo -e "${RED} ✗ 失败${NC}" echo -e "${RED}========================================${NC}" echo -e "${RED}测试失败: $file${NC}" echo -e "${RED}========================================${NC}" exit 1 fi done < <(find "$dir" -type f -name "*.tsf" -print0 | sort -z) echo "" done # 打印总结 echo -e "${BLUE}========================================${NC}" echo -e "${GREEN}所有测试完成!${NC}" echo -e "${BLUE}========================================${NC}" echo -e "总文件数: $total_files" echo -e "已测试: $tested_files" echo -e "失败: $failed_files" if [ $failed_files -eq 0 ]; then echo -e "${GREEN}✓ 全部通过${NC}" exit 0 else echo -e "${RED}✗ 存在失败${NC}" exit 1 fi