From 4a4e0a2e0c1749828142ad2e37b8aeebe9b090e8 Mon Sep 17 00:00:00 2001 From: white66663 <1005774559@qq.com> Date: Mon, 23 Mar 2026 17:12:52 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 自动遍历test/test_case/functional/下的所有.sy文件 - 统计测试通过/失败数量 - 输出详细的测试报告 - 用于Lab1语法树构建验证 --- scripts/run_all_tests.sh | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 scripts/run_all_tests.sh diff --git a/scripts/run_all_tests.sh b/scripts/run_all_tests.sh new file mode 100755 index 0000000..2b3ffb0 --- /dev/null +++ b/scripts/run_all_tests.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# 批量测试所有.sy文件的语法解析 + +test_dir="/home/white/nudt-compiler-cpp/test/test_case/functional" +compiler="/home/white/nudt-compiler-cpp/build/bin/compiler" + +if [ ! -f "$compiler" ]; then + echo "错误:编译器不存在,请先构建项目" + exit 1 +fi + +success_count=0 +failed_count=0 +failed_tests=() + +echo "开始测试所有.sy文件的语法解析..." +echo "=" + +# 获取所有.sy文件并排序 +for test_file in $(find "$test_dir" -name "*.sy" | sort); do + echo "测试: $(basename "$test_file")" + + # 运行解析测试,将输出重定向到/dev/null + "$compiler" --emit-parse-tree "$test_file" > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + echo " ✓ 成功" + ((success_count++)) + else + echo " ✗ 失败" + ((failed_count++)) + failed_tests+=($(basename "$test_file")) + fi +done + +echo "=" +echo "测试完成!" +echo "总测试数: $((success_count + failed_count))" +echo "成功: $success_count" +echo "失败: $failed_count" + +if [ $failed_count -gt 0 ]; then + echo "失败的测试用例:" + for test in "${failed_tests[@]}"; do + echo " - $test" + done +fi