test_modfile.sh
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
# Compile a source file and compare generated .mod files against expected.
set -e
F18_OPTIONS="-fdebug-resolve-names -fparse-only"
srcdir=$(dirname $0)
source $srcdir/common.sh
actual=$temp/actual.mod
expect=$temp/expect.mod
actual_files=$temp/actual_files
prev_files=$temp/prev_files
diffs=$temp/diffs
set $src
touch $actual
for src in "$@"; do
[[ ! -f $src ]] && echo "File not found: $src" && exit 1
path=$(git ls-files --full-name $src 2>/dev/null || echo $src)
(
cd $temp
ls -1 *.mod > prev_files
$F18 $F18_OPTIONS $src
ls -1 *.mod | comm -13 prev_files -
) > $actual_files
expected_files=$(sed -n 's/^!Expect: \(.*\)/\1/p' $src | sort)
extra_files=$(echo "$expected_files" | comm -23 $actual_files -)
if [[ ! -z "$extra_files" ]]; then
echo "Unexpected .mod files produced:" $extra_files
die FAIL $path
fi
for mod in $expected_files; do
if [[ ! -f $temp/$mod ]]; then
echo "Compilation did not produce expected mod file: $mod"
die FAIL $path
fi
# The first three bytes of the file are a UTF-8 BOM
sed '/^[^!]*!mod\$/d' $temp/$mod > $actual
sed '1,/^!Expect: '"$mod"'/d' $src | sed -e '/^$/,$d' -e 's/^!//' > $expect
if ! diff -w -U999999 $expect $actual > $diffs; then
echo "Module file $mod differs from expected:"
sed '1,2d' $diffs
die FAIL $path
fi
done
rm -f $actual $expect
done
echo PASS