* convert.c: include <string.h> for convert_i.c.
[bpt/guile.git] / test-suite / guile-test
CommitLineData
1be6b49c 1#!../libguile/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;;;;
96e30d2a 8;;;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
068a9d87 9;;;;
000ee07f
JB
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.
068a9d87 14;;;;
000ee07f
JB
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.
068a9d87 19;;;;
000ee07f
JB
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;;;;
068a9d87 39;;;; The option `--test-suite' can be given to specify the test
1ff7abbe
DH
40;;;; directory. If no such option is given, the test directory is
41;;;; taken from the environment variable TEST_SUITE_DIR (if defined),
068a9d87 42;;;; otherwise a default directory that is hardcoded in this file is
1ff7abbe
DH
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;;;;
068a9d87
TTN
48;;;; If present, the `--debug' option will enable a debugging mode.
49;;;;
50;;;; If present, the `--flag-unresolved' option will cause guile-test
51;;;; to exit with failure status if any tests are UNRESOLVED.
1ff7abbe
DH
52;;;;
53;;;;
000ee07f
JB
54;;;; Installation:
55;;;;
1ff7abbe
DH
56;;;; If you change the #! line at the top of this script to point at
57;;;; the Guile interpreter you want to test, you can call this script
58;;;; as an executable instead of having to pass it as a parameter to
59;;;; guile via "guile -e main -s guile-test". Further, you can edit
60;;;; the definition of default-test-suite to point to the parent
61;;;; directory of the `tests' tree, which makes it unnecessary to set
62;;;; the environment variable `TEST_SUITE_DIR'.
63;;;;
000ee07f
JB
64;;;;
65;;;; Shortcomings:
66;;;;
67;;;; At the moment, due to a simple-minded implementation, test files
68;;;; must live in the test directory, and you must specify their names
69;;;; relative to the top of the test directory. If you want to send
1ff7abbe 70;;;; me a patch that fixes this, but still leaves sane test names in
000ee07f
JB
71;;;; the log file, that would be great. At the moment, all the tests
72;;;; I care about are in the test directory, though.
73;;;;
74;;;; It would be nice if you could specify the Guile interpreter you
75;;;; want to test on the command line. As it stands, if you want to
76;;;; change which Guile interpreter you're testing, you need to edit
77;;;; the #! line at the top of this file, which is stupid.
78
1ff7abbe
DH
79\f
80;;; User configurable settings:
81(define default-test-suite
66301f9a 82 (string-append (getenv "HOME") "/bogus-path/test-suite"))
1ff7abbe
DH
83
84\f
000ee07f 85(use-modules (test-suite lib)
000ee07f 86 (ice-9 getopt-long)
0e3817d7
DH
87 (ice-9 and-let-star)
88 (ice-9 rdelim))
000ee07f
JB
89
90\f
efb07c89
DH
91;;; Variables that will receive their actual values later.
92(define test-suite default-test-suite)
93
66301f9a
GH
94(define tmp-dir #f)
95
efb07c89 96\f
000ee07f
JB
97;;; General utilities, that probably should be in a library somewhere.
98
1ff7abbe
DH
99;;; Enable debugging
100(define (enable-debug-mode)
101 (write-line %load-path)
102 (set! %load-verbosely #t)
103 (debug-enable 'backtrace 'debug))
104
000ee07f
JB
105;;; Traverse the directory tree at ROOT, applying F to the name of
106;;; each file in the tree, including ROOT itself. For a subdirectory
107;;; SUB, if (F SUB) is true, we recurse into SUB. Do not follow
108;;; symlinks.
109(define (for-each-file f root)
110
068a9d87 111 ;; A "hard directory" is a path that denotes a directory and is not a
000ee07f
JB
112 ;; symlink.
113 (define (file-is-hard-directory? filename)
114 (eq? (stat:type (lstat filename)) 'directory))
115
116 (let visit ((root root))
117 (let ((should-recur (f root)))
118 (if (and should-recur (file-is-hard-directory? root))
119 (let ((dir (opendir root)))
120 (let loop ()
121 (let ((entry (readdir dir)))
068a9d87 122 (cond
000ee07f
JB
123 ((eof-object? entry) #f)
124 ((or (string=? entry ".")
1febd88c
TTN
125 (string=? entry "..")
126 (string=? entry "CVS")
127 (string=? entry "RCS"))
000ee07f
JB
128 (loop))
129 (else
130 (visit (string-append root "/" entry))
131 (loop))))))))))
132
000ee07f
JB
133\f
134;;; The test driver.
135
efb07c89 136\f
66301f9a 137;;; Localizing test files and temporary data files.
efb07c89
DH
138
139(define (data-file-name filename)
66301f9a 140 (in-vicinity tmp-dir filename))
efb07c89
DH
141
142(define (test-file-name test)
143 (in-vicinity test-suite test))
000ee07f
JB
144
145;;; Return a list of all the test files in the test tree.
1ff7abbe 146(define (enumerate-tests test-dir)
1ff7abbe 147 (let ((root-len (+ 1 (string-length test-dir)))
000ee07f
JB
148 (tests '()))
149 (for-each-file (lambda (file)
150 (if (has-suffix? file ".test")
151 (let ((short-name
152 (substring file root-len)))
153 (set! tests (cons short-name tests))))
154 #t)
1ff7abbe 155 test-dir)
000ee07f
JB
156
157 ;; for-each-file presents the files in whatever order it finds
158 ;; them in the directory. We sort them here, so they'll always
159 ;; appear in the same order. This makes it easier to compare test
160 ;; log files mechanically.
161 (sort tests string<?)))
162
163(define (main args)
164 (let ((options (getopt-long args
068a9d87 165 `((test-suite
1ff7abbe
DH
166 (single-char #\t)
167 (value #t))
068a9d87
TTN
168 (flag-unresolved
169 (single-char #\u))
170 (log-file
1ff7abbe
DH
171 (single-char #\l)
172 (value #t))
068a9d87 173 (debug
1ff7abbe 174 (single-char #\d))))))
000ee07f
JB
175 (define (opt tag default)
176 (let ((pair (assq tag options)))
177 (if pair (cdr pair) default)))
1ff7abbe
DH
178
179 (if (opt 'debug #f)
180 (enable-debug-mode))
181
efb07c89
DH
182 (set! test-suite
183 (or (opt 'test-suite #f)
184 (getenv "TEST_SUITE_DIR")
185 default-test-suite))
186
66301f9a
GH
187 ;; directory where temporary files are created.
188 ;; when run from "make check", this must be under the build-dir,
189 ;; not the src-dir.
190 (set! tmp-dir (getcwd))
191
efb07c89 192 (let* ((tests
1ff7abbe 193 (let ((foo (opt '() '())))
068a9d87 194 (if (null? foo)
1ff7abbe
DH
195 (enumerate-tests test-suite)
196 foo)))
068a9d87 197 (log-file
1ff7abbe 198 (opt 'log-file "guile.log")))
000ee07f
JB
199
200 ;; Open the log file.
201 (let ((log-port (open-output-file log-file)))
202
203 ;; Register some reporters.
1ff7abbe
DH
204 (let ((global-pass #t)
205 (counter (make-count-reporter)))
000ee07f
JB
206 (register-reporter (car counter))
207 (register-reporter (make-log-reporter log-port))
208 (register-reporter user-reporter)
1ff7abbe
DH
209 (register-reporter (lambda results
210 (case (car results)
068a9d87
TTN
211 ((unresolved)
212 (and (opt 'flag-unresolved #f)
213 (set! global-pass #f)))
214 ((fail upass error)
1ff7abbe 215 (set! global-pass #f)))))
000ee07f
JB
216
217 ;; Run the tests.
218 (for-each (lambda (test)
219 (with-test-prefix test
efb07c89 220 (load (test-file-name test))))
000ee07f
JB
221 tests)
222
223 ;; Display the final counts, both to the user and in the log
224 ;; file.
225 (let ((counts ((cadr counter))))
226 (print-counts counts)
227 (print-counts counts log-port))
228
1ff7abbe
DH
229 (close-port log-port)
230 (quit global-pass))))))
000ee07f
JB
231
232\f
233;;; Local Variables:
234;;; mode: scheme
235;;; End: