tsl-devkit/lsp-server/test/test_symbol/test.sh

190 lines
5.4 KiB
Bash
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
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# 测试的可执行文件路径
TEST_SYMBOL="./build/arch-company/test_symbol"
TEST_SYMBOL="./build/arch-person/test_symbol"
# 需要测试的目录列表(可以自行添加)
DIRECTORIES=(
"/mnt/c/Programs/Tinysoft/TSLGen2/funcext"
# "./another_directory"
)
# 是否显示详细输出设置为1显示详细信息0只显示摘要
VERBOSE=0
# 是否在第一个失败时停止设置为1则停止0继续测试
STOP_ON_FIRST_FAILURE=1
# 打印使用说明
print_usage() {
echo "用法: $0 [选项]"
echo "选项:"
echo " -v, --verbose 显示详细的测试输出"
echo " -c, --continue-on-error 遇到错误继续测试"
echo " -h, --help 显示此帮助信息"
exit 0
}
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case $1 in
-v|--verbose)
VERBOSE=1
shift
;;
-c|--continue-on-error)
STOP_ON_FIRST_FAILURE=0
shift
;;
-h|--help)
print_usage
;;
*)
echo -e "${RED}未知选项: $1${NC}"
print_usage
;;
esac
done
# 检查test_ast是否存在
if [ ! -f "$TEST_SYMBOL" ]; then
echo -e "${RED}错误: 找不到 test_ast 可执行文件${NC}"
echo "请确保 test_ast 在当前目录下,或修改脚本中的 TEST_SYMBOL 变量"
exit 1
fi
# 检查test_ast是否可执行
if [ ! -x "$TEST_SYMBOL" ]; then
echo -e "${RED}错误: test_ast 不可执行${NC}"
echo "请运行: chmod +x $TEST_SYMBOL"
exit 1
fi
# 统计变量
total_files=0
tested_files=0
failed_files=0
declare -a failed_file_list
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}开始测试 TSF 文件${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e "${CYAN}测试工具: $TEST_SYMBOL${NC}"
echo -e "${CYAN}跟随软链接: 是${NC}"
if [ $VERBOSE -eq 1 ]; then
echo -e "${CYAN}详细模式: 开启${NC}"
fi
if [ $STOP_ON_FIRST_FAILURE -eq 0 ]; then
echo -e "${CYAN}失败后继续: 是${NC}"
fi
echo ""
# 遍历每个目录
for dir in "${DIRECTORIES[@]}"; do
# 检查目录是否存在(支持软链接)
if [ ! -e "$dir" ]; then
echo -e "${YELLOW}警告: 目录不存在: $dir${NC}"
continue
fi
# 检查是否为目录(解引用软链接后)
if [ ! -d "$dir" ]; then
echo -e "${YELLOW}警告: 不是目录: $dir${NC}"
continue
fi
# 显示目录信息(包括软链接信息)
if [ -L "$dir" ]; then
real_path=$(readlink -f "$dir")
echo -e "${BLUE}扫描目录: $dir ${CYAN}(软链接 -> $real_path)${NC}"
else
echo -e "${BLUE}扫描目录: $dir${NC}"
fi
# 递归查找所有.tsf文件-L 选项跟随符号链接)
while IFS= read -r -d '' file; do
((total_files++))
# 显示文件路径(包括软链接信息)
if [ -L "$file" ]; then
real_file=$(readlink -f "$file")
echo -e "${YELLOW}[测试 $total_files]${NC} $file ${CYAN}(软链接)${NC}"
else
echo -e "${YELLOW}[测试 $total_files]${NC} $file"
fi
# 运行test_ast并捕获输出
output=$("$TEST_SYMBOL" "$file" 2>&1)
exit_code=$?
# 检查是否包含 "Status: SUCCESS"
if echo "$output" | grep -q "SUCCESS"; then
((tested_files++))
echo -e "${GREEN} ✓ 通过 (Status: SUCCESS)${NC}"
# 如果是详细模式,显示输出摘要
if [ $VERBOSE -eq 1 ]; then
echo "$output" | grep -E "(File:|Size:|Statements:|Errors:|Status:)" | sed 's/^/ /'
fi
else
((failed_files++))
failed_file_list+=("$file")
echo -e "${RED} ✗ 失败${NC}"
echo -e "${RED}========================================${NC}"
echo -e "${RED}测试失败: $file${NC}"
echo -e "${RED}退出码: $exit_code${NC}"
echo -e "${RED}========================================${NC}"
# 显示完整输出
echo -e "${YELLOW}测试输出:${NC}"
echo "$output" | sed 's/^/ /'
echo -e "${RED}========================================${NC}"
# 如果设置了第一次失败就停止
if [ $STOP_ON_FIRST_FAILURE -eq 1 ]; then
echo -e "${RED}因为测试失败而停止${NC}"
exit 1
fi
fi
echo ""
done < <(find -L "$dir" -type f -name "*.tsf" -print0 2>/dev/null | sort -z)
done
# 打印总结
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN}所有测试完成!${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e "总文件数: ${CYAN}$total_files${NC}"
echo -e "已通过: ${GREEN}$tested_files${NC}"
echo -e "失败: ${RED}$failed_files${NC}"
# 如果有失败的文件,列出它们
if [ $failed_files -gt 0 ]; then
echo ""
echo -e "${RED}失败的文件列表:${NC}"
for failed_file in "${failed_file_list[@]}"; do
echo -e " ${RED}${NC} $failed_file"
done
fi
echo ""
if [ $failed_files -eq 0 ]; then
echo -e "${GREEN}✓ 全部通过${NC}"
exit 0
else
echo -e "${RED}✗ 存在 $failed_files 个失败${NC}"
exit 1
fi