Permalink
Browse files

Merge pull request #12 from tejr/master

A few shell tweaks to test suite
  • Loading branch information...
2 parents c45801f + b81e4c0 commit 1fe26938923d3938ed9e66a4b34aabcbe6a66732 @mkfifo committed Jul 23, 2015
Showing with 14 additions and 12 deletions.
  1. +14 −12 test.sh
View
@@ -1,26 +1,29 @@
#!/usr/bin/env bash
# check for valgrind
-which valgrind
-if [[ 0 -ne $? ]]; then
- echo "No valgrind found"
- exit 1
-fi
+hash valgrind || exit
set -eu
-TESTFILENAME="tmp_testing_file"
+TESTFILENAME=$(mktemp) || exit
VALGRINDOPTS="--track-origins=yes --error-exitcode=1 --leak-check=full --show-reachable=yes"
echo -e "\nWriting file"
-cat <<EOF > $TESTFILENAME
+cat <<EOF > "$TESTFILENAME"
hello world how are you mutter mutter sl/ash
EOF
+warn() {
+ if [[ -e $TESTFILENAME ]] ; then
+ printf 'Leaving tmp file laying around as '\''%s'\''\n' "$TESTFILENAME"
+ exit 1
+ fi
+}
+trap warn EXIT
echo -e "\nRunning dodo"
-valgrind $VALGRINDOPTS ./dodo $TESTFILENAME <<EOF
+valgrind $VALGRINDOPTS ./dodo "$TESTFILENAME" <<EOF
p # print 100 bytes
p5 # print 5 bytes ('hello')
e/hello/ # expect string 'hello'
@@ -35,22 +38,21 @@ EOF
echo -e "\nComparing output"
-GOT=`cat $TESTFILENAME`
+GOT=`cat "$TESTFILENAME"`
EXPECTED="hello marge how are you mutter mutter slashy"
if [ ! "$GOT" = "$EXPECTED" ]; then
echo -e "\nTest failed:"
echo "Got '$GOT'"
echo "Expected '$EXPECTED'"
# do not clean up on failure to allow inspection of file
- #rm -f $TESTFILENAME
- echo "Leaving tmp file laying around as '$TESTFILENAME'"
+ #rm -f -- "$TESTFILENAME"
exit 1
fi
echo -e "\nAll green"
echo -e "\nRemoving temporary file"
-rm -f $TESTFILENAME
+rm -f -- "$TESTFILENAME"

0 comments on commit 1fe2693

Please sign in to comment.