(scm_char_set_xor): bug fix: characters should only be included if
[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.
000ee07f
JB
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
66301f9a 79 (string-append (getenv "HOME") "/bogus-path/test-suite"))
1ff7abbe
DH
80
81\f
000ee07f 82(use-modules (test-suite lib)
000ee07f 83 (ice-9 getopt-long)
0e3817d7
DH
84 (ice-9 and-let-star)
85 (ice-9 rdelim))
000ee07f
JB
86
87\f
efb07c89
DH
88;;; Variables that will receive their actual values later.
89(define test-suite default-test-suite)
90
66301f9a
GH
91(define tmp-dir #f)
92
efb07c89 93\f
000ee07f
JB
94;;; General utilities, that probably should be in a library somewhere.
95
1ff7abbe
DH
96;;; Enable debugging
97(define (enable-debug-mode)
98 (write-line %load-path)
99 (set! %load-verbosely #t)
100 (debug-enable 'backtrace 'debug))
101
000ee07f
JB
102;;; Traverse the directory tree at ROOT, applying F to the name of
103;;; each file in the tree, including ROOT itself. For a subdirectory
104;;; SUB, if (F SUB) is true, we recurse into SUB. Do not follow
105;;; symlinks.
106(define (for-each-file f root)
107
108 ;; A "hard directory" is a path that denotes a directory and is not a
109 ;; symlink.
110 (define (file-is-hard-directory? filename)
111 (eq? (stat:type (lstat filename)) 'directory))
112
113 (let visit ((root root))
114 (let ((should-recur (f root)))
115 (if (and should-recur (file-is-hard-directory? root))
116 (let ((dir (opendir root)))
117 (let loop ()
118 (let ((entry (readdir dir)))
119 (cond
120 ((eof-object? entry) #f)
121 ((or (string=? entry ".")
122 (string=? entry ".."))
123 (loop))
124 (else
125 (visit (string-append root "/" entry))
126 (loop))))))))))
127
000ee07f
JB
128\f
129;;; The test driver.
130
efb07c89 131\f
66301f9a 132;;; Localizing test files and temporary data files.
efb07c89
DH
133
134(define (data-file-name filename)
66301f9a 135 (in-vicinity tmp-dir filename))
efb07c89
DH
136
137(define (test-file-name test)
138 (in-vicinity test-suite test))
000ee07f
JB
139
140;;; Return a list of all the test files in the test tree.
1ff7abbe 141(define (enumerate-tests test-dir)
1ff7abbe 142 (let ((root-len (+ 1 (string-length test-dir)))
000ee07f
JB
143 (tests '()))
144 (for-each-file (lambda (file)
145 (if (has-suffix? file ".test")
146 (let ((short-name
147 (substring file root-len)))
148 (set! tests (cons short-name tests))))
149 #t)
1ff7abbe 150 test-dir)
000ee07f
JB
151
152 ;; for-each-file presents the files in whatever order it finds
153 ;; them in the directory. We sort them here, so they'll always
154 ;; appear in the same order. This makes it easier to compare test
155 ;; log files mechanically.
156 (sort tests string<?)))
157
158(define (main args)
159 (let ((options (getopt-long args
1ff7abbe
DH
160 `((test-suite
161 (single-char #\t)
162 (value #t))
163 (log-file
164 (single-char #\l)
165 (value #t))
166 (debug
167 (single-char #\d))))))
000ee07f
JB
168 (define (opt tag default)
169 (let ((pair (assq tag options)))
170 (if pair (cdr pair) default)))
1ff7abbe
DH
171
172 (if (opt 'debug #f)
173 (enable-debug-mode))
174
efb07c89
DH
175 (set! test-suite
176 (or (opt 'test-suite #f)
177 (getenv "TEST_SUITE_DIR")
178 default-test-suite))
179
66301f9a
GH
180 ;; directory where temporary files are created.
181 ;; when run from "make check", this must be under the build-dir,
182 ;; not the src-dir.
183 (set! tmp-dir (getcwd))
184
efb07c89 185 (let* ((tests
1ff7abbe
DH
186 (let ((foo (opt '() '())))
187 (if (null? foo)
188 (enumerate-tests test-suite)
189 foo)))
190 (log-file
191 (opt 'log-file "guile.log")))
000ee07f
JB
192
193 ;; Open the log file.
194 (let ((log-port (open-output-file log-file)))
195
196 ;; Register some reporters.
1ff7abbe
DH
197 (let ((global-pass #t)
198 (counter (make-count-reporter)))
000ee07f
JB
199 (register-reporter (car counter))
200 (register-reporter (make-log-reporter log-port))
201 (register-reporter user-reporter)
1ff7abbe
DH
202 (register-reporter (lambda results
203 (case (car results)
204 ((fail upass unresolved error)
205 (set! global-pass #f)))))
000ee07f
JB
206
207 ;; Run the tests.
208 (for-each (lambda (test)
209 (with-test-prefix test
efb07c89 210 (load (test-file-name test))))
000ee07f
JB
211 tests)
212
213 ;; Display the final counts, both to the user and in the log
214 ;; file.
215 (let ((counts ((cadr counter))))
216 (print-counts counts)
217 (print-counts counts log-port))
218
1ff7abbe
DH
219 (close-port log-port)
220 (quit global-pass))))))
000ee07f
JB
221
222\f
223;;; Local Variables:
224;;; mode: scheme
225;;; End: