diff --git a/src/Makefile b/src/Makefile index 73a0fd3..78152fe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,9 @@ all: gcc -g -O0 -o pebblisp -D STANDALONE pebblisp.c tokens.c object.c env.c && ./tests.sh +val: + gcc -g -O0 -o pebblisp -D STANDALONE pebblisp.c tokens.c object.c env.c && ./tests.sh -val + debug: gcc -g -O0 -o pebblisp -D STANDALONE -D DEBUG pebblisp.c tokens.c object.c env.c && ./tests.sh diff --git a/src/tests.sh b/src/tests.sh index 3267f16..5ba1a63 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -1,6 +1,11 @@ #!/bin/bash PASSES=0 FAILS=0 +VALGRIND=0 + +if [ "$1" == "-val" ]; then + VALGRIND=1 +fi pass() { echo "$1 test PASSED" @@ -13,7 +18,13 @@ fail() { } check() { - local output=$(./pebblisp "$2") + local output + if (($VALGRIND == 1)); then + local output=$(valgrind --leak-check=full ./pebblisp "$2") + else + local output=$(./pebblisp "$2") + fi + if [ "$output" == "$3" ]; then pass $1 else @@ -22,7 +33,8 @@ check() { fi } -check "PlainRet" "5" "5" +check "PlainRet" "10" "10" +check "StrRetrn" "\"hey\"" "hey" echo "" check "Addition" "(+ 1093 102852)" "103945" check "Multiply" "(*1000 10000)" "10000000" @@ -57,7 +69,12 @@ check "DemoFunc" "(spent 68)" "Tip: \$13.60" echo "" check "MultStmt" "(def yee (fn (a) (* 10 a))) (yee 5)" "50" check "DefinMap" "(def yee (fn (a) (* 10 a))) (map yee (5 10 2 (+ 12 0)))" "( 50 100 20 120 )" - +check "FbnciSeq" "(def fib (fn (a) \ + (if (< a 2) \ + a \ + (+ (fib (- a 1)) (fib (- a 2))) \ + ))) \ + (fib 20)" "6765" echo "" if [ "$FAILS" -ne "0" ]; then