#!/bin/bash # Verify that trying to write to a directory results in failure. if [[ $# != 2 ]]; then echo "$0 " exit 1 fi SPLITTER=$1 INPUT=$2 MSG=$(mktemp -p .) WRITABLE_OUTPUT=$(mktemp -p .) UNWRITABLE_OUTPUT=$(mktemp -d -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" "$WRITABLE_OUTPUT" rmdir "$UNWRITABLE_OUTPUT" exit 1 } # Check exit status. if ( "./$SPLITTER" "$INPUT" "$UNWRITABLE_OUTPUT" "$WRITABLE_OUTPUT" > "$MSG" ); then die "$LINENO: Unexpected success." fi # Check error message. if ! ( grep -qF "$UNWRITABLE_OUTPUT" "$MSG" ); then die "$LINENO: Did not identify failing output." fi if ! ( grep -qiF "writ" "$MSG" ); then die "$LINENO: Did not identify failing operation." fi # Try again with different argument order. if ( "./$SPLITTER" "$INPUT" "$WRITABLE_OUTPUT" "$UNWRITABLE_OUTPUT" > "$MSG" ); then die "$LINENO: Unexpected success." fi if ! ( grep -qF "$UNWRITABLE_OUTPUT" "$MSG" ); then die "$LINENO: Did not identify failing output." fi if ! ( grep -qiF "writ" "$MSG" ); then die "$LINENO: Did not identify failing operation." fi # Success, cleanup and exit quietly. rm -f "$MSG" "$WRITABLE_OUTPUT" rmdir "$UNWRITABLE_OUTPUT" exit 0