Fixed the horrendous 'unbound symbol nil' bug. Also work on documentation and

unit tests.
This commit is contained in:
Simon Brooke 2026-02-14 11:40:52 +00:00
parent 3659103dd7
commit 5e6363e6ae
17 changed files with 328 additions and 143 deletions

View file

@ -1,79 +1,92 @@
#!/bin/bash
result=0;
echo -n "$0: Add two small integers... "
expected='5'
actual=`echo "(add 2 3)" | target/psse | tail -1`
actual=`echo "(add 2 3)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Add float to integer... "
expected='5.5'
actual=`echo "(add 2.5 3)" | target/psse | tail -1`
actual=`echo "(add 2.5 3)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
exit 0
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Add two rationals... "
expected='1/4'
actual=`echo "(+ 3/14 1/28)" | target/psse | tail -1`
actual=`echo "(+ 3/14 1/28)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Add an integer to a rational... "
# (+ integer ratio) should be ratio
expected='25/4'
actual=`echo "(+ 6 1/4)" | target/psse | tail -1`
actual=`echo "(+ 6 1/4)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Add a rational to an integer... "
# (+ ratio integer) should be ratio
expected='25/4'
actual=`echo "(+ 1/4 6)" | target/psse | tail -1`
actual=`echo "(+ 1/4 6)" | target/psse 2>/dev/null | sed -r '/^\s*$/d' | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Add a real to a rational... "
# (+ real ratio) should be real
# for this test, trailing zeros can be ignored
expected='6.25'
actual=`echo "(+ 6.000000001 1/4)" |\
target/psse 2> /dev/null |\
sed 's/0*$//' |\
head -2 |\
tail -1`
sed -r '/^\s*$/d' |\
sed 's/0*$//'
outcome=`echo "sqrt((${expected} - ${actual})^2) < 0.0000001" | bc`
if [ "${outcome}" = "1" ]
if [ "${outcome}" -eq "1" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc `
fi
exit ${result}

View file

@ -1,24 +1,44 @@
#!/bin/bash
return=0;
echo -n "$0: Append two lists... "
expected='(a b c d e f)'
actual=`echo "(append '(a b c) '(d e f))" | target/psse | tail -1`
actual=`echo "(append '(a b c) '(d e f))" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0: Append two strings... "
expected='"hellodere"'
actual=`echo '(append "hello" "dere")' | target/psse | tail -1`
actual=`echo '(append "hello" "dere")' | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0: Append keyword to string should error... "
expected='Exception:'
actual=`echo '(append "hello" :dere)' | target/psse 2>/dev/null | sed -r '/^\s*$/d' | awk '{print $1}'`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=`echo "${return} + 1" | bc`
fi
exit ${return}

View file

@ -1,13 +1,30 @@
#!/bin/bash
result=1
echo -n "$0: Apply function to one argument... "
expected='1'
actual=`echo "(apply 'add '(1))"| target/psse | tail -1`
actual=`echo "(apply 'add '(1))"| target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
exit 0
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
result=`echo "${result} + 1" | bc`
fi
echo -n "$0: Apply function to multiple arguments... "
expected='3'
actual=`echo "(apply 'add '(1 2))"| target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
result=`echo "${result} + 1" | bc`
fi
exit ${result}

View file

@ -20,7 +20,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "checking no bignum was created: "
@ -30,7 +30,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
#####################################################################
@ -52,7 +52,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0 => checking a bignum was created: "
@ -62,7 +62,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
@ -85,7 +85,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0 => checking a bignum was created: "
@ -95,7 +95,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
#####################################################################
@ -118,7 +118,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "checking a bignum was created: "
@ -128,7 +128,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
@ -150,7 +150,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
#####################################################################
@ -171,7 +171,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
@ -195,7 +195,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0 => checking a bignum was created: "
@ -205,7 +205,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
@ -228,7 +228,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0 => checking a bignum was created: "
@ -238,7 +238,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
@ -262,7 +262,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
return=1
return=`echo "${return} + 1" | bc`
fi
echo -n "$0 => checking a bignum was created: "
@ -272,7 +272,7 @@ then
echo "OK"
else
echo "Fail"
return=1
return=`echo "${return} + 1" | bc`
fi
exit ${return}

View file

@ -2,8 +2,10 @@
result=0
echo -n "$0: cond with one clause... "
expected='5'
actual=`echo "(cond ((equal 2 2) 5))" | target/psse | tail -1`
actual=`echo "(cond ((equal 2 2) 5))" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then
@ -13,8 +15,10 @@ else
result=1
fi
echo -n "$0: cond with two clauses... "
expected='"should"'
actual=`echo "(cond ((equal 2 3) \"shouldn't\")(t \"should\"))" | target/psse | tail -1`
actual=`echo "(cond ((equal 2 3) \"shouldn't\")(t \"should\"))" | target/psse 2>/dev/null | tail -1`
if [ "${expected}" = "${actual}" ]
then

View file

@ -1,5 +1,7 @@
#!/bin/bash
result=0
expected=':foo'
actual=`echo "(try ((+ 2 (/ 1 'a))) (:foo))" | target/psse | tail -1`
@ -8,7 +10,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
expected='4'
@ -19,7 +21,7 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
expected='8'
@ -30,16 +32,18 @@ then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
expected=''
actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch *exception*))" | target/psse | tail -1`
expected='Exception: "Cannot divide: not a number"'
actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch *exception*))" | target/psse | grep Exception`
if [ "${expected}" = "${actual}" ]
then
echo "OK"
else
echo "Fail: expected '${expected}', got '${actual}'"
exit 1
return=`echo "${return} + 1" | bc`
fi
exit ${result}