1#!/usr/bin/env bash 2# Compile a source file and check errors against those listed in the file. 3# Change the compiler by setting the F18 environment variable. 4 5F18_OPTIONS="-fparse-only" 6srcdir=$(dirname $0) 7source $srcdir/common.sh 8[[ ! -f $src ]] && die "File not found: $src" 9 10log=$temp/log 11actual=$temp/actual 12expect=$temp/expect 13diffs=$temp/diffs 14 15cmd="$F18 $F18_OPTIONS $src" 16( cd $temp; $cmd ) > $log 2>&1 17if [[ $? -ge 128 ]]; then 18 cat $log 19 exit 1 20fi 21 22# $actual has errors from the compiler; $expect has them from !ERROR comments in source 23# Format both as "<line>: <text>" so they can be diffed. 24sed -n 's=^[^:]*:\([^:]*\):[^:]*: error: =\1: =p' $log > $actual 25awk ' 26 BEGIN { FS = "!ERROR: "; } 27 /^ *!ERROR: / { errors[nerrors++] = $2; next; } 28 { for (i = 0; i < nerrors; ++i) printf "%d: %s\n", NR, errors[i]; nerrors = 0; } 29' $src > $expect 30 31if diff -U0 $actual $expect > $diffs; then 32 echo PASS 33else 34 echo "$cmd" 35 < $diffs \ 36 sed -n -e 's/^-\([0-9]\)/actual at \1/p' -e 's/^+\([0-9]\)/expect at \1/p' \ 37 | sort -n -k 3 38 die FAIL 39fi 40