summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-06-04 12:16:52 -0300
committerAndrés <andmarti@gmail.com>2021-06-04 12:16:52 -0300
commit35a9175456c5518cad3c5d278876dd1219bd24a2 (patch)
tree0104a0086555db6368f1ecfdc1a84ee907c279f2 /tests
parent619ded1af207f95fb8d93b0f120e0ad9d36daadf (diff)
Added valgrind check on tests
Diffstat (limited to 'tests')
-rwxr-xr-xtests/assert.sh19
-rwxr-xr-xtests/test1.sh7
-rwxr-xr-xtests/test2.sh9
-rwxr-xr-xtests/test3.sh9
-rwxr-xr-xtests/test4.sh9
5 files changed, 38 insertions, 15 deletions
diff --git a/tests/assert.sh b/tests/assert.sh
index ffd2b95..c7bcf1a 100755
--- a/tests/assert.sh
+++ b/tests/assert.sh
@@ -114,6 +114,25 @@ assert() {
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
}
+assert_iffound() {
+ (( tests_ran++ )) || :
+ [[ -z "$DISCOVERONLY" ]] || return
+ file=$1
+ pattern=$2
+ assert_ne_cond=$3
+ #echo ":$file."
+ #echo ":$pattern."
+ #echo ":$assert_ne_cond."
+ grepres="$(grep "$file" -e "$pattern" | grep -v "$assert_ne_cond")" || true
+ #echo $grepres
+ if [[ -z "$grepres" ]]; then
+ [[ -z "$DEBUG" ]] || echo -n .
+ return
+ fi
+ #echo leak found
+ _assert_fail "$grepres" $file "$1" "$3"
+}
+
assert_raises() {
# assert_raises <command> <expected code> [stdin]
(( tests_ran++ )) || :
diff --git a/tests/test1.sh b/tests/test1.sh
index 4283c7a..37d92aa 100755
--- a/tests/test1.sh
+++ b/tests/test1.sh
@@ -10,9 +10,10 @@ VALGRIND_CMD='valgrind -v --log-file=${NAME}_vallog --tool=memcheck --track-orig
. assert.sh
assert "echo GETNUM C2 | $VALGRIND_CMD ../src/sc-im ${NAME}.sc --nocurses --nodebug --quit_afterload 2>&1 |grep -v '^$\|Interp'" "81"
-#TODO: check valgrind log here
-#"in use at exit: 0 bytes in 0 blocks"
-#"All heap blocks were freed -- no leaks are possible"
+#we check valgrind log
+assert_iffound ${NAME}_vallog "definitely lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "indirectly lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "possibly lost.*bytes" "0 bytes"
rm ${NAME}_vallog
assert_end ${NAME}
diff --git a/tests/test2.sh b/tests/test2.sh
index ec906c7..f933668 100755
--- a/tests/test2.sh
+++ b/tests/test2.sh
@@ -10,9 +10,10 @@ VALGRIND_CMD='valgrind -v --log-file=${NAME}_vallog --tool=memcheck --track-orig
. assert.sh
assert "echo GETNUM C2 | $VALGRIND_CMD ../src/sc-im ${NAME}.sc --nocurses --nodebug --quit_afterload 2>&1 |grep -v '^$\|Interp\|left'" "81"
-#TODO: check valgrind log here
-#"in use at exit: 0 bytes in 0 blocks"
-#"All heap blocks were freed -- no leaks are possible"
-#rm ${NAME}_vallog
+#we check valgrind log
+assert_iffound ${NAME}_vallog "definitely lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "indirectly lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "possibly lost.*bytes" "0 bytes"
+rm ${NAME}_vallog
assert_end ${NAME}
diff --git a/tests/test3.sh b/tests/test3.sh
index 1216a2c..8e68a4f 100755
--- a/tests/test3.sh
+++ b/tests/test3.sh
@@ -10,9 +10,10 @@ VALGRIND_CMD='valgrind -v --log-file=${NAME}_vallog --tool=memcheck --track-orig
. assert.sh
assert "echo GETNUM A0 | $VALGRIND_CMD ../src/sc-im ${NAME}.sc --nocurses --nodebug --quit_afterload 2>&1 |grep -v '^$\|Interp\|left'" "3.3"
-#TODO: check valgrind log here
-#"in use at exit: 0 bytes in 0 blocks"
-#"All heap blocks were freed -- no leaks are possible"
-#rm ${NAME}_vallog
+#we check valgrind log
+assert_iffound ${NAME}_vallog "definitely lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "indirectly lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "possibly lost.*bytes" "0 bytes"
+rm ${NAME}_vallog
assert_end ${NAME}
diff --git a/tests/test4.sh b/tests/test4.sh
index f76e863..7cf29d1 100755
--- a/tests/test4.sh
+++ b/tests/test4.sh
@@ -12,9 +12,10 @@ VALGRIND_CMD='valgrind -v --log-file=${NAME}_vallog --tool=memcheck --track-orig
CMD='LET A2 = 1\nUNDO\nGETNUM A0\nGETNUM {"dos"}!B3'
assert "echo -e '${CMD}' | $VALGRIND_CMD ../src/sc-im ${NAME}.sc --nocurses --nodebug --quit_afterload 2>&1 |grep -v '^$\|Interp\|left\|Change'" "2.3\n0"
-#TODO: check valgrind log here
-#"in use at exit: 0 bytes in 0 blocks"
-#"All heap blocks were freed -- no leaks are possible"
-#rm ${NAME}_vallog
+#we check valgrind log
+assert_iffound ${NAME}_vallog "definitely lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "indirectly lost.*bytes" "0 bytes"
+assert_iffound ${NAME}_vallog "possibly lost.*bytes" "0 bytes"
+rm ${NAME}_vallog
assert_end ${NAME}