2022-04-28 23:28:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Arg 1: qb54 location
|
2022-09-04 00:55:10 +00:00
|
|
|
# Arg 2: Optional category to test
|
2022-04-28 23:28:45 +00:00
|
|
|
|
|
|
|
PREFIX="Compilation"
|
|
|
|
|
|
|
|
RESULTS_DIR="./tests/results/$PREFIX"
|
|
|
|
|
|
|
|
mkdir -p $RESULTS_DIR
|
|
|
|
|
|
|
|
QB64=$1
|
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
if [ "$#" -eq 2 ]; then
|
|
|
|
CATEGORY="/$2"
|
|
|
|
fi
|
|
|
|
|
2022-04-28 23:28:45 +00:00
|
|
|
show_failure()
|
|
|
|
{
|
2022-09-04 00:55:10 +00:00
|
|
|
cat "$RESULTS_DIR/$1-$2-compile_result.txt"
|
|
|
|
cat "$RESULTS_DIR/$2-compilelog.txt"
|
2022-04-28 23:28:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 03:02:21 +00:00
|
|
|
show_incorrect_result()
|
|
|
|
{
|
|
|
|
printf "EXPECTED: '%s'\n" "$1"
|
|
|
|
printf "GOT: '%s'\n" "$2"
|
|
|
|
}
|
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
|
|
|
|
# Each .bas file represents a separate test.
|
|
|
|
while IFS= read -r test
|
2022-04-28 23:28:45 +00:00
|
|
|
do
|
2022-09-04 00:55:10 +00:00
|
|
|
category=$(basename "$(dirname "$test")")
|
|
|
|
testName=$(basename "$test" .bas)
|
|
|
|
|
|
|
|
TESTCASE="$category/$testName"
|
|
|
|
EXE="$RESULTS_DIR/$category-$testName - output"
|
2022-05-23 03:54:20 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
# If a .err file exists, then this test is actually testing a compilation error
|
|
|
|
testType="success"
|
|
|
|
if test -f "./tests/compile_tests/$category/$testName.err"; then
|
|
|
|
testType="error"
|
|
|
|
fi
|
2022-04-28 23:28:45 +00:00
|
|
|
|
2022-05-11 00:11:51 +00:00
|
|
|
# Clear out temp folder before next compile, avoids stale compilelog files
|
|
|
|
rm -fr ./internal/temp/*
|
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
# Clean up existing EXE, so we don't use it by accident
|
|
|
|
rm -f "$EXE*"
|
|
|
|
|
|
|
|
compileResultOutput="$RESULTS_DIR/$category-$testName-compile_result.txt"
|
|
|
|
|
2022-09-04 07:04:39 +00:00
|
|
|
# A .flags file contains any extra compiler flags to provide to QB64 for this test
|
|
|
|
compilerFlags=
|
|
|
|
if test -f "./tests/compile_tests/$category/$testName.flags"; then
|
|
|
|
compilerFlags=$(cat "./tests/compile_tests/$category/$testName.flags")
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -m and -q make sure that we get predictable results
|
|
|
|
"$QB64" $compilerFlags -m -q -x "./tests/compile_tests/$category/$testName.bas" -o "$EXE" 1>"$compileResultOutput"
|
2022-04-28 23:28:45 +00:00
|
|
|
ERR=$?
|
2022-09-04 00:55:10 +00:00
|
|
|
cp_if_exists ./internal/temp/compilelog.txt "$RESULTS_DIR/$category-$testName-compilelog.txt"
|
2022-04-28 23:28:45 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
if [ "$testType" == "success" ]; then
|
|
|
|
(exit $ERR)
|
|
|
|
assert_success_named "Compile" "Compilation Error:" show_failure "$category" "$testName"
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
test -f "$EXE"
|
|
|
|
assert_success_named "exe exists" "$test-output executable does not exist!" show_failure "$category" "$testName"
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
# Some tests do not have an output or err file because they should
|
|
|
|
# compile successfully but cannot be run on the build agents
|
|
|
|
if [ ! -f "./tests/compile_tests/$category/$testName.output" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
expectedResult="$(cat "./tests/compile_tests/$category/$testName.output")"
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
pushd . > /dev/null
|
|
|
|
cd "./tests/compile_tests/$category"
|
|
|
|
testResult=$("../../../$EXE" 2>&1)
|
|
|
|
ERR=$?
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
(exit $ERR)
|
|
|
|
assert_success_named "run" "Execution Error:" echo "$testResult"
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
[ "$testResult" == "$expectedResult" ]
|
|
|
|
assert_success_named "result" "Result is wrong:" show_incorrect_result "$expectedResult" "$testResult"
|
|
|
|
else
|
|
|
|
! (exit $ERR)
|
|
|
|
assert_success_named "Compile" "Compilation Success, was expecting error:" show_failure "$category" "$testName"
|
2022-05-09 03:02:21 +00:00
|
|
|
|
2022-09-04 00:55:10 +00:00
|
|
|
! test -f "$EXE"
|
|
|
|
assert_success_named "Exe exists" "'$category-$testName - output' exists, it should not!" show_failure "$category" "$testName"
|
|
|
|
|
|
|
|
expectedErr="$(cat "./tests/compile_tests/$category/$testName.err")"
|
|
|
|
|
|
|
|
diffResult=$(diff -y "./tests/compile_tests/$category/$testName.err" "$compileResultOutput")
|
|
|
|
assert_success_named "Error result" "Error reporting is wrong:" echo "$diffResult"
|
|
|
|
fi
|
|
|
|
done < <(find ./tests/compile_tests$CATEGORY -name "*.bas" -print)
|