2016-10-16 15:34:51 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# -*-scheme-*-
|
2018-04-07 16:27:26 +00:00
|
|
|
MES=${MES-$(dirname $0)/../src/mes}
|
2018-04-14 20:06:28 +00:00
|
|
|
#export MES_ARENA=${MES_ARENA-40000}
|
|
|
|
$MES $MES_FLAGS "$@" < $0
|
2016-10-16 15:34:51 +00:00
|
|
|
exit $?
|
|
|
|
!#
|
|
|
|
|
2016-07-25 12:39:56 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-07-25 12:39:56 +00:00
|
|
|
;;;
|
2016-12-07 19:26:41 +00:00
|
|
|
;;; This file is part of Mes.
|
2016-07-25 12:39:56 +00:00
|
|
|
;;;
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-12 21:40:11 +00:00
|
|
|
(mes-use-module (mes test))
|
|
|
|
|
2016-07-25 12:39:56 +00:00
|
|
|
(pass-if "first dummy" #t)
|
|
|
|
(pass-if-not "second dummy" #f)
|
|
|
|
|
2016-11-02 09:26:04 +00:00
|
|
|
(pass-if "lambda" (symbol? 'lambda))
|
2016-07-25 12:39:56 +00:00
|
|
|
|
2018-01-25 05:58:44 +00:00
|
|
|
(pass-if-equal "append" '(0 1) (append2 '(0) '(1)))
|
|
|
|
(pass-if-equal "append 2" '(0) (append2 '(0) '()))
|
|
|
|
(pass-if-equal "append 3" '(0 1 2) (append '(0) '(1) '(2)))
|
|
|
|
|
|
|
|
(pass-if-equal "cond #f" #t (cond (#f #f) (#t #t)))
|
|
|
|
(pass-if "cond #t" (cond (#t)))
|
|
|
|
(pass-if "cond #f" (cond (#f #f) (#t #t)))
|
|
|
|
(pass-if-equal "cond 2" *unspecified* (cond (#f)))
|
|
|
|
(pass-if-equal "cond 3" 0 (cond (#t 0)))
|
|
|
|
(pass-if-equal "cond 3a" 0 (cond (#f 1) (#t 0)))
|
|
|
|
(pass-if-equal "cond side effect"
|
2017-04-02 14:47:22 +00:00
|
|
|
1
|
2018-01-25 05:58:44 +00:00
|
|
|
((lambda (i)
|
|
|
|
(cond ((set! i (+ i 1)) i)))
|
|
|
|
0))
|
|
|
|
(pass-if-equal "cond => "
|
|
|
|
0 ((lambda (lst)
|
|
|
|
(define (next)
|
|
|
|
((lambda (r)
|
2017-04-02 14:47:22 +00:00
|
|
|
(set! lst (cdr lst))
|
2018-01-25 05:58:44 +00:00
|
|
|
r)
|
|
|
|
(car lst)))
|
|
|
|
(cond ((next) => identity)))
|
|
|
|
'(0 1 2)))
|
|
|
|
|
|
|
|
(pass-if-equal "and" 1 (and 1))
|
|
|
|
(pass-if-not "and 2" (and 1 (= 0 1) #f))
|
|
|
|
(pass-if-not "or" (or))
|
|
|
|
(pass-if-equal "or 2" 1 (or 1))
|
|
|
|
(pass-if-equal "or 3" 3 (or #f (= 0 1) 3))
|
|
|
|
(pass-if "or 4" (or (= 0 0) (= 0 1)))
|
|
|
|
(pass-if "or 5" (or (= 0 1) (= 0 0)))
|
|
|
|
(pass-if-equal "or only once"
|
|
|
|
1
|
|
|
|
((lambda ()
|
|
|
|
(define read
|
|
|
|
((lambda (lst)
|
|
|
|
(lambda ()
|
|
|
|
((lambda (r)
|
|
|
|
(set! lst (cdr lst))
|
|
|
|
r)
|
|
|
|
(car lst))))
|
|
|
|
'(1 0)))
|
|
|
|
(or (read) #t))))
|
|
|
|
|
|
|
|
(pass-if-eq "let" 0 (let () 0))
|
|
|
|
(pass-if-eq "let 2" 0 (let ((x 0)) x))
|
|
|
|
(pass-if-eq "let 3" 11 (let ((p 5) (q 6)) (+ p q)))
|
|
|
|
|
|
|
|
(let () (define *top-let-define-a* '*top-let-define-a*) #t)
|
|
|
|
(pass-if-not "top let define " (defined? '*top-let-define-a*))
|
2016-07-25 12:39:56 +00:00
|
|
|
|
2016-10-29 14:35:44 +00:00
|
|
|
(pass-if "apply" (sequal? (apply list '(1)) '(1)))
|
|
|
|
(pass-if "apply 2" (sequal? (apply list 1 '(2)) '(1 2)))
|
|
|
|
(pass-if "apply 3" (sequal? (apply list 1 2 '(3)) '(1 2 3)))
|
2016-11-02 19:25:08 +00:00
|
|
|
(begin
|
|
|
|
(define local-answer 41))
|
|
|
|
(pass-if-equal "begin 2" 41 (begin local-answer))
|
|
|
|
|
2018-01-25 05:58:44 +00:00
|
|
|
(pass-if-equal "primitive-load" 42 (primitive-load "tests/data/load.scm") the-answer)
|
|
|
|
|
|
|
|
(cond-expand
|
|
|
|
(mes
|
2018-04-14 20:06:28 +00:00
|
|
|
(pass-if-equal "include" 42 (include "tests/data/load.scm") the-answer))
|
|
|
|
(else))
|
2016-11-02 19:25:08 +00:00
|
|
|
|
2018-01-25 05:58:44 +00:00
|
|
|
(pass-if-eq "call/cc"
|
2016-12-28 21:04:57 +00:00
|
|
|
0
|
2018-01-25 05:58:44 +00:00
|
|
|
((lambda (cont seen?)
|
|
|
|
(+ 1 (call/cc (lambda (c) (set! cont c) 1)))
|
|
|
|
(if seen? 0
|
|
|
|
(begin (set! seen? #t)
|
|
|
|
(cont 2))))
|
|
|
|
#f #f))
|
2016-12-28 21:04:57 +00:00
|
|
|
|
2018-04-14 20:06:28 +00:00
|
|
|
(cond-expand
|
|
|
|
(mes
|
|
|
|
(pass-if-not "#<eof>"
|
|
|
|
(char? (integer->char -1))))
|
|
|
|
(else))
|
2018-01-04 20:36:46 +00:00
|
|
|
|
2018-04-07 07:34:02 +00:00
|
|
|
(pass-if-equal "setenv, getenv"
|
|
|
|
"bar"
|
|
|
|
(begin
|
|
|
|
(setenv "foo" "bar")
|
|
|
|
(getenv "bar")
|
|
|
|
(getenv "foo")))
|
|
|
|
|
2016-07-25 12:39:56 +00:00
|
|
|
(result 'report)
|