3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; test.mes can be loaded after base.mes. It provides a minimalistic
24 ;;; test framework: pass-if, pass-if-not, seq?, sequal? and result.
28 (mes-use-module (mes base))
29 (define guile? (not (pair? (current-module))))
35 (cond ((or (null? t) (eq? (car t) result)) (list pass fail))
36 ((eq? (car t) 'report)
37 (let ((expect (if (null? (cdr t)) 0 (cadr t))))
39 (display "passed: ") (display pass) (newline)
40 (display "failed: ") (display fail) (newline)
41 (if (not (eq? expect 0)) (begin (display "expect: ") (display expect) (newline)))
42 (display "total: ") (display (+ pass fail)) (newline)
43 (exit (if (eq? expect fail) 0 fail))))
44 ((car t) (display ": pass") (newline) (set! pass (+ pass 1)))
45 (#t (display ": fail") (newline) (set! fail (+ fail 1)))))))
52 (display "expected: ")
64 (display "expected: ")
71 (define (sequal2? expect actual)
72 (or (equal? expect actual)
74 (display ": fail") (newline)
75 (display "expected: ") (display expect) (newline)
76 (display "actual: ") (display actual) (newline)
79 (define-macro (pass-if name t)
82 (list display "test: ") (list display name)
85 (define-macro (pass-if-equal name expect . body)
86 `(pass-if ,name (sequal2? ,expect (begin ,@body))))
88 (define-macro (expect-fail name expect . body)
89 `(pass-if ,name (not (sequal2? ,expect (begin ,@body)))))
91 (define-macro (pass-if-not name f)
94 (list display "test: ") (list display name)
95 (list result (list not f))))