#!/bin/bash # 变异测试跑一次:$1=文件 $2=old $3=new $4=判据文件 $5=说明 set -u f="$1"; old="$2"; new="$3"; t="$4"; why="$5" BAK="${TMPDIR:-/tmp}/mut-bak-$$-$RANDOM.orig" # ★ 不用固定名:并行跑会互相覆盖 cp -a "$f" "$BAK" before=$(sha256sum < "$f") python3 - "$f" "$old" "$new" <<'PY' import sys p,old,new=sys.argv[1],sys.argv[2],sys.argv[3] s=open(p,encoding='utf-8').read() n=s.count(old) if n!=1: print(f" [SKIP] 锚点出现 {n} 次(要恰好 1 次):{old[:60]!r}"); sys.exit(3) open(p,'w',encoding='utf-8').write(s.replace(old,new,1)) PY rc=$? if [ $rc -ne 0 ]; then cp -a "$BAK" "$f"; rm -f "$BAK"; echo " [SKIP] $why"; exit 0; fi node --test "$t" >/tmp/mut/out.txt 2>&1 trc=$? cp -a "$BAK" "$f" rm -f "$BAK" after=$(sha256sum < "$f") if [ "$before" != "$after" ]; then echo " [!! 还原失败] $f 必须立刻处理"; exit 2; fi if [ $trc -eq 0 ]; then echo " [红不了·缺陷] $why" else echo " [红✓] $why" fi