You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.0 KiB
97 lines
2.0 KiB
#!/bin/bash
|
|
|
|
# 测试脚本
|
|
# 用法: ./run_tests.sh [--verbose] [<单个测试文件>]
|
|
|
|
COMPILER="./build/bin/compiler"
|
|
TEST_DIR="test/test_case"
|
|
RESULT_FILE="result.txt"
|
|
VERBOSE=0
|
|
|
|
# 解析参数
|
|
if [[ "$1" == "--verbose" ]]; then
|
|
VERBOSE=1
|
|
shift
|
|
fi
|
|
|
|
# 检查编译器是否存在
|
|
if [ ! -f "$COMPILER" ]; then
|
|
echo "错误: 编译器未找到于 $COMPILER"
|
|
echo "请先完成项目构建 (cmake 和 make)"
|
|
exit 1
|
|
fi
|
|
|
|
# 如果指定了单个文件,检查文件是否存在
|
|
if [ -n "$1" ] && [ ! -f "$1" ]; then
|
|
echo "错误: 文件 $1 不存在"
|
|
exit 1
|
|
fi
|
|
|
|
# 清空(或创建)结果文件
|
|
> "$RESULT_FILE"
|
|
|
|
# 计数器
|
|
total=0
|
|
passed=0
|
|
failed=0
|
|
|
|
echo "开始测试 SysY 解析..."
|
|
echo "输出将保存到 $RESULT_FILE"
|
|
echo "------------------------"
|
|
|
|
# 确定测试文件列表
|
|
if [ -n "$1" ]; then
|
|
# 使用提供的单个文件
|
|
TEST_FILES=("$1")
|
|
else
|
|
# 收集所有 .sy 文件
|
|
mapfile -t TEST_FILES < <(find "$TEST_DIR" -type f -name "*.sy" | sort)
|
|
fi
|
|
|
|
for file in "${TEST_FILES[@]}"; do
|
|
((total++))
|
|
if [ $VERBOSE -eq 1 ]; then
|
|
echo "测试文件: $file"
|
|
else
|
|
echo -n "测试 $file ... "
|
|
fi
|
|
|
|
echo "========== $file ==========" >> "$RESULT_FILE"
|
|
|
|
if [ $VERBOSE -eq 1 ]; then
|
|
"$COMPILER" --emit-parse-tree "$file" 2>&1 | tee -a "$RESULT_FILE"
|
|
result=${PIPESTATUS[0]}
|
|
else
|
|
"$COMPILER" --emit-parse-tree "$file" >> "$RESULT_FILE" 2>&1
|
|
result=$?
|
|
fi
|
|
|
|
echo "" >> "$RESULT_FILE"
|
|
|
|
if [ $result -eq 0 ]; then
|
|
if [ $VERBOSE -eq 0 ]; then
|
|
echo "通过"
|
|
fi
|
|
((passed++))
|
|
else
|
|
if [ $VERBOSE -eq 0 ]; then
|
|
echo "失败"
|
|
else
|
|
echo ">>> 解析失败: $file"
|
|
fi
|
|
((failed++))
|
|
fi
|
|
done
|
|
|
|
echo "------------------------"
|
|
echo "总计: $total"
|
|
echo "通过: $passed"
|
|
echo "失败: $failed"
|
|
echo "详细输出已保存至 $RESULT_FILE"
|
|
|
|
if [ $failed -gt 0 ]; then
|
|
exit 1
|
|
else
|
|
exit 0
|
|
fi
|