diff --git a/scripts/score.sh b/scripts/score.sh index 70405310..e9228b40 100755 --- a/scripts/score.sh +++ b/scripts/score.sh @@ -23,6 +23,17 @@ BLUE='\033[0;34m' BOLD='\033[1m' NC='\033[0m' +# 规范比较:忽略尾部空格和尾部空行(与 2026test.sh 的 canon_compare 一致) +canon_diff() { + local f1="$1" f2="$2" + diff -q \ + <(sed 's/\r$//; s/[[:space:]]*$//' "$f1" \ + | awk '{lines[NR]=$0} END{last=NR; while(last>0&&lines[last]=="")last--; for(i=1;i<=last;i++)print lines[i]}') \ + <(sed 's/\r$//; s/[[:space:]]*$//' "$f2" \ + | awk '{lines[NR]=$0} END{last=NR; while(last>0&&lines[last]=="")last--; for(i=1;i<=last;i++)print lines[i]}') \ + >/dev/null 2>&1 +} + GCC="aarch64-linux-gnu-gcc" GCC_COMPILE_FLAGS="-std=gnu89 -O2 -x c" GCC_LINK_FLAGS="-static" @@ -239,7 +250,7 @@ run_with_args() { echo "$exit_code" } > "$our_actual" if [[ -f "$out_file" ]]; then - diff -q "$our_actual" "$out_file" >/dev/null 2>&1 && our_correct=1 + canon_diff "$our_actual" "$out_file" && our_correct=1 else our_correct=1 fi