* guile-test: Use (ice-9 and-let-star) instead of (ice-9
[bpt/guile.git] / test-suite / guile-test
CommitLineData
1ff7abbe 1#!/home/dirk/bin/guile \
000ee07f
JB
2-e main -s
3!#
4
5;;;; guile-test --- run the Guile test suite
6;;;; Jim Blandy <jimb@red-bean.com> --- May 1999
7;;;;
8;;;; Copyright (C) 1999 Free Software Foundation, Inc.
9;;;;
10;;;; This program is free software; you can redistribute it and/or modify
11;;;; it under the terms of the GNU General Public License as published by
12;;;; the Free Software Foundation; either version 2, or (at your option)
13;;;; any later version.
14;;;;
15;;;; This program is distributed in the hope that it will be useful,
16;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;;; GNU General Public License for more details.
19;;;;
20;;;; You should have received a copy of the GNU General Public License
21;;;; along with this software; see the file COPYING. If not, write to
22;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23;;;; Boston, MA 02111-1307 USA
24
25
1ff7abbe 26;;;; Usage: [guile -e main -s] guile-test [OPTIONS] [TEST ...]
000ee07f
JB
27;;;;
28;;;; Run tests from the Guile test suite. Report failures and
29;;;; unexpected passes to the standard output, along with a summary of
30;;;; all the results. Record each reported test outcome in the log
1ff7abbe
DH
31;;;; file, `guile.log'. The exit status is #f if any of the tests
32;;;; fail or pass unexpectedly.
000ee07f
JB
33;;;;
34;;;; Normally, guile-test scans the test directory, and executes all
35;;;; files whose names end in `.test'. (It assumes they contain
36;;;; Scheme code.) However, you can have it execute specific tests by
37;;;; listing their filenames on the command line.
38;;;;
1ff7abbe
DH
39;;;; The option '--test-suite' can be given to specify the test
40;;;; directory. If no such option is given, the test directory is
41;;;; taken from the environment variable TEST_SUITE_DIR (if defined),
42;;;; otherwise a default directory that is hardcoded in this file is
43;;;; used (see "Installation" below).
44;;;;
000ee07f
JB
45;;;; If present, the `--log-file LOG' option tells `guile-test' to put
46;;;; the log output in a file named LOG.
47;;;;
1ff7abbe
DH
48;;;; If present, the '--debug' option will enable a debugging mode.
49;;;;
50;;;;
000ee07f
JB
51;;;; Installation:
52;;;;
1ff7abbe
DH
53;;;; If you change the #! line at the top of this script to point at
54;;;; the Guile interpreter you want to test, you can call this script
55;;;; as an executable instead of having to pass it as a parameter to
56;;;; guile via "guile -e main -s guile-test". Further, you can edit
57;;;; the definition of default-test-suite to point to the parent
58;;;; directory of the `tests' tree, which makes it unnecessary to set
59;;;; the environment variable `TEST_SUITE_DIR'.
60;;;;
000ee07f
JB
61;;;;
62;;;; Shortcomings:
63;;;;
64;;;; At the moment, due to a simple-minded implementation, test files
65;;;; must live in the test directory, and you must specify their names
66;;;; relative to the top of the test directory. If you want to send
1ff7abbe 67;;;; me a patch that fixes this, but still leaves sane test names in
000ee07f
JB
68;;;; the log file, that would be great. At the moment, all the tests
69;;;; I care about are in the test directory, though.
70;;;;
71;;;; It would be nice if you could specify the Guile interpreter you
72;;;; want to test on the command line. As it stands, if you want to
73;;;; change which Guile interpreter you're testing, you need to edit
74;;;; the #! line at the top of this file, which is stupid.
75
1ff7abbe
DH
76\f
77;;; User configurable settings:
78(define default-test-suite
79 (string-append (getenv "HOME") "/guile-core/test-suite"))
80
81\f
000ee07f 82(use-modules (test-suite lib)
000ee07f 83 (ice-9 getopt-long)
e11e60d6 84 (ice-9 and-let-star))
000ee07f
JB
85
86\f
efb07c89
DH
87;;; Variables that will receive their actual values later.
88(define test-suite default-test-suite)
89
90\f
000ee07f
JB
91;;; General utilities, that probably should be in a library somewhere.
92
1ff7abbe
DH
93;;; Enable debugging
94(define (enable-debug-mode)
95 (write-line %load-path)
96 (set! %load-verbosely #t)
97 (debug-enable 'backtrace 'debug))
98
000ee07f
JB
99;;; Traverse the directory tree at ROOT, applying F to the name of
100;;; each file in the tree, including ROOT itself. For a subdirectory
101;;; SUB, if (F SUB) is true, we recurse into SUB. Do not follow
102;;; symlinks.
103(define (for-each-file f root)
104
105 ;; A "hard directory" is a path that denotes a directory and is not a
106 ;; symlink.
107 (define (file-is-hard-directory? filename)
108 (eq? (stat:type (lstat filename)) 'directory))
109
110 (let visit ((root root))
111 (let ((should-recur (f root)))
112 (if (and should-recur (file-is-hard-directory? root))
113 (let ((dir (opendir root)))
114 (let loop ()
115 (let ((entry (readdir dir)))
116 (cond
117 ((eof-object? entry) #f)
118 ((or (string=? entry ".")
119 (string=? entry ".."))
120 (loop))
121 (else
122 (visit (string-append root "/" entry))
123 (loop))))))))))
124
000ee07f
JB
125\f
126;;; The test driver.
127
efb07c89
DH
128\f
129;;; Localizing test files and temporary data files relative to the
130;;; test suite directory.
131
132(define (data-file-name filename)
133 (in-vicinity test-suite filename))
134
135(define (test-file-name test)
136 (in-vicinity test-suite test))
000ee07f
JB
137
138;;; Return a list of all the test files in the test tree.
1ff7abbe 139(define (enumerate-tests test-dir)
1ff7abbe 140 (let ((root-len (+ 1 (string-length test-dir)))
000ee07f
JB
141 (tests '()))
142 (for-each-file (lambda (file)
143 (if (has-suffix? file ".test")
144 (let ((short-name
145 (substring file root-len)))
146 (set! tests (cons short-name tests))))
147 #t)
1ff7abbe 148 test-dir)
000ee07f
JB
149
150 ;; for-each-file presents the files in whatever order it finds
151 ;; them in the directory. We sort them here, so they'll always
152 ;; appear in the same order. This makes it easier to compare test
153 ;; log files mechanically.
154 (sort tests string<?)))
155
156(define (main args)
157 (let ((options (getopt-long args
1ff7abbe
DH
158 `((test-suite
159 (single-char #\t)
160 (value #t))
161 (log-file
162 (single-char #\l)
163 (value #t))
164 (debug
165 (single-char #\d))))))
000ee07f
JB
166 (define (opt tag default)
167 (let ((pair (assq tag options)))
168 (if pair (cdr pair) default)))
1ff7abbe
DH
169
170 (if (opt 'debug #f)
171 (enable-debug-mode))
172
efb07c89
DH
173 (set! test-suite
174 (or (opt 'test-suite #f)
175 (getenv "TEST_SUITE_DIR")
176 default-test-suite))
177
178 (let* ((tests
1ff7abbe
DH
179 (let ((foo (opt '() '())))
180 (if (null? foo)
181 (enumerate-tests test-suite)
182 foo)))
183 (log-file
184 (opt 'log-file "guile.log")))
000ee07f
JB
185
186 ;; Open the log file.
187 (let ((log-port (open-output-file log-file)))
188
189 ;; Register some reporters.
1ff7abbe
DH
190 (let ((global-pass #t)
191 (counter (make-count-reporter)))
000ee07f
JB
192 (register-reporter (car counter))
193 (register-reporter (make-log-reporter log-port))
194 (register-reporter user-reporter)
1ff7abbe
DH
195 (register-reporter (lambda results
196 (case (car results)
197 ((fail upass unresolved error)
198 (set! global-pass #f)))))
000ee07f
JB
199
200 ;; Run the tests.
201 (for-each (lambda (test)
202 (with-test-prefix test
efb07c89 203 (load (test-file-name test))))
000ee07f
JB
204 tests)
205
206 ;; Display the final counts, both to the user and in the log
207 ;; file.
208 (let ((counts ((cadr counter))))
209 (print-counts counts)
210 (print-counts counts log-port))
211
1ff7abbe
DH
212 (close-port log-port)
213 (quit global-pass))))))
000ee07f
JB
214
215\f
216;;; Local Variables:
217;;; mode: scheme
218;;; End: