summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-18 18:36:57 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-18 18:36:57 +0100
commit481884fb892f949478dad8d801ced704baea986c (patch)
tree8c5bcf1d306c8ad3d39d449da8def74cb24dca2d
parent4746aa52f85f4dc3ce8e195f0a5fd8afe2d54378 (diff)
Automatic testing of examples
-rw-r--r--closuretest.lisp1
-rw-r--r--stdlib.lisp3
-rwxr-xr-xtest.sh9
-rw-r--r--tests/closuretest.lisp7
-rw-r--r--tests/closuretest.out2
-rw-r--r--tests/data.lisp (renamed from data.lisp)0
-rw-r--r--tests/data.out5
-rw-r--r--tests/disabled/match.lisp (renamed from match.lisp)0
-rw-r--r--tests/f.lisp (renamed from f.lisp)0
-rw-r--r--tests/f.out5
-rw-r--r--tests/fibo.lisp (renamed from fibo.lisp)0
-rw-r--r--tests/fibo.out25
-rw-r--r--tests/fiboY.lisp (renamed from fiboY.lisp)0
-rw-r--r--tests/fiboY.out25
-rw-r--r--tests/filetest.lisp3
-rw-r--r--tests/filetest.out4
-rw-r--r--tests/let-fail.lisp8
-rw-r--r--tests/let-fail.out1
-rw-r--r--tests/stdlib.lisp28
-rw-r--r--tests/stdlib.out0
-rw-r--r--tests/symbols.lisp (renamed from symbols.lisp)0
-rw-r--r--tests/symbols.out3
22 files changed, 125 insertions, 4 deletions
diff --git a/closuretest.lisp b/closuretest.lisp
deleted file mode 100644
index 5d96c7f..0000000
--- a/closuretest.lisp
+++ /dev/null
@@ -1 +0,0 @@
-(print (((lambda (x) (lambda (y) (+ x y))) 1) 2))
diff --git a/stdlib.lisp b/stdlib.lisp
deleted file mode 100644
index b691a0a..0000000
--- a/stdlib.lisp
+++ /dev/null
@@ -1,3 +0,0 @@
-(define cadr (x) (car (cdr x)))
-(define caddr (x) (car (cdr (cdr x))))
-(define cadddr (x) (car (cdr (cdr (cdr x)))))
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..6b1971f
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+set -euo pipefail
+stack build
+prog="$(stack path --local-install-root)/bin/lisp"
+for f in tests/*.lisp; do
+ echo "$f"
+ diff -u <("$prog" "$f") "$(sed 's/\.lisp$/.out/' <<<"$f")"
+done
+echo "All OK"
diff --git a/tests/closuretest.lisp b/tests/closuretest.lisp
new file mode 100644
index 0000000..d743481
--- /dev/null
+++ b/tests/closuretest.lisp
@@ -0,0 +1,7 @@
+(print (((lambda (x) (lambda (y) (+ x y))) 1) 2))
+
+((lambda (f)
+ ((lambda (g1 g2)
+ (print (g1 10) (g1 20)))
+ (f 42)))
+ (lambda (x) (lambda (y) (+ x y))))
diff --git a/tests/closuretest.out b/tests/closuretest.out
new file mode 100644
index 0000000..542797d
--- /dev/null
+++ b/tests/closuretest.out
@@ -0,0 +1,2 @@
+3
+52, 62
diff --git a/data.lisp b/tests/data.lisp
index 1e77aae..1e77aae 100644
--- a/data.lisp
+++ b/tests/data.lisp
diff --git a/tests/data.out b/tests/data.out
new file mode 100644
index 0000000..40c5dd4
--- /dev/null
+++ b/tests/data.out
@@ -0,0 +1,5 @@
+1
+2
+3
+[1,2,3,4,5,6]
+[1,2,3,4,5,6]
diff --git a/match.lisp b/tests/disabled/match.lisp
index 84503e0..84503e0 100644
--- a/match.lisp
+++ b/tests/disabled/match.lisp
diff --git a/f.lisp b/tests/f.lisp
index 5644138..5644138 100644
--- a/f.lisp
+++ b/tests/f.lisp
diff --git a/tests/f.out b/tests/f.out
new file mode 100644
index 0000000..297955d
--- /dev/null
+++ b/tests/f.out
@@ -0,0 +1,5 @@
+42
+kaas
+ja
+iets
+iets, iets
diff --git a/fibo.lisp b/tests/fibo.lisp
index 3beae63..3beae63 100644
--- a/fibo.lisp
+++ b/tests/fibo.lisp
diff --git a/tests/fibo.out b/tests/fibo.out
new file mode 100644
index 0000000..14950e3
--- /dev/null
+++ b/tests/fibo.out
@@ -0,0 +1,25 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+144
+233
+377
+610
+987
+1597
+2584
+4181
+6765
+10946
+17711
+28657
+46368
+75025
diff --git a/fiboY.lisp b/tests/fiboY.lisp
index d12a5ab..d12a5ab 100644
--- a/fiboY.lisp
+++ b/tests/fiboY.lisp
diff --git a/tests/fiboY.out b/tests/fiboY.out
new file mode 100644
index 0000000..14950e3
--- /dev/null
+++ b/tests/fiboY.out
@@ -0,0 +1,25 @@
+1
+1
+2
+3
+5
+8
+13
+21
+34
+55
+89
+144
+233
+377
+610
+987
+1597
+2584
+4181
+6765
+10946
+17711
+28657
+46368
+75025
diff --git a/tests/filetest.lisp b/tests/filetest.lisp
new file mode 100644
index 0000000..b37d2fe
--- /dev/null
+++ b/tests/filetest.lisp
@@ -0,0 +1,3 @@
+#include "stdlib.lisp"
+
+(print (read-file "tests/filetest.lisp"))
diff --git a/tests/filetest.out b/tests/filetest.out
new file mode 100644
index 0000000..7d444f6
--- /dev/null
+++ b/tests/filetest.out
@@ -0,0 +1,4 @@
+#include "stdlib.lisp"
+
+(print (read-file "tests/filetest.lisp"))
+
diff --git a/tests/let-fail.lisp b/tests/let-fail.lisp
new file mode 100644
index 0000000..005cfc9
--- /dev/null
+++ b/tests/let-fail.lisp
@@ -0,0 +1,8 @@
+(print
+ (
+ (lambda (fid)
+ (let ((x (lambda (arg) fid)))
+ (x 42)))
+ 123
+ )
+)
diff --git a/tests/let-fail.out b/tests/let-fail.out
new file mode 100644
index 0000000..190a180
--- /dev/null
+++ b/tests/let-fail.out
@@ -0,0 +1 @@
+123
diff --git a/tests/stdlib.lisp b/tests/stdlib.lisp
new file mode 100644
index 0000000..380fa2a
--- /dev/null
+++ b/tests/stdlib.lisp
@@ -0,0 +1,28 @@
+(define cadr (x) (car (cdr x)))
+(define caddr (x) (car (cdr (cdr x))))
+(define cadddr (x) (car (cdr (cdr (cdr x)))))
+
+(define YY (recur) (lambda (f) (lambda (a) (f ((recur recur) f) a))))
+(define Y (YY YY))
+
+(define for (start end f)
+ (if (<= start end)
+ (do (f start) (for (+ start 1) end f))
+ '()))
+
+(define with-open-file (path mode f)
+ (let ((fid (sys-open-file mode path)))
+ (let ((value (f fid)))
+ (do
+ (sys-close-file fid)
+ value))))
+
+(define read-file (path)
+ (with-open-file path 0 (lambda (fid)
+ ; (print (sys-get-char fid))
+ ; (print (let ((x (lambda (arg) fid))) (x 42)))
+ (let ((helper (Y (lambda (recur s)
+ (let ((ch (sys-get-char fid)))
+ (if (null? ch) s (recur (+ s ch))))))))
+ (helper ""))
+ )))
diff --git a/tests/stdlib.out b/tests/stdlib.out
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/stdlib.out
diff --git a/symbols.lisp b/tests/symbols.lisp
index cba1302..cba1302 100644
--- a/symbols.lisp
+++ b/tests/symbols.lisp
diff --git a/tests/symbols.out b/tests/symbols.out
new file mode 100644
index 0000000..16f9c5e
--- /dev/null
+++ b/tests/symbols.out
@@ -0,0 +1,3 @@
+[1,2,3]
+[1,2,3]
+1