|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
shopt -s nullglob
|
|
|
|
|
|
|
|
|
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
|
BUILD_DIR="$ROOT_DIR/build"
|
|
|
|
|
@ -10,6 +11,38 @@ GRAMMAR_PATH="$ROOT_DIR/src/antlr4/SysY.g4"
|
|
|
|
|
COMPILER="$BUILD_DIR/bin/compiler"
|
|
|
|
|
SAVE_TREE=false
|
|
|
|
|
TREE_DIR="$ROOT_DIR/test_tree"
|
|
|
|
|
POSITIVE_CASES=(
|
|
|
|
|
"$ROOT_DIR"/test/test_case/functional/*.sy
|
|
|
|
|
"$ROOT_DIR"/test/test_case/performance/*.sy
|
|
|
|
|
)
|
|
|
|
|
NEGATIVE_CASES=(
|
|
|
|
|
"$ROOT_DIR"/test/test_case/negative/*.sy
|
|
|
|
|
)
|
|
|
|
|
positive_total=0
|
|
|
|
|
positive_passed=0
|
|
|
|
|
positive_failed=0
|
|
|
|
|
negative_total=0
|
|
|
|
|
negative_passed=0
|
|
|
|
|
negative_failed=0
|
|
|
|
|
failed_cases=()
|
|
|
|
|
|
|
|
|
|
print_summary() {
|
|
|
|
|
local total passed failed
|
|
|
|
|
total=$((positive_total + negative_total))
|
|
|
|
|
passed=$((positive_passed + negative_passed))
|
|
|
|
|
failed=$((positive_failed + negative_failed))
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
echo "Summary:"
|
|
|
|
|
echo " Positive cases: total=$positive_total, passed=$positive_passed, failed=$positive_failed"
|
|
|
|
|
echo " Negative cases: total=$negative_total, passed=$negative_passed, failed=$negative_failed"
|
|
|
|
|
echo " Overall: total=$total, passed=$passed, failed=$failed"
|
|
|
|
|
|
|
|
|
|
if (( ${#failed_cases[@]} > 0 )); then
|
|
|
|
|
echo "Failed cases:"
|
|
|
|
|
printf ' - %s\n' "${failed_cases[@]}"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
@ -35,20 +68,20 @@ java -jar "$JAR_PATH" \
|
|
|
|
|
"$GRAMMAR_PATH"
|
|
|
|
|
|
|
|
|
|
echo "[2/4] Configuring CMake..."
|
|
|
|
|
cmake -S "$ROOT_DIR" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release
|
|
|
|
|
cmake -S "$ROOT_DIR" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release -DCOMPILER_PARSE_ONLY=ON
|
|
|
|
|
|
|
|
|
|
echo "[3/4] Building project..."
|
|
|
|
|
cmake --build "$BUILD_DIR" -j "$(nproc)"
|
|
|
|
|
|
|
|
|
|
echo "[4/4] Running parse-tree tests..."
|
|
|
|
|
failed=0
|
|
|
|
|
echo "[4/4] Running parse-tree tests in parse-only mode..."
|
|
|
|
|
|
|
|
|
|
if [[ "$SAVE_TREE" == true ]]; then
|
|
|
|
|
rm -rf "$TREE_DIR"
|
|
|
|
|
mkdir -p "$TREE_DIR"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
for case_file in "$ROOT_DIR"/test/test_case/functional/*.sy "$ROOT_DIR"/test/test_case/performance/*.sy; do
|
|
|
|
|
for case_file in "${POSITIVE_CASES[@]}"; do
|
|
|
|
|
((positive_total += 1))
|
|
|
|
|
if [[ "$SAVE_TREE" == true ]]; then
|
|
|
|
|
rel_path="${case_file#"$ROOT_DIR"/test/test_case/}"
|
|
|
|
|
rel_dir="$(dirname "$rel_path")"
|
|
|
|
|
@ -60,22 +93,51 @@ for case_file in "$ROOT_DIR"/test/test_case/functional/*.sy "$ROOT_DIR"/test/tes
|
|
|
|
|
echo "FAIL: $case_file"
|
|
|
|
|
cat /tmp/lab1_parse.err
|
|
|
|
|
rm -f "$out_file"
|
|
|
|
|
failed=1
|
|
|
|
|
((positive_failed += 1))
|
|
|
|
|
failed_cases+=("$case_file")
|
|
|
|
|
else
|
|
|
|
|
echo "PASS: $case_file -> $out_file"
|
|
|
|
|
((positive_passed += 1))
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if ! "$COMPILER" --emit-parse-tree "$case_file" >/dev/null 2>/tmp/lab1_parse.err; then
|
|
|
|
|
echo "FAIL: $case_file"
|
|
|
|
|
cat /tmp/lab1_parse.err
|
|
|
|
|
failed=1
|
|
|
|
|
((positive_failed += 1))
|
|
|
|
|
failed_cases+=("$case_file")
|
|
|
|
|
else
|
|
|
|
|
echo "PASS: $case_file"
|
|
|
|
|
((positive_passed += 1))
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [[ "$failed" -ne 0 ]]; then
|
|
|
|
|
if (( ${#NEGATIVE_CASES[@]} > 0 )); then
|
|
|
|
|
echo
|
|
|
|
|
echo "Running negative parse tests..."
|
|
|
|
|
for case_file in "${NEGATIVE_CASES[@]}"; do
|
|
|
|
|
((negative_total += 1))
|
|
|
|
|
if "$COMPILER" --emit-parse-tree "$case_file" >/tmp/lab1_negative.out 2>/tmp/lab1_negative.err; then
|
|
|
|
|
echo "FAIL: $case_file (expected parse failure, but parsing succeeded)"
|
|
|
|
|
((negative_failed += 1))
|
|
|
|
|
failed_cases+=("$case_file")
|
|
|
|
|
else
|
|
|
|
|
if grep -q '^\[error\] \[parse\]' /tmp/lab1_negative.err; then
|
|
|
|
|
echo "PASS: $case_file -> expected parse error"
|
|
|
|
|
((negative_passed += 1))
|
|
|
|
|
else
|
|
|
|
|
echo "FAIL: $case_file (did not report parse error as expected)"
|
|
|
|
|
cat /tmp/lab1_negative.err
|
|
|
|
|
((negative_failed += 1))
|
|
|
|
|
failed_cases+=("$case_file")
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
print_summary
|
|
|
|
|
|
|
|
|
|
if (( positive_failed + negative_failed > 0 )); then
|
|
|
|
|
echo "Batch test finished with failures."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|