--- flac.old/test/test_compression.sh	2013-03-11 10:29:30.291319496 -0500
+++ flac/test/test_compression.sh	2013-03-12 20:53:03.960435626 -0500
@@ -17,35 +17,86 @@
 #  restrictive of those mentioned above.  See the file COPYING.Xiph in this
 #  distribution.
 
-LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_synthesis/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../src/share/utf8/.libs:$LD_LIBRARY_PATH
-LD_LIBRARY_PATH=`pwd`/../objs/$BUILD/lib:$LD_LIBRARY_PATH
-export LD_LIBRARY_PATH
-PATH=`pwd`/../src/flac:$PATH
-
-echo "Using FLAC binary :" $(which flac)
-
-date=`date "+%Y%m%dT%H%M%S"`
-fname="comp${date}.flac"
-
-last_k=0
-last_size=$(wc -c < noisy-sine.wav)
-
-echo "Original file size ${last_size} bytes."
-
-for k in 1 2 3 4 5 6 7 8 ; do
-	flac -${k} --silent noisy-sine.wav -o ${fname}
-	size=$(wc -c < ${fname})
-	echo "Compression level ${k}, file size ${size} bytes."
-	if test ${last_size} -lt ${size} ; then
-		echo "Error : Compression ${last_k} size $last_size >= compression $k size $size."
+# General die function
+die () {
+	printf "%s\n" "$@" 1>&2
+	exit 1
+}
+
+# Set up path to built `flac' binary and `test_streams' binary
+PATH=../src/flac:$PATH
+PATH=../src/test_streams:$PATH
+
+# Find where `flac' is located in $PATH
+flac_binary="$(command -v flac)"
+
+# Print out current operation
+printf "%s\n" "Using FLAC binary: \`$(command -v flac)'"
+
+# Check if 'noisy-sine.wav' exists.  If not, create it using `test_streams'
+if [ ! -f noise.raw ] ; then
+	test_streams || die "ERROR during \`test_streams'"
+fi
+
+# Obtain 'noisy-sine.wav' file size (in bytes)
+previous_size=$(wc -c < noisy-sine.wav)
+
+# Print the original file size (in bytes) of 'noisy-sine.wav'
+printf "Original file size: $previous_size bytes.\n"
+
+# Initialize previous compression level to original WAV file (essentiall NUL) to
+# compare against the test fails in the below loop
+previous_compression="WAV File (Not Compressed)"
+
+# For each level of compression, run through and encode 'noisy-sine.wav' with
+# said compression level, testing the FLAC's file size with that of the last
+# encoded FLAC's file size.  This checks to make sure each encoded file gets
+# progressively smaller as the compression level is increased
+for current_compression in 0 1 2 3 4 5 6 7 8 ; do
+
+	# Temporarily encoded filename
+	tmp_file="tmp_compression_${current_compression}.$$.flac"
+
+	# Create the temporarily encoded FLAC file from 'noisy-sine.wav' with
+	# currently specified compression level
+	"$flac_binary" "-$current_compression" --silent noisy-sine.wav -o "$tmp_file"
+
+	# Obtain the file size (in bytes) from the encoded FLAC file
+	current_size="$(wc -c < "$tmp_file")"
+
+	# Print the current compression level and the encoded file's size (in bytes)
+	printf "%s\n" "Compression level: '${current_compression}' ::: File size: $current_size bytes."
+
+	# If the current size of the encoded FLAC file is greater than the
+	# previously encoded FLAC file, display ERROR and exit
+	if [ $current_size -gt $previous_size ] ; then
+		{
+		printf "################################  ERROR  #######################################\n"
+		printf "\n"
+		printf "                              Previous File\n"
+		printf "    ------------------------------------------------------------------------\n"
+		printf "    Compression Level: '$previous_compression'\n"
+		printf "            File Size: '$previous_size' bytes\n"
+		printf "\n"
+		printf "                               Current File\n"
+		printf "    ------------------------------------------------------------------------\n"
+		printf "    Compression Level: '$current_compression'\n"
+		printf "            File Size: '$current_size' bytes\n"
+		printf "\n"
+		printf " ** Current file is GREATER in size than previous file! Regression detected! ** \n"
+		printf "\n"
+		printf "################################################################################\n"
+		} >&2
+
 		exit 1
-		fi
-	last_size=${size}
-	last_k=${k}
-	rm -f ${fname}
-	done
+	fi
+
+	# Set previous size to the current size
+	previous_size="$current_size"
+
+	# Set previous compression to current compression
+	previous_compression="$current_compression"
+
+	# Remove the tested FLAC file
+	rm -f "$tmp_file"
+done
