also include "aligned"
[llf.git] / run_fuzz.sh
blobca54256eaa7a345b7d42fa7f77081e58ff243ae3
1 #!/bin/sh
3 set -eu
5 # Download a random, recent paper from arXiv and try to run llf on it.
7 # Note the most common problems are unmatched {, which LLF rejects,
8 # or an encoding other than UTF-8. These are not considered errors
9 # in LLF.
10 tmpdir=$(mktemp -d)
11 root=$(dirname $(readlink -f "$0") )
12 cd "${tmpdir}"
14 discipline=$(dd if=/dev/urandom count=1 bs=1 2>/dev/null | od -A none -d)
15 discipline=$(( ${discipline} % 20 ))
16 case ${discipline} in
17 0) discipline="astro-ph"; ;;
18 1) discipline="cond-mat"; ;;
19 2) discipline="cs"; ;;
20 3) discipline="econ"; ;;
21 4) discipline="eess"; ;;
22 5) discipline="gr-qc"; ;;
23 6) discipline="hep-ex"; ;;
24 7) discipline="hep-lat"; ;;
25 8) discipline="hep-ph"; ;;
26 9) discipline="hep-th"; ;;
27 10) discipline="math"; ;;
28 11) discipline="math-ph"; ;;
29 12) discipline="nlin"; ;;
30 13) discipline="nucl-ex"; ;;
31 14) discipline="nucl-th"; ;;
32 15) discipline="physics"; ;;
33 16) discipline="q-bio"; ;;
34 17) discipline="q-fin"; ;;
35 18) discipline="quant-ph"; ;;
36 19) discipline="stat"; ;;
37 esac
39 absurl=$(curl -s "http://export.arxiv.org/rss/${discipline}" | grep -Eo '[^"<>]+arxiv.org/abs/[^"<>]+' | sort -R | head -n 1)
40 srcurl=$(printf %s\\n "${absurl}" | sed -re 's/\/abs\//\/e-print\//')
41 srcname=$(printf %s\\n "${srcurl}" | sed -re 's/.*\///')
42 curl -Ls "${srcurl}" -o "${srcname}"
43 mime=$(file -bi "${srcname}" | sed -re 's/;.*//')
45 case ${mime} in
46 application/x-gzip)
47 tar -xf "${srcname}" 2>/dev/null >/dev/null || gunzip -c "${srcname}" > "${srcname}.raw"
49 application/gzip)
50 tar -xf "${srcname}" 2>/dev/null >/dev/null || gunzip -c "${srcname}" > "${srcname}.raw"
52 text/x-tex) ;;
53 application/pdf)
54 printf 'No TeX source for %s\n' "${absurl}"
55 printf 'tmpdir = %s\n' "${tmpdir}"
56 exit 1
59 printf 'Unknown mimetype %s at %s\n' "${mime}" ${tmpdir}
60 printf 'tmpdir = %s\n' "${tmpdir}"
61 exit 1
63 esac
65 oldifs="${IFS}"
66 IFS="
68 err=0
69 for f in $(ls); do
70 mime=$(file -bi "${f}" | sed -re 's/;.*//')
71 [ "${mime}" = "text/x-tex" ] || continue
72 case "${f}" in
73 *sty) continue ;;
74 *bst) continue ;;
75 esac
77 "${root}/llf.lua" -c "${root}/llfrc.lua" < "${f}" 2>/dev/null > /dev/null && continue
78 err=1
79 printf 'LLF could not handle %s\n' "${f}"
80 done
82 if [ "${err}" -eq 0 ]; then
83 printf 'All okay for %s\n' "${absurl}"
84 rm -rf "${tmpdir}"
86 exit 0
87 else
88 printf 'There were some errors for %s\n' "${absurl}"
89 printf 'tmpdir = %s\n' "${tmpdir}"