2018-07-18 07:43:20 +08:00
|
|
|
#!/usr/bin/env bash
|
2018-06-16 05:54:34 +08:00
|
|
|
# Compile a source file and check errors against those listed in the file.
|
2018-07-12 08:45:13 +08:00
|
|
|
# Change the compiler by setting the F18 environment variable.
|
2018-06-16 05:54:34 +08:00
|
|
|
|
2020-09-10 22:22:52 +08:00
|
|
|
F18_OPTIONS="-fparse-only"
|
2020-05-12 02:38:53 +08:00
|
|
|
srcdir=$(dirname $0)
|
2019-07-13 03:37:16 +08:00
|
|
|
source $srcdir/common.sh
|
|
|
|
[[ ! -f $src ]] && die "File not found: $src"
|
2018-07-18 07:43:20 +08:00
|
|
|
|
2018-06-16 05:54:34 +08:00
|
|
|
log=$temp/log
|
|
|
|
actual=$temp/actual
|
|
|
|
expect=$temp/expect
|
|
|
|
diffs=$temp/diffs
|
2019-06-05 06:14:34 +08:00
|
|
|
|
2020-05-12 02:38:53 +08:00
|
|
|
cmd="$F18 $F18_OPTIONS $src"
|
2018-07-25 21:55:11 +08:00
|
|
|
( cd $temp; $cmd ) > $log 2>&1
|
2018-10-11 07:20:46 +08:00
|
|
|
if [[ $? -ge 128 ]]; then
|
|
|
|
cat $log
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-06-16 05:54:34 +08:00
|
|
|
|
|
|
|
# $actual has errors from the compiler; $expect has them from !ERROR comments in source
|
|
|
|
# Format both as "<line>: <text>" so they can be diffed.
|
|
|
|
sed -n 's=^[^:]*:\([^:]*\):[^:]*: error: =\1: =p' $log > $actual
|
2019-02-14 23:59:20 +08:00
|
|
|
awk '
|
|
|
|
BEGIN { FS = "!ERROR: "; }
|
|
|
|
/^ *!ERROR: / { errors[nerrors++] = $2; next; }
|
|
|
|
{ for (i = 0; i < nerrors; ++i) printf "%d: %s\n", NR, errors[i]; nerrors = 0; }
|
|
|
|
' $src > $expect
|
2018-06-16 05:54:34 +08:00
|
|
|
|
|
|
|
if diff -U0 $actual $expect > $diffs; then
|
|
|
|
echo PASS
|
|
|
|
else
|
|
|
|
echo "$cmd"
|
|
|
|
< $diffs \
|
2018-07-12 08:45:13 +08:00
|
|
|
sed -n -e 's/^-\([0-9]\)/actual at \1/p' -e 's/^+\([0-9]\)/expect at \1/p' \
|
2019-08-01 06:53:46 +08:00
|
|
|
| sort -n -k 3
|
2019-07-13 03:37:16 +08:00
|
|
|
die FAIL
|
2018-06-16 05:54:34 +08:00
|
|
|
fi
|