|
3 | 3 | for f in test_cases/*.brainrot; do
|
4 | 4 | echo "Running Valgrind on $f..."
|
5 | 5 | base=$(basename "$f" .brainrot)
|
6 |
| - if [[ "$base" == slorp_int ]]; then |
7 |
| - echo 42 | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
8 |
| - elif [[ "$base" == slorp_short ]]; then |
9 |
| - echo 69 | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
10 |
| - elif [[ "$base" == slorp_float ]]; then |
11 |
| - echo "3.14" | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
12 |
| - elif [[ "$base" == slorp_double ]]; then |
13 |
| - echo "3.141592" | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
14 |
| - elif [[ "$base" == slorp_char ]]; then |
15 |
| - echo "c" | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
16 |
| - elif [[ "$base" == slorp_string ]]; then |
17 |
| - echo "skibidi bop bop yes yes" | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
| 6 | + |
| 7 | + case "$base" in |
| 8 | + slorp_int) input="42" ;; |
| 9 | + slorp_short) input="69" ;; |
| 10 | + slorp_float) input="3.14" ;; |
| 11 | + slorp_double) input="3.141592" ;; |
| 12 | + slorp_char) input="c" ;; |
| 13 | + slorp_string) input="skibidi bop bop yes yes" ;; |
| 14 | + *) input="" ;; |
| 15 | + esac |
| 16 | + |
| 17 | + if [[ -n "$input" ]]; then |
| 18 | + echo "$input" | valgrind --leak-check=full --error-exitcode=100 ./brainrot "$f" |
18 | 19 | else
|
19 |
| - valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" |
| 20 | + valgrind --leak-check=full --error-exitcode=100 ./brainrot "$f" |
20 | 21 | fi
|
21 |
| - if [[ $? -ne 0 ]]; then |
22 |
| - echo "Valgrind failed on $f" |
| 22 | + |
| 23 | + valgrind_exit_code=$? # Capture only valgrind’s exit code |
| 24 | + |
| 25 | + if [[ $valgrind_exit_code -eq 100 ]]; then |
| 26 | + echo "Valgrind detected memory issues in $f" |
23 | 27 | exit 1
|
24 | 28 | fi
|
| 29 | + |
25 | 30 | echo
|
26 | 31 | done
|
| 32 | + |
0 commit comments