--- flac.old/test/test_libFLAC.sh	2013-03-11 10:29:30.292319483 -0500
+++ flac/test/test_libFLAC.sh	2013-03-11 12:57:56.841972290 -0500
@@ -17,36 +17,65 @@
 #  restrictive of those mentioned above.  See the file COPYING.Xiph in this
 #  distribution.
 
-die ()
-{
-	echo $* 1>&2
-	exit 1
-}
-
+# Checks for debug build
 if [ x = x"$1" ] ; then 
 	BUILD=debug
 else
 	BUILD="$1"
 fi
 
+# Set up various paths to libs
 LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH
 LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH
 LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
 LD_LIBRARY_PATH=../objs/$BUILD/lib:$LD_LIBRARY_PATH
+
+# Must be exported
 export LD_LIBRARY_PATH
 export MALLOC_CHECK_=3
 export MALLOC_PERTURB_=$((RANDOM % 255 + 1))
 
+# This is where the `test_libFLAC' executable is located
 PATH=../src/test_libFLAC:$PATH
 PATH=../objs/$BUILD/bin:$PATH
 
-run_test_libFLAC ()
-{
+# Find where `valgrind' executable is located
+valgrind_binary="$(command -v valgrind)"
+
+# General die function
+die () {
+	printf "%s\n" "$@" 1>&2
+	exit 1
+}
+
+# Run `test_libFLAC' function
+run_test_libFLAC () {
+	# `test_libFLAC' is an executable which as was added to $PATH
+
+	# Test with `valgrind' if enabled.  If `flac' was _NOT_ compiled with debug
+	# symobls, this will error out and the valgrind.log will specify why
 	if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then
-		valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --log-fd=4 test_libFLAC $* 4>>test_libFLAC.valgrind.log
+
+		# Check for `valgrind' before continuing
+		if [ -n "$valgrind_binary" ] ; then
+			# `Valgrind' command wrapping around `test_libFLAC'
+			"$valgrind_binary" \
+				--leak-check=yes \
+				--show-reachable=yes \
+				--num-callers=100 \
+				--log-fd=4 \
+					test_libFLAC \
+						"$@" \
+						4>>test_libFLAC.valgrind.log
+		else
+			die "ERROR can't find \`valgrind' executable"
+		fi
+
+	# Run test _WITHOUT_ `valgrind'
 	else
-		test_libFLAC $*
+		test_libFLAC "$@"
 	fi
 }
 
-run_test_libFLAC || die "ERROR during test_libFLAC"
+# Execute test
+run_test_libFLAC || die "ERROR during \`test_libFLAC' test"
