4 (define (test actual expected)
5 (when (not (equal? actual expected))
7 (format "test failed:\nexpected: ~a\nactual: ~a"
10 (define (read-file file)
11 (call-with-input-file file
13 (let loop ((next (read-char p))
15 (if (eof-object? next)
17 (loop (read-char p) (string-append result (string next))))))))
19 (define (test-prog prog output)
20 (compile-to-binary prog "/tmp/test-prog")
21 (system "/tmp/test-prog > /tmp/test-output.txt")
22 (let ((str (read-file "/tmp/test-output.txt")))
23 (test (substring str 0 (- (string-length str) 1))
26 (test (typecheck '(lambda (x) (+ ((lambda (y) (x y 3)) 5) 2)))
27 '(abs (abs int (abs int int)) int))
29 (test-prog '(+ 1 2) "3")
30 (test-prog '((lambda (x) ((lambda (y) (+ x y)) 42)) 100) "142")
31 ; todo: support recursive let
32 (test-prog '(let ((x (+ 1 32))
34 ((lambda (z) (+ 1 z)) (* y x)))