2024-06-23 12:42:10 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Arg 1: qb64 location
|
|
|
|
# Arg 2: Optional category to test
|
|
|
|
|
|
|
|
# Format tests perform multiple test cases on the same source input, varying the format
|
|
|
|
# settings to produce a different output. The mapping between "foo.bas" and its variant
|
|
|
|
# outputs are given by the "foo.flagmap" file, which specifies an output file name and list
|
|
|
|
# of compiler flags to use, separated by a space. e.g.
|
|
|
|
#
|
|
|
|
# foo-indent-only.out -f:autoindent=true -f:indentsize=4 -f:autolayout=false
|
|
|
|
|
|
|
|
PREFIX="Format"
|
|
|
|
|
|
|
|
RESULTS_DIR="./tests/results/$PREFIX"
|
|
|
|
|
|
|
|
mkdir -p $RESULTS_DIR
|
|
|
|
|
|
|
|
QB64=$1
|
|
|
|
|
|
|
|
if [ "$#" -ge 2 ]; then
|
|
|
|
CATEGORY="/$2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$#" -eq 3 ]; then
|
|
|
|
TESTS_TO_RUN="$3"
|
|
|
|
else
|
|
|
|
TESTS_TO_RUN='*.bas'
|
|
|
|
fi
|
|
|
|
|
|
|
|
show_failure()
|
|
|
|
{
|
|
|
|
cat "$RESULTS_DIR/$1-$2-$3-compile_result.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
show_incorrect_result()
|
|
|
|
{
|
|
|
|
printf "EXPECTED: '%s'\n" "$1"
|
|
|
|
printf "GOT: '%s'\n" "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while IFS= read -r test
|
|
|
|
do
|
|
|
|
category=$(basename "$(dirname "$test")")
|
|
|
|
testName=$(basename "$test" .bas)
|
|
|
|
|
|
|
|
FLAGMAP="tests/format_tests/$category/$testName.flagmap"
|
|
|
|
|
|
|
|
while IFS=' ' read -ra map
|
|
|
|
do
|
|
|
|
variant="${map[0]}"
|
2024-06-23 13:04:10 +00:00
|
|
|
TESTCASE="$category/$testName/$variant"
|
2024-06-23 12:42:10 +00:00
|
|
|
output="$RESULTS_DIR/$category-$testName-$variant-output"
|
|
|
|
compileResultOutput="$RESULTS_DIR/$category-$testName-$variant-compile_result.txt"
|
|
|
|
expectedResult="$(cat "tests/format_tests/$category/$variant")"
|
|
|
|
compilerFlags=("${map[@]:1}")
|
|
|
|
pushd . >/dev/null
|
|
|
|
cd "tests/format_tests/$category"
|
2024-06-23 13:04:10 +00:00
|
|
|
"../../../$QB64" -y -m "${compilerFlags[@]}" "$testName.bas" -o "../../../$output" 1>"../../../$compileResultOutput"
|
2024-06-23 12:42:10 +00:00
|
|
|
ERR=$?
|
|
|
|
popd >/dev/null
|
|
|
|
(exit $ERR)
|
2024-06-23 13:04:10 +00:00
|
|
|
assert_success_named "Format" "Formatting Error:" show_failure "$category" "$testName" "$variant"
|
2024-06-23 12:42:10 +00:00
|
|
|
test -f "$output"
|
|
|
|
assert_success_named "output exists" "$test-output does not exist!" show_failure "$category" "$testName" "$variant"
|
|
|
|
testResult="$(cat "$output")"
|
|
|
|
[ "$testResult" == "$expectedResult" ]
|
|
|
|
assert_success_named "result" "Result is wrong:" show_incorrect_result "$expectedResult" "$testResult"
|
|
|
|
done < "$FLAGMAP"
|
|
|
|
done < <(find "./tests/format_tests$CATEGORY" -name "$TESTS_TO_RUN" -print)
|