53 lines
1.4 KiB
Bash
53 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# This script is expected to be run from the root of the project.
|
|
|
|
# Paths to the two implementations
|
|
GPL="src/gpl"
|
|
SPL="swipl"
|
|
|
|
GPL_FLAGS=("--debug")
|
|
SPL_FLAGS=("--quiet" "-t" "'true'")
|
|
|
|
# Directory containing test files
|
|
TEST_DIR="examples"
|
|
|
|
# Temporary files for storing outputs
|
|
GPL_OUT=$(mktemp)
|
|
SPL_OUT=$(mktemp)
|
|
|
|
# Flag to track if all tests pass
|
|
PASSED=0
|
|
FAILED=0
|
|
|
|
# Iterate over all test files in the test directory
|
|
#for TESTFILE in $(find ${TEST_DIR} -type f); do
|
|
files=("examples/program.pl" "examples/basics/disjunction.pl" "examples/basics/fraternity.pl")
|
|
for TESTFILE in "${files[@]}"; do
|
|
# Run both programs with the test file
|
|
"${SPL}" "${SPL_FLAGS[@]}" "$TESTFILE" > "${SPL_OUT}" 2>&1
|
|
"${GPL}" "${GPL_FLAGS[@]}" -s "$TESTFILE" > "${GPL_OUT}" 2>&1
|
|
|
|
# Compare the outputs
|
|
if diff -q "$SPL_OUT" "$GPL_OUT" > /dev/null; then
|
|
PASSED=$((PASSED + 1))
|
|
else
|
|
echo "Test failed! Outputs differ for $TESTFILE"
|
|
printf "\nTest:\n%s\n" "$(cat "$TESTFILE")"
|
|
printf "\nExpected:\n%s\n" "$(cat "$SPL_OUT")"
|
|
printf "\nGot:\n%s\n" "$(cat "$GPL_OUT")"
|
|
echo "-----------------------------------------"
|
|
FAILED=$((FAILED + 1))
|
|
fi
|
|
done
|
|
|
|
# Clean up temporary files
|
|
rm "$SPL_OUT" "$GPL_OUT"
|
|
|
|
# Final result, summary
|
|
if [ $FAILED -eq 0 ]; then
|
|
echo "All tests passed!"
|
|
else
|
|
printf "Tests passed: %d\nTests failed: %d\n" "$PASSED" "$FAILED"
|
|
exit 1
|
|
fi
|