docs: fix typos in manual, and a couple in code comments.
[bpt/guile.git] / test-suite / vm / run-vm-tests.scm
CommitLineData
b6368dbb
LC
1;;; run-vm-tests.scm -- Run Guile-VM's test suite.
2;;;
038cb342 3;;; Copyright 2005, 2009, 2010 Free Software Foundation, Inc.
b6368dbb 4;;;
83ba2d37
NJ
5;;; This program is free software; you can redistribute it and/or
6;;; modify it under the terms of the GNU Lesser General Public License
7;;; as published by the Free Software Foundation; either version 3 of
8;;; the License, or (at your option) any later version.
b6368dbb
LC
9;;;
10;;; This program is distributed in the hope that it will be useful,
11;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83ba2d37 13;;; GNU Lesser General Public License for more details.
b6368dbb 14;;;
83ba2d37 15;;; You should have received a copy of the GNU Lesser General Public License
b6368dbb
LC
16;;; along with this program; if not, write to the Free Software
17;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
0b5f0e49 19
d0927dde 20(use-modules (system vm vm)
038cb342 21 (system vm program)
0b5f0e49
LC
22 (system base compile)
23 (system base language)
b0b180d5
AW
24 (language scheme spec)
25 (language objcode spec)
b6368dbb
LC
26 (srfi srfi-1)
27 (ice-9 r5rs))
0b5f0e49
LC
28
29\f
0b5f0e49
LC
30(define (fetch-sexp-from-file file)
31 (with-input-from-file file
32 (lambda ()
33 (let loop ((sexp (read))
34 (result '()))
35 (if (eof-object? sexp)
36 (cons 'begin (reverse result))
37 (loop (read) (cons sexp result)))))))
38
39(define (compile-to-objcode sexp)
40 "Compile the expression @var{sexp} into a VM program and return it."
b0b180d5 41 (compile sexp #:from scheme #:to objcode))
0b5f0e49
LC
42
43(define (run-vm-program objcode)
44 "Run VM program contained into @var{objcode}."
ea9f4f4b 45 ((make-program objcode)))
0b5f0e49 46
b6368dbb 47(define (compile/run-test-from-file file)
0b5f0e49
LC
48 "Run test from source file @var{file} and return a value indicating whether
49it succeeded."
50 (run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))
51
52\f
53(define-macro (watch-proc proc-name str)
54 `(let ((orig-proc ,proc-name))
55 (set! ,proc-name
56 (lambda args
57 (format #t (string-append ,str "... "))
58 (apply orig-proc args)))))
59
60(watch-proc fetch-sexp-from-file "reading")
61(watch-proc compile-to-objcode "compiling")
62(watch-proc run-vm-program "running")
63
64\f
65;; The program.
66
67(define (run-vm-tests files)
b6368dbb
LC
68 "For each file listed in @var{files}, load it and run it through both the
69interpreter and the VM (after having it compiled). Both results must be
70equal in the sense of @var{equal?}."
0b5f0e49
LC
71 (let* ((res (map (lambda (file)
72 (format #t "running `~a'... " file)
73 (if (catch #t
74 (lambda ()
6297d229 75 (equal? (compile/run-test-from-file file)
32aa2111 76 (primitive-eval (fetch-sexp-from-file file))))
0b5f0e49
LC
77 (lambda (key . args)
78 (format #t "[~a/~a] " key args)
79 #f))
80 (format #t "ok~%")
81 (begin (format #t "FAILED~%") #f)))
82 files))
83 (total (length files))
84 (failed (length (filter not res))))
85
86 (if (= 0 failed)
10331eac 87 (exit 0)
0b5f0e49
LC
88 (begin
89 (format #t "~%~a tests failed out of ~a~%"
90 failed total)
91 (exit failed)))))
92