test_ascii.sh (1251B)
1 #!/bin/sh 2 # Sources and docs stay pure ASCII. Em-dashes and curly quotes arrive via copy 3 # paste and show up as mojibake on a serial console with no locale. 4 set -eu 5 HERE=$(cd "$(dirname "$0")" && pwd) 6 ROOT=$(cd "${HERE}/../.." && pwd) 7 8 echo "==> test_ascii: source and docs are pure ASCII" 9 cd "${ROOT}" 10 11 # Walks the tree rather than asking git: CI delivers a tarball of the commit, 12 # with no repository, so `git ls-files` would fail there and report nothing 13 # wrong. 14 files=$(find . \ 15 -path ./build -prune -o \ 16 -path ./.git -prune -o \ 17 -name lib -prune -o \ 18 -type f \( -name '*.c' -o -name '*.h' -o -name '*.sh' -o -name '*.md' \ 19 -o -name 'Makefile' -o -name '*.mk' -o -name '*.cnf' \ 20 -o -name '*.yml' -o -name '.dep' \) -print) 21 22 [ -n "${files}" ] || { echo "FAIL: found no files to check" >&2; exit 1; } 23 echo "checking $(printf '%s\n' "${files}" | wc -l) files" 24 25 bad='' 26 for f in ${files}; do 27 hit=$(LC_ALL=C grep -nP '[^\x00-\x7F]' "$f" 2>/dev/null | head -3 | sed "s|^|${f}:|" || true) 28 [ -n "${hit}" ] && bad="${bad}${hit} 29 " 30 done 31 32 if [ -n "${bad}" ]; then 33 echo "FAIL: non-ASCII bytes found:" >&2 34 printf '%s' "${bad}" | head -10 >&2 35 exit 1 36 fi 37 echo "PASS: no non-ASCII in sources" 38 39 echo "==> test_ascii done"