|
| 1 | +#!/bin/bash |
| 2 | +# Test the formatter's ability to print to stdout |
| 3 | + |
| 4 | +# Exit on error |
| 5 | +set -e |
| 6 | + |
| 7 | +# Path to the executables |
| 8 | +BUILD_DIR="build" |
| 9 | +FORMATTER="$BUILD_DIR/jres_formatter" |
| 10 | +SOLVER="$BUILD_DIR/jres_solver" |
| 11 | +INPUT_FILE="data/24h_race.json" |
| 12 | +SOLUTION_FILE="/tmp/test_solution_stdout.json" |
| 13 | + |
| 14 | +# Make sure we are in the project root |
| 15 | +if [ ! -f "CMakeLists.txt" ]; then |
| 16 | + echo "Error: This script must be run from the project root directory." |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +# Make sure binaries exist |
| 21 | +if [ ! -f "$SOLVER" ]; then |
| 22 | + echo "Error: Solver binary not found at $SOLVER. Build the project first." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | +if [ ! -f "$FORMATTER" ]; then |
| 26 | + echo "Error: Formatter binary not found at $FORMATTER. Build the project first." |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# Cleanup previous runs |
| 31 | +rm -f "$SOLUTION_FILE" |
| 32 | + |
| 33 | +echo "Running solver to generate solution..." |
| 34 | +$SOLVER -i $INPUT_FILE -s sequential -o $SOLUTION_FILE --quiet |
| 35 | + |
| 36 | +if [ ! -f "$SOLUTION_FILE" ]; then |
| 37 | + echo "Error: Solver failed to generate solution file." |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +echo "Running formatter without -o flag..." |
| 42 | +# Run the formatter and capture stdout |
| 43 | +OUTPUT=$($FORMATTER -i "$SOLUTION_FILE") |
| 44 | + |
| 45 | +# Check if the output contains expected strings from the summary report |
| 46 | +if [[ "$OUTPUT" == *"--- DRIVER SUMMARY ---"* ]] && [[ "$OUTPUT" == *"--- SCHEDULE ---"* ]]; then |
| 47 | + echo "Success: Formatter output to stdout detected." |
| 48 | +else |
| 49 | + echo "Error: Formatter did not print expected summary to stdout." |
| 50 | + echo "Output was:" |
| 51 | + echo "$OUTPUT" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +# Clean up |
| 56 | +rm "$SOLUTION_FILE" |
| 57 | +exit 0 |
0 commit comments