#!/bin/bash # Verify that trying to process a nonexistent file results in failure. if [[ $# != 1 ]]; then echo "$0 " exit 1 fi SPLITTER=$1 MSG=$(mktemp -p .) OUTPUT1=$(mktemp -p .) OUTPUT2=$(mktemp -p .) # Disable leak checking for ASAN, since we intentionally don't free memory. export ASAN_OPTIONS=detect_leaks=0 function die { echo "$1" rm -f "$MSG" "$OUTPUT1" "$OUTPUT2" exit 1 } # Check exit status. if ( "./$SPLITTER" nonexistent_file.png "$OUTPUT1" "$OUTPUT2" > "$MSG" ); then die "$LINENO: Unexpected success." fi # Check error message. if ! ( grep -qF "nonexistent_file.png" "$MSG" ); then die "$LINENO: Did not identify failing input." fi if ! ( grep -qiF "read" "$MSG" ); then die "$LINENO: Did not identify failing operation." fi # Verify that we didn't try to write anything. # # mktemp would have created empty temporary files, here we check that # they are still empty. if [[ -s "$OUTPUT1" ]]; then die "$LINENO: Unexpected output file $OUTPUT1" fi if [[ -s "$OUTPUT2" ]]; then die "$LINENO: Unexpected output file $OUTPUT2" fi # Success, cleanup and exit quietly. rm -f "$MSG" "$OUTPUT1" "$OUTPUT2" exit 0