From 222368bf640a0b79d57322878dee42ed58b47bd6 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 14 Feb 2026 14:04:41 +0000 Subject: [PATCH] Stage one clean up of test files. Some unit tests are still creating temporary files in the project root directory, which is still to be fixed; and *I think* known-failing tests which I don't intend to fix immediately should be marked in some way. --- Makefile | 4 ++- src/arith/integer.c | 8 +++++- src/io/print.c | 10 ++----- unit-tests/apply.sh | 1 - unit-tests/bignum-add.sh | 36 ++++++++++++------------ unit-tests/bignum-subtract.sh | 18 ++++++------ unit-tests/complex-list.sh | 2 +- unit-tests/cond.sh | 4 +-- unit-tests/let.sh | 10 ++++--- unit-tests/list-test,sh | 42 ---------------------------- unit-tests/list-test.sh | 47 ++++++++++++++++++++++++++++++++ unit-tests/many-args.sh | 16 ++++++----- unit-tests/map.sh | 23 ++++++++-------- unit-tests/multiply.sh | 12 +++++--- unit-tests/nil.sh | 2 +- unit-tests/path-notation.sh | 11 ++++---- unit-tests/progn.sh | 10 ++++--- unit-tests/quote.sh | 2 +- unit-tests/quoted-list.sh | 2 +- unit-tests/ratio-addition.sh | 2 +- unit-tests/reverse.sh | 17 +++++++----- unit-tests/simple-list.sh | 2 +- unit-tests/slurp.sh | 4 +-- unit-tests/string-cons.sh | 12 ++++---- unit-tests/string-with-spaces.sh | 2 +- unit-tests/try.sh | 13 ++++++--- unit-tests/varargs.sh | 2 +- unit-tests/wide-character.sh | 2 +- 28 files changed, 172 insertions(+), 144 deletions(-) delete mode 100644 unit-tests/list-test,sh create mode 100644 unit-tests/list-test.sh diff --git a/Makefile b/Makefile index b4f9d3c..85c8b8f 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ TESTS := $(shell find unit-tests -name *.sh) INC_DIRS := $(shell find $(SRC_DIRS) -type d) INC_FLAGS := $(addprefix -I,$(INC_DIRS)) +TMP_DIR ?= ./tmp + INDENT_FLAGS := -nbad -bap -nbc -br -brf -brs -c33 -cd33 -ncdb -ce -ci4 -cli4 \ -d0 -di1 -nfc1 -i4 -ip0 -l75 -lp -npcs \ -npsl -nsc -nsob -nss -nut -prs -l79 -ts2 @@ -41,7 +43,7 @@ test: $(TESTS) Makefile $(TARGET) .PHONY: clean clean: - $(RM) $(TARGET) $(OBJS) $(DEPS) $(SRC_DIRS)/*~ $(SRC_DIRS)/*/*~ *~ core + $(RM) $(TARGET) $(OBJS) $(DEPS) $(SRC_DIRS)/*~ $(SRC_DIRS)/*/*~ $(TMP_DIR)/* *~ core repl: $(TARGET) -p 2> psse.log diff --git a/src/arith/integer.c b/src/arith/integer.c index 0247d0f..0e7cd6f 100644 --- a/src/arith/integer.c +++ b/src/arith/integer.c @@ -412,10 +412,16 @@ struct cons_pointer multiply_integers( struct cons_pointer a, struct cons_pointer integer_to_string_add_digit( int digit, int digits, struct cons_pointer tail ) { wint_t character = btowc( hex_digits[digit] ); - return ( digits % 3 == 0 ) ? + debug_printf( DEBUG_IO, L"integer_to_string_add_digit: digit is %d, digits is %d; returning: ", digit, digits); + struct cons_pointer r = ( digits % 3 == 0 ) ? make_string( L',', make_string( character, tail ) ) : make_string( character, tail ); + + debug_print_object( r, DEBUG_IO); + debug_println( DEBUG_IO); + + return r; } /** diff --git a/src/io/print.c b/src/io/print.c index f4aab9f..deea087 100644 --- a/src/io/print.c +++ b/src/io/print.c @@ -170,13 +170,9 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) { url_fputwc( L'>', output ); break; case INTEGERTV: - if ( nilp( cell.payload.integer.more)) { - url_fwprintf( output, L"%ld", cell.payload.integer.value); - } else { - struct cons_pointer s = integer_to_string( pointer, 10 ); - print_string_contents( output, s ); - dec_ref( s ); - } + struct cons_pointer s = integer_to_string( pointer, 10 ); + print_string_contents( output, s ); + dec_ref( s ); break; case KEYTV: url_fputws( L":", output ); diff --git a/unit-tests/apply.sh b/unit-tests/apply.sh index 63b76a3..aa8171a 100755 --- a/unit-tests/apply.sh +++ b/unit-tests/apply.sh @@ -18,7 +18,6 @@ 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" diff --git a/unit-tests/bignum-add.sh b/unit-tests/bignum-add.sh index c82dee6..aa0aef4 100755 --- a/unit-tests/bignum-add.sh +++ b/unit-tests/bignum-add.sh @@ -9,7 +9,7 @@ a=1152921504606846975 b=1 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1` @@ -23,8 +23,8 @@ else return=`echo "${return} + 1" | bc` fi -echo -n "checking no bignum was created: " -grep -v 'BIGNUM!' psse.log > /dev/null +echo -n "$0: checking no bignum was created: " +grep -v 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -40,7 +40,7 @@ a='1152921504606846976' b=1 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -56,7 +56,7 @@ else fi echo -n "$0 => checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -73,7 +73,7 @@ a='1152921504606846977' b=1 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -89,7 +89,7 @@ else fi echo -n "$0 => checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -106,7 +106,7 @@ a=1 b=1152921504606846977 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -121,8 +121,8 @@ else return=`echo "${return} + 1" | bc` fi -echo -n "checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +echo -n "$0 => checking a bignum was created: " +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -139,7 +139,7 @@ a=1152921504606846977 c=`echo "$a + $a" | bc` echo -n "$0 => adding $a to $a: " expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -160,7 +160,7 @@ a=1152921504606846977 c=`echo "$a * 5" | bc` echo -n "$0 => adding $a, $a $a, $a, $a: " expected='t' -output=`echo "(= (+ $a $a $a $a $a) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $a $a $a $a) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -183,7 +183,7 @@ a=10000000000000000000 b=10000000000000000000 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -199,7 +199,7 @@ else fi echo -n "$0 => checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -216,7 +216,7 @@ a=1 b=1329227995784915872903807060280344576 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -232,7 +232,7 @@ else fi echo -n "$0 => checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" @@ -250,7 +250,7 @@ a=1 b=3064991081731777716716694054300618367237478244367204352 c=`echo "$a + $b" | bc` expected='t' -output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>psse.log` +output=`echo "(= (+ $a $b) $c)" | target/psse -v 2 2>tmp/psse.log` actual=`echo $output |\ tail -1 |\ @@ -266,7 +266,7 @@ else fi echo -n "$0 => checking a bignum was created: " -grep 'BIGNUM!' psse.log > /dev/null +grep 'BIGNUM!' tmp/psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" diff --git a/unit-tests/bignum-subtract.sh b/unit-tests/bignum-subtract.sh index 19c673f..814d901 100755 --- a/unit-tests/bignum-subtract.sh +++ b/unit-tests/bignum-subtract.sh @@ -1,6 +1,6 @@ #!/bin/bash -return=0 +result=0 ##################################################################### # subtract a smallnum from a smallnum to produce a smallnum @@ -20,17 +20,17 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - return=1 + result=`echo "${result} + 1" | bc` fi -echo -n "checking no bignum was created: " +echo -n "$0 => checking no bignum was created: " grep -v 'BIGNUM!' psse.log > /dev/null if [ $? -eq "0" ] then echo "OK" else echo "Fail" - return=1 + result=`echo "${result} + 1" | bc` fi ##################################################################### @@ -51,7 +51,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - return=1 + result=`echo "${result} + 1" | bc` fi ##################################################################### @@ -71,7 +71,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - return=1 + result=`echo "${result} + 1" | bc` fi @@ -93,7 +93,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - return=1 + result=`echo "${result} + 1" | bc` fi ##################################################################### @@ -113,7 +113,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - return=1 + result=`echo "${result} + 1" | bc` fi -exit ${return} \ No newline at end of file +exit ${result} \ No newline at end of file diff --git a/unit-tests/complex-list.sh b/unit-tests/complex-list.sh index 3e84d79..6a6307b 100755 --- a/unit-tests/complex-list.sh +++ b/unit-tests/complex-list.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='(1 2 3 ("Fred") nil 77,354)' -actual=`echo "'(1 2 3 (\"Fred\") () 77354)" | target/psse | tail -1` +actual=`echo "'(1 2 3 (\"Fred\") () 77354)" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/cond.sh b/unit-tests/cond.sh index 4c4a66c..86f0e9f 100755 --- a/unit-tests/cond.sh +++ b/unit-tests/cond.sh @@ -12,7 +12,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi echo -n "$0: cond with two clauses... " @@ -25,7 +25,7 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} \ No newline at end of file diff --git a/unit-tests/let.sh b/unit-tests/let.sh index a4ab77f..037a96a 100755 --- a/unit-tests/let.sh +++ b/unit-tests/let.sh @@ -2,26 +2,28 @@ result=0 +echo -n "$0: let with two bindings, one form in body..." expected='11' -actual=`echo "(let ((a . 5)(b . 6)) (+ a b))" | target/psse | tail -1` +actual=`echo "(let ((a . 5)(b . 6)) (+ a b))" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '$expected', got '$actual'" - result=1 + result=`echo "${result} + 1" | bc` fi +echo -n "$0: let with two bindings, two forms in body..." expected='1' -actual=`echo "(let ((a . 5)(b . 6)) (+ a b) (- b a))" | target/psse | tail -1` +actual=`echo "(let ((a . 5)(b . 6)) (+ a b) (- b a))" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '$expected', got '$actual'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} \ No newline at end of file diff --git a/unit-tests/list-test,sh b/unit-tests/list-test,sh deleted file mode 100644 index 12fdd60..0000000 --- a/unit-tests/list-test,sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -result=0 - -expected="(0 1 2 3 4 5 6 7 8 9 a b c d e f)" - -actual=`echo "(list 0 1 2 3 4 5 6 7 8 9 'a 'b 'c 'd 'e 'f)" | target/psse | tail -1` - -if [ "${expected}" = "${actual}" ] -then - echo "OK" -else - echo "Fail: expected '$expected', got '$actual'" - result=1 -fi - -expected="(0 1 2 3 4)" - -actual=`echo "(list 0 1 2 3 4)" | target/psse | tail -1` - -if [ "${expected}" = "${actual}" ] -then - echo "OK" -else - echo "Fail: expected '$expected', got '$actual'" - result=1 -fi - -expected="(0 1 2 3 4 5 6 7)" - -actual=`echo "(list 0 1 2 3 4 5 6 7)" | target/psse | tail -1` - -if [ "${expected}" = "${actual}" ] -then - echo "OK" - exit 0 -else - echo "Fail: expected '$expected', got '$actual'" - result=1 -fi - -exit ${result} \ No newline at end of file diff --git a/unit-tests/list-test.sh b/unit-tests/list-test.sh new file mode 100644 index 0000000..ef94631 --- /dev/null +++ b/unit-tests/list-test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +result=0 + +echo -n "$0: flat list with 16 elements... " +expected="(0 1 2 3 4 5 6 7 8 9 a b c d e f)" + +actual=`echo "(list 0 1 2 3 4 5 6 7 8 9 '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'" + result=`echo "${result} + 1" | bc` +fi + +echo -n "$0: flat list with 5 elements... " +expected="(0 1 2 3 4)" + +actual=`echo "(list 0 1 2 3 4)" | 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 + +echo -n "$0: flat list with 8 elements... " +expected="(0 1 2 3 4 5 6 7)" + +actual=`echo "(list 0 1 2 3 4 5 6 7)" | target/psse 2>/dev/null | tail -1` + +if [ "${expected}" = "${actual}" ] +then + echo "OK" + exit 0 +else + echo "Fail: expected '$expected', got '$actual'" + result=`echo "${result} + 1" | bc` +fi + +exit ${result} \ No newline at end of file diff --git a/unit-tests/many-args.sh b/unit-tests/many-args.sh index 449f7d8..bbbb6e8 100755 --- a/unit-tests/many-args.sh +++ b/unit-tests/many-args.sh @@ -1,28 +1,30 @@ #!/bin/bash -result=1 +result=0 + +echo -n "$0: plus with fifteen arguments... " expected="120" -actual=`echo "(+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)" | target/psse | tail -1` +actual=`echo "(+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi -# check that all the args are actually being evaluated... +echo -n "$0: check that all the args are actually being evaluated... " expected="120" -actual=`echo "(+ (+ 0 1) (+ 0 2) (+ 0 3) (+ 0 4) (+ 0 5) (+ 0 6) (+ 0 7) (+ 0 8) (+ 0 9) (+ 0 10) (+ 0 11) (+ 0 12) (+ 0 13) (+ 0 14 ) (+ 0 15))" | target/psse | tail -1` +actual=`echo "(+ (+ 0 1) (+ 0 2) (+ 0 3) (+ 0 4) (+ 0 5) (+ 0 6) (+ 0 7) (+ 0 8) (+ 0 9) (+ 0 10) (+ 0 11) (+ 0 12) (+ 0 13) (+ 0 14 ) (+ 0 15))" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi -return ${result} +exit ${result} diff --git a/unit-tests/map.sh b/unit-tests/map.sh index 90857ef..0e698f0 100755 --- a/unit-tests/map.sh +++ b/unit-tests/map.sh @@ -5,9 +5,9 @@ result=0 ##################################################################### # Create an empty map using map notation expected='{}' -actual=`echo "$expected" | target/psse | tail -1` +actual=`echo "$expected" | target/psse 2>/dev/null | tail -1` -echo -n "Empty map using compact map notation: " +echo -n "$0: Empty map using compact map notation... " if [ "${expected}" = "${actual}" ] then echo "OK" @@ -19,7 +19,7 @@ fi ##################################################################### # Create an empty map using make-map expected='{}' -actual=`echo "(hashmap)" | target/psse | tail -1` +actual=`echo "(hashmap)" | target/psse 2>/dev/null | tail -1` echo -n "Empty map using (make-map): " if [ "${expected}" = "${actual}" ] @@ -35,9 +35,9 @@ fi # significant at this stage, but in the long term should be sorted # alphanumerically expected='{:one 1, :two 2, :three 3}' -actual=`echo "{:one 1 :two 2 :three 3}" | target/psse | tail -1` +actual=`echo "{:one 1 :two 2 :three 3}" | target/psse 2>/dev/null | tail -1` -echo -n "Map using map notation: " +echo -n "$0: Map using map notation... " if [ "${expected}" = "${actual}" ] then echo "OK" @@ -51,9 +51,10 @@ fi # significant at this stage, but in the long term should be sorted # alphanumerically expected='{:one 1, :two 2, :three 3}' -actual=`echo "(hashmap nil nil '((:one . 1)(:two . 2)(:three . 3)))" | target/psse | tail -1` +actual=`echo "(hashmap nil nil '((:one . 1)(:two . 2)(:three . 3)))" |\ + target/psse 2>/dev/null | tail -1` -echo -n "Map using (hashmap): " +echo -n "$0: Map using (hashmap) with arguments... " if [ "${expected}" = "${actual}" ] then echo "OK" @@ -65,9 +66,9 @@ fi ##################################################################### # Keyword in function position expected='2' -actual=`echo "(:two {:one 1 :two 2 :three 3})" | target/psse | tail -1` +actual=`echo "(:two {:one 1 :two 2 :three 3})" | target/psse 2>/dev/null | tail -1` -echo -n "Keyword in function position: " +echo -n "$0: Keyword in function position... " if [ "${expected}" = "${actual}" ] then echo "OK" @@ -80,9 +81,9 @@ fi ##################################################################### # Map in function position expected='2' -actual=`echo "({:one 1 :two 2 :three 3} :two)" | target/psse | tail -1` +actual=`echo "({:one 1 :two 2 :three 3} :two)" | target/psse 2>/dev/null | tail -1` -echo -n "Map in function position: " +echo -n "$0: Map in function position... " if [ "${expected}" = "${actual}" ] then echo "OK" diff --git a/unit-tests/multiply.sh b/unit-tests/multiply.sh index aeac7e8..1e2da1f 100755 --- a/unit-tests/multiply.sh +++ b/unit-tests/multiply.sh @@ -2,26 +2,30 @@ result=0 +echo -n "$0: multiply two integers... " + expected='6' -actual=`echo "(multiply 2 3)" | target/psse | tail -1` +actual=`echo "(multiply 2 3)" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi +echo -n "$0: multiply a real by an integer... " + expected='7.5' -actual=`echo "(multiply 2.5 3)" | target/psse | tail -1` +actual=`echo "(multiply 2.5 3)" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} \ No newline at end of file diff --git a/unit-tests/nil.sh b/unit-tests/nil.sh index fcbf530..c15f0b1 100755 --- a/unit-tests/nil.sh +++ b/unit-tests/nil.sh @@ -1,7 +1,7 @@ #!/bin/bash expected=nil -actual=`echo 'nil' | target/psse | tail -1` +actual=`echo 'nil' | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/path-notation.sh b/unit-tests/path-notation.sh index 70610b0..cbb9dea 100755 --- a/unit-tests/path-notation.sh +++ b/unit-tests/path-notation.sh @@ -4,8 +4,9 @@ result=0 ##################################################################### # Create a path from root using compact path notation +echo -n "$0: Create a path from root using compact path notation... " expected='(-> oblist :users :simon :functions (quote assoc))' -actual=`echo "'/:users:simon:functions/assoc" | target/psse | tail -1` +actual=`echo "'/:users:simon:functions/assoc" | target/psse 2>&1 | tail -1` echo -n "Path from root (oblist) using compact notation: " if [ "${expected}" = "${actual}" ] @@ -13,21 +14,21 @@ then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi ##################################################################### # Create a path from the current session using compact path notation +echo -n "$0: Create a path from the current session using compact path notation... " expected='(-> session :input-stream)' -actual=`echo "'$:input-stream" | target/psse | tail -1` +actual=`echo "'$:input-stream" | target/psse 2>/dev/null | tail -1` -echo -n "Path from current session using compact notation: " if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} diff --git a/unit-tests/progn.sh b/unit-tests/progn.sh index b9b44eb..ea6cf7b 100755 --- a/unit-tests/progn.sh +++ b/unit-tests/progn.sh @@ -2,26 +2,28 @@ result=0 +echo -n "$0: progn with one form... " expected='5' -actual=`echo "(progn (add 2 3))" | target/psse | tail -1` +actual=`echo "(progn (add 2 3))" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi +echo -n "$0: progn with two forms... " expected='"foo"' -actual=`echo "(progn (add 2.5 3) \"foo\")" | target/psse | tail -1` +actual=`echo "(progn (add 2.5 3) \"foo\")" | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} diff --git a/unit-tests/quote.sh b/unit-tests/quote.sh index 78d4ce5..d98e215 100755 --- a/unit-tests/quote.sh +++ b/unit-tests/quote.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='Fred' -actual=`echo "'Fred" | target/psse | tail -1` +actual=`echo "'Fred" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/quoted-list.sh b/unit-tests/quoted-list.sh index f69cd75..ade7b2a 100755 --- a/unit-tests/quoted-list.sh +++ b/unit-tests/quoted-list.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='(123 (4 (5 nil)) Fred)' -actual=`echo "'(123 (4 (5 ())) Fred)" | target/psse | tail -1` +actual=`echo "'(123 (4 (5 ())) Fred)" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/ratio-addition.sh b/unit-tests/ratio-addition.sh index ba93c5d..5e5bc7e 100755 --- a/unit-tests/ratio-addition.sh +++ b/unit-tests/ratio-addition.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='1/4' -actual=`echo "(+ 3/14 1/28)" | target/psse | tail -1` +actual=`echo "(+ 3/14 1/28)" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/reverse.sh b/unit-tests/reverse.sh index bbc3216..a0eb01c 100755 --- a/unit-tests/reverse.sh +++ b/unit-tests/reverse.sh @@ -2,30 +2,33 @@ result=0 +echo -n "$0: reverse a string... " expected='"god yzal eht revo depmuj xof nworb kciuq ehT"' -actual=`echo '(reverse "The quick brown fox jumped over the lazy dog")' | target/psse | tail -1` +actual=`echo '(reverse "The quick brown fox jumped over the lazy dog")' | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi +echo -n "$0: reverse a list... " expected='(1,024 512 256 128 64 32 16 8 4 2)' -actual=`echo "(reverse '(2 4 8 16 32 64 128 256 512 1024))" | target/psse | tail -1` +actual=`echo "(reverse '(2 4 8 16 32 64 128 256 512 1024))" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi +echo -n "$0: reverse a symbol... " expected='esrever' -actual=`echo "(reverse 'reverse)" | target/psse | tail -1` +actual=`echo "(reverse 'reverse)" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then @@ -33,8 +36,8 @@ then exit 0 else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi -echo ${result} +exit ${result} diff --git a/unit-tests/simple-list.sh b/unit-tests/simple-list.sh index daf3db2..6fb7e5d 100755 --- a/unit-tests/simple-list.sh +++ b/unit-tests/simple-list.sh @@ -1,7 +1,7 @@ #!/bin/bash expected="(1 2 3)" -actual=`echo "'(1 2 3)" | target/psse | tail -1` +actual=`echo "'(1 2 3)" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/slurp.sh b/unit-tests/slurp.sh index 700df15..1b0b888 100755 --- a/unit-tests/slurp.sh +++ b/unit-tests/slurp.sh @@ -1,9 +1,9 @@ #!/bin/bash -tmp=hi.$$ +tmp=tmp/hi.$$ echo "Hello, there." > ${tmp} expected='"Hello, there.' -actual=`echo "(slurp (open \"${tmp}\"))" | target/psse | tail -2 | head -1` +actual=`echo "(slurp (open \"${tmp}\"))" | target/psse 2>&1 | tail -2 | head -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/string-cons.sh b/unit-tests/string-cons.sh index ad6e3d2..918dbc6 100755 --- a/unit-tests/string-cons.sh +++ b/unit-tests/string-cons.sh @@ -2,28 +2,28 @@ result=0 -# We should be able to cons a single character string onto the front of a string +echo -n "$0: We should be able to cons a single character string onto the front of a string... " expected='"Test"' -actual=`echo '(cons "T" "est")' | target/psse | tail -1` +actual=`echo '(cons "T" "est")' | target/psse 2>/dev/null | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi -# But if the first argument has more than one character, we should get a dotted pair +echo -n "$0: But if the first argument has more than one character, we should get a dotted pair... " expected='("Test" . "pass")' -actual=`echo '(cons "Test" "pass")' | target/psse | tail -1` +actual=`echo '(cons "Test" "pass")' | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then echo "OK" else echo "Fail: expected '${expected}', got '${actual}'" - result=1 + result=`echo "${result} + 1" | bc` fi exit ${result} diff --git a/unit-tests/string-with-spaces.sh b/unit-tests/string-with-spaces.sh index 0f0f6d0..6a424fb 100755 --- a/unit-tests/string-with-spaces.sh +++ b/unit-tests/string-with-spaces.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='"Strings should be able to include spaces (and other stuff)!"' -actual=`echo ${expected} | target/psse | tail -1` +actual=`echo ${expected} | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/try.sh b/unit-tests/try.sh index c70c4d8..43e35ad 100755 --- a/unit-tests/try.sh +++ b/unit-tests/try.sh @@ -2,8 +2,9 @@ result=0 +echo -n "$0: if the body of a try errors, the last form in the catch block is returned... " expected=':foo' -actual=`echo "(try ((+ 2 (/ 1 'a))) (:foo))" | target/psse | tail -1` +actual=`echo "(try ((+ 2 (/ 1 'a))) (:foo))" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then @@ -13,8 +14,10 @@ else return=`echo "${return} + 1" | bc` fi +echo -n "$0: if the body of a try errors, the last form in the catch block is evaluated... " + expected='4' -actual=`echo "(try ((+ 2 (/ 1 'a))) ((+ 2 2)))" | target/psse | tail -1` +actual=`echo "(try ((+ 2 (/ 1 'a))) ((+ 2 2)))" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then @@ -24,8 +27,9 @@ else return=`echo "${return} + 1" | bc` fi +echo -n "$0: body and catch block can optionally be marked with keywords... " expected='8' -actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch (* 2 2 2)))" | target/psse | tail -1` +actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch (* 2 2 2)))" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then @@ -35,8 +39,9 @@ else return=`echo "${return} + 1" | bc` fi +echo -n "$0: the exception is bound to the symbol \`*exception*\` in the catch environment... " expected='Exception: "Cannot divide: not a number"' -actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch *exception*))" | target/psse | grep Exception` +actual=`echo "(try (:body (+ 2 (/ 1 'a))) (:catch *exception*))" | target/psse 2>&1 | grep Exception` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/varargs.sh b/unit-tests/varargs.sh index 27bac3e..45ff627 100755 --- a/unit-tests/varargs.sh +++ b/unit-tests/varargs.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='(1 2 3 4 5 6 7 8 9 10)' -actual=`echo "(set! list (lambda l l))(list 1 2 3 4 5 6 7 8 9 10)" |target/psse | tail -1` +actual=`echo "(set! list (lambda l l))(list 1 2 3 4 5 6 7 8 9 10)" | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then diff --git a/unit-tests/wide-character.sh b/unit-tests/wide-character.sh index d56544e..57dced6 100755 --- a/unit-tests/wide-character.sh +++ b/unit-tests/wide-character.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='"λάμ(β)δα"' -actual=`echo $expected | target/psse | tail -1` +actual=`echo $expected | target/psse 2>&1 | tail -1` if [ "${expected}" = "${actual}" ] then