Skip to content

Commit

Permalink
clean up editor config, reformat run_tests.sh according to it's rules
Browse files Browse the repository at this point in the history
  • Loading branch information
drichardson committed Apr 21, 2021
1 parent a7ab347 commit efdfdbc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 69 deletions.
13 changes: 0 additions & 13 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.{c,h}]
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[CMakeLists.txt]
indent_style = tab
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
trim_trailing_whitespace = true

119 changes: 63 additions & 56 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,88 @@ USE_VALGRIND=0
HUFFCODE="./huffcode"

usage() {
echo "Usage: run_tests.sh [USE_VALGRIND]"
echo "Usage: run_tests.sh [USE_VALGRIND]"
}

while [[ $# -gt 0 ]]; do
case "$1" in
--use-valgrind)
USE_VALGRIND=1
shift
;;
--huffcode)
shift
if [[ $# -eq 0 ]]; then
echo "Missing argument for --huffcode"
exit 1
fi
HUFFCODE=$1
shift
;;
*)
echo "Unexpected parameter $1"
exit 1
;;
esac
case "$1" in
--use-valgrind)
USE_VALGRIND=1
shift
;;
--huffcode)
shift
if [[ $# -eq 0 ]]; then
echo "Missing argument for --huffcode"
exit 1
fi
HUFFCODE=$1
shift
;;
*)
echo "Unexpected parameter $1"
exit 1
;;
esac
done

SCRATCH=$(mktemp --tmpdir -d huffman.XXXXXXXXXX)
# echo "Using temporary directory $SCRATCH"
cleanup() {
# echo "Cleaning up $SCRATCH"
rm -r "$SCRATCH"
# echo "Cleaning up $SCRATCH"
rm -r "$SCRATCH"
}
trap cleanup EXIT

if [[ $USE_VALGRIND == 1 ]]; then
VALGRIND="valgrind --tool=memcheck --memcheck:leak-check=yes --leak-check=full --errors-for-leak-kinds=all --show-leak-kinds=all --track-origins=yes --error-exitcode=1"
HUFFCODE="$VALGRIND $HUFFCODE"
VALGRIND="valgrind \
--tool=memcheck \
--memcheck:leak-check=yes \
--leak-check=full \
--errors-for-leak-kinds=all \
--show-leak-kinds=all \
--track-origins=yes \
--error-exitcode=1"
HUFFCODE="$VALGRIND $HUFFCODE"
fi

compress_test() {
local IN=$1
local OUT="$SCRATCH/$(basename $IN)"
echo "compress_test $IN"
set +e
$HUFFCODE -i "$IN" -o "$OUT.compressed"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode encode failed on $IN"
exit 1
fi
$HUFFCODE -d -i "$OUT.compressed" -o "$OUT.decompressed"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode decode failed on $OUT.compressed"
exit 1
fi
diff "$OUT.decompressed" "$IN"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode decode didn't match original on $IN"
exit 1
fi
set -e
local IN=$1
local OUT="$SCRATCH/$(basename $IN)"
echo "compress_test $IN"
set +e
$HUFFCODE -i "$IN" -o "$OUT.compressed"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode encode failed on $IN"
exit 1
fi
$HUFFCODE -d -i "$OUT.compressed" -o "$OUT.decompressed"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode decode failed on $OUT.compressed"
exit 1
fi
diff "$OUT.decompressed" "$IN"
if [ "$?" != 0 ]; then
echo "FAILURE: huffcode decode didn't match original on $IN"
exit 1
fi
set -e
}

# Only decompress. Does not verify against originally compressed file,
# but is used to make sure invalid code tables do not crash the decompressor.
decompress_test() {
local IN=$1
local OUT="$SCRATCH/$(basename $IN)"
echo "decompress_test $IN"
set +e
$HUFFCODE -d -i "$IN" -o "$OUT.decompressed"
local STATUS=$?
if [ "$STATUS" != 1 ]; then
echo "Expected test to fail with 1 but got $STATUS."
exit 1
fi
set -e
local IN=$1
local OUT="$SCRATCH/$(basename $IN)"
echo "decompress_test $IN"
set +e
$HUFFCODE -d -i "$IN" -o "$OUT.decompressed"
local STATUS=$?
if [ "$STATUS" != 1 ]; then
echo "Expected test to fail with 1 but got $STATUS."
exit 1
fi
set -e
}

echo "Basic Checks..."
Expand All @@ -96,7 +103,7 @@ compress_test "test_data/128_byte_2_symbol"

echo "Issue 2 Regression Checks..."
for file in "test_data/reported_issues/issue2/"*; do
decompress_test "$file"
decompress_test "$file"
done

echo "All Tests Passed"
Expand Down

0 comments on commit efdfdbc

Please sign in to comment.