tame/tamer/tests/xmli/test-xmli

75 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Assert that a program can be derived from the ASG as expected.
#
# See `./README.md` for more information.
set -euo pipefail
mypath=$(dirname "$0")
. "$mypath/../../conf.sh"
# Performing this check within `<()` below won't cause a failure.
: "${P_XMLLINT?}" # conf.sh
tamer-flag-or-exit-ok wip-asg-derived-xmli
# Derive a program from `src.xml` and verify that it meets our expectations.
#
# This test is inherently fragile, as it will break any time we perform
# certain types of optimizations or change internal representations. _But
# that is intended._ We want to be well aware of such changes in derivation
# so that we can judge whether it needs adjustment.
test-derive-from-src() {
local dir="${1?Missing directory name}"
echo "# test-derive-from-src $dir"
"${TAMER_PATH_TAMEC?}" -o "$dir/out.xmli" --emit xmlo "$dir/src.xml" || return
diff <("$P_XMLLINT" --format "$dir/expected.xml" || echo 'ERR expected.xml') \
<("$P_XMLLINT" --format "$dir/out.xmli" || echo 'ERR out.xmli')
}
# Having taken `A` and derived `B`, we should be able to take `B` and derive
# `C`, where `B` and `C` are equivalent programs.
#
# That is, this derivation should be transitively equivalent and reach a
# fixpoint on the second derivation. This serves as a sanity check to
# ensure that the program we generated makes sense to our own system.
#
# Note that, in the future, we'll have to strip handoff metadata
# (`preproc:*` data) from the output so that it will be accepted by TAMER.
test-fixpoint() {
local dir="${1?Missing directory name}"
echo "# test-fixpoint $dir"
"${TAMER_PATH_TAMEC?}" -o "$dir/out-2.xmli" --emit xmlo "$dir/out.xmli" || return
diff <("$P_XMLLINT" --format "$dir/expected.xml" || echo 'ERR expected.xml') \
<("$P_XMLLINT" --format "$dir/out-2.xmli" || echo 'ERR out.xmli')
}
main() {
local fail=
for dir in "$mypath"/*/; do
test-derive-from-src "$dir" && test-fixpoint "$dir" || fail=1
done
test -z "$fail" || {
cat << EOF
!!! TEST FAILED
tamec: $TAMER_PATH_TAMEC
note: The compiler output and diff between the expected and given data
are above. Both files are formatted with \`xmllint\` automatically.
EOF
exit 1
}
}
main "$@"