2023-02-22 23:03:42 -05:00
|
|
|
#!/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"
|
|
|
|
|
2023-02-24 14:11:27 -05:00
|
|
|
# Performing this check within `<()` below won't cause a failure.
|
|
|
|
: "${P_XMLLINT?}" # conf.sh
|
|
|
|
|
2023-02-22 23:03:42 -05:00
|
|
|
tamer-flag-or-exit-ok wip-asg-derived-xmli
|
|
|
|
|
2023-02-24 14:11:27 -05:00
|
|
|
# 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() {
|
|
|
|
echo '# test-derive-from-src'
|
2023-02-22 23:03:42 -05:00
|
|
|
"${TAMER_PATH_TAMEC?}" -o "$mypath/out.xmli" --emit xmlo "$mypath/src.xml"
|
|
|
|
|
2023-02-24 14:11:27 -05:00
|
|
|
diff <("$P_XMLLINT" --format "$mypath/expected.xml" || echo 'ERR expected.xml') \
|
|
|
|
<("$P_XMLLINT" --format "$mypath/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() {
|
|
|
|
echo '# test-fixpoint'
|
|
|
|
"${TAMER_PATH_TAMEC?}" -o "$mypath/out-2.xmli" --emit xmlo "$mypath/out.xmli"
|
2023-02-22 23:03:42 -05:00
|
|
|
|
|
|
|
diff <("$P_XMLLINT" --format "$mypath/expected.xml" || echo 'ERR expected.xml') \
|
2023-02-24 14:11:27 -05:00
|
|
|
<("$P_XMLLINT" --format "$mypath/out-2.xmli" || echo 'ERR out.xmli')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
local fail=
|
|
|
|
|
|
|
|
test-derive-from-src || fail=1
|
|
|
|
test-fixpoint || fail=1
|
|
|
|
|
|
|
|
test -z "$fail" || {
|
2023-02-22 23:03:42 -05:00
|
|
|
cat << EOF
|
|
|
|
!!! TEST FAILED
|
|
|
|
tamec: $TAMER_PATH_TAMEC
|
|
|
|
|
2023-02-24 14:11:27 -05:00
|
|
|
note: The compiler output and diff between the expected and given data
|
2023-02-22 23:03:42 -05:00
|
|
|
are above. Both files are formatted with \`xmllint\` automatically.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|
|
|
|
|