commit 7c1bfa0f19e559ce0a205f1bff8fc1c5d59937dd
parent ef3108dfd09b0f3d123ffb9157849ef021313354
Author: Ed van Bruggen <edvb@uw.edu>
Date: Wed, 28 Mar 2018 21:53:14 -0700
Add tests
Diffstat:
22 files changed, 198 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -57,6 +57,10 @@ uninstall:
@rm -f $(DESTDIR)$(MANPREFIX)/man1/$(EXE).1
@echo \ done
+test: $(EXE)
+ @echo running tests
+ @cd t && ./t
+
man:
@echo -n updating man page $(EXE).1 ...
@(head -1 README.md | sed "s/$(EXE)/$(EXE) 1 \"`date +%B\ %Y`\" \"$(EXE)\ $(VERSION)\"\n\n##NAME\n\n&/"; \
diff --git a/t/math/add.expect b/t/math/add.expect
@@ -0,0 +1,6 @@
+2
+6
+6
+6
+6
+4369
diff --git a/t/math/add.tsp b/t/math/add.tsp
@@ -0,0 +1,6 @@
+(+ 1 1)
+(+ 1 2 3)
+(+ 1 2 (+ 1 2))
+(+ 1 (+ 1 2) 2)
+(+ (+ 1 2) 1 2)
+(+ 1029 283 1928 28 189 912)
diff --git a/t/prim/cond.expect b/t/prim/cond.expect
@@ -0,0 +1,8 @@
+()
+1
+1
+3
+2
+()
+2
+()
diff --git a/t/prim/cond.tsp b/t/prim/cond.tsp
@@ -0,0 +1,8 @@
+(cond)
+(cond (t 1))
+(cond ((= 1 1) 1) ((= 1 2) 2) (t 3))
+(cond ((= 1 2) 1) ((= 1 2) 2) (t (+ 1 2)))
+(cond ((= 1 2) 1) ((= 1 1) 2) (t 3))
+(cond ((= 1 2) 1) ((= 1 3) 2))
+(cond ((= 1 2) 1) ("foo" 2) (t 3))
+(cond (() (+ 1 2)))
diff --git a/t/prim/cons.expect b/t/prim/cons.expect
@@ -0,0 +1,6 @@
+(1 . 2)
+(1 2 . 3)
+(1 2 3 . 4)
+("foo" . "bar")
+(3 . 3)
+((1 . 2) 3 . 4)
diff --git a/t/prim/cons.tsp b/t/prim/cons.tsp
@@ -0,0 +1,6 @@
+(cons 1 2)
+(cons 1 (cons 2 3))
+(cons 1 (cons 2 (cons 3 4)))
+(cons "foo" "bar")
+(cons (+ 1 2) 3)
+(cons (cons 1 2) (cons 3 4))
diff --git a/t/prim/cxr.expect b/t/prim/cxr.expect
@@ -0,0 +1,11 @@
+1
+2
+1
+2
+3
+4
+(2 3 4)
+(3 4)
+1
+(2 . 3)
+3
diff --git a/t/prim/cxr.tsp b/t/prim/cxr.tsp
@@ -0,0 +1,14 @@
+(car (cons 1 2))
+(cdr (cons 1 2))
+
+(car (quote (1 2 3 4)))
+(car (cdr (quote (1 2 3 4))))
+(car (cdr (cdr (quote (1 2 3 4)))))
+(car (cdr (cdr (cdr (quote (1 2 3 4))))))
+
+(cdr (quote (1 2 3 4)))
+(cdr (cdr (quote (1 2 3 4))))
+
+(car (cons 1 (cons 2 3)))
+(cdr (cons 1 (cons 2 3)))
+(cdr (cdr (cons 1 (cons 2 3))))
diff --git a/t/prim/define.expect b/t/prim/define.expect
@@ -0,0 +1,6 @@
+4
+4
+4
+4
+#<primitive>
+8
diff --git a/t/prim/define.tsp b/t/prim/define.tsp
@@ -0,0 +1,6 @@
+(define foo 4)
+foo
+(define bar foo)
+bar
+(define add +)
+(add foo bar)
diff --git a/t/prim/eq.expect b/t/prim/eq.expect
@@ -0,0 +1,21 @@
+t
+t
+t
+t
+t
+()
+()
+()
+()
+t
+t
+()
+t
+()
+()
+()
+()
+t
+t
+()
+t
diff --git a/t/prim/eq.tsp b/t/prim/eq.tsp
@@ -0,0 +1,21 @@
+(=)
+(= 1)
+(= "foo")
+(= 1 1)
+(= 1 1 1 1 1 1)
+(= 1 2)
+(= 1 1 2 1 1 1)
+(= 1 1 1 1 1 2)
+(= 2 1 1 1 1 1)
+(= (+ 1 1) (+ 2 0))
+(= "foo" "foo")
+(= "foo" "bar")
+(= "foo" "foo" "foo" "foo" "foo")
+(= "foo" "bar" "foo" "foo" "foo")
+(= "foo" 3)
+(= "foo" "foo" 4 "foo" "foo")
+(= "foo" "FOO")
+(= t t)
+(= car car)
+(= car cdr)
+(= quote quote quote)
diff --git a/t/prim/lambda.expect b/t/prim/lambda.expect
@@ -0,0 +1,5 @@
+3
+6
+9
+4
+5
diff --git a/t/prim/lambda.tsp b/t/prim/lambda.tsp
@@ -0,0 +1,5 @@
+((lambda (x) x) 3)
+((lambda (x) x) (+ 1 2 3))
+((lambda (x) (+ x 1)) 8)
+((lambda (a b) (+ a b)) 2 2)
+((lambda () 5))
diff --git a/t/prim/quote.expect b/t/prim/quote.expect
@@ -0,0 +1,7 @@
+1
+9234
+"foo"
+bar
+(1 2 3 4)
+(quote 1)
+(+ 2 2)
diff --git a/t/prim/quote.tsp b/t/prim/quote.tsp
@@ -0,0 +1,7 @@
+(quote 1)
+(quote 9234)
+(quote "foo")
+(quote bar)
+(quote (1 2 3 4))
+(quote (quote 1))
+(quote (+ 2 2))
diff --git a/t/simple/comments.expect b/t/simple/comments.expect
@@ -0,0 +1,2 @@
+3
+4
diff --git a/t/simple/comments.tsp b/t/simple/comments.tsp
@@ -0,0 +1,11 @@
+; commment
+; (+ 1 1)
+(+ 1 1 ; more comments
+ 1)
+
+ ; white space too
+ (+ 2 2)
+
+
+
+; another comment
diff --git a/t/simple/self.expect b/t/simple/self.expect
@@ -0,0 +1,8 @@
+1
+2
+0
+30
+12
+"foo"
+"foo bar"
+t
diff --git a/t/simple/self.tsp b/t/simple/self.tsp
@@ -0,0 +1,8 @@
+1
+2
+0
+30
+12
+"foo"
+"foo bar"
+t
diff --git a/t/t b/t/t
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+total=0
+pass=0
+
+for file in */*.tsp; do
+ expect=${file%.tsp}.expect
+
+ echo -n "testing $file ... "
+ if [[ $(../tisp "$file" 2>&1 | diff -q "$expect" - 2>&1 ) ]]; then
+ echo fail
+ else
+ echo ok
+ ((pass++))
+ fi
+ ((total++))
+done
+
+echo "$pass/$total tests passed"
+
+[[ $pass == $total ]] && exit 0
+exit 1