2001-01-26 13:44:57 +00:00
|
|
|
|
#!/home/dirk/bin/guile \
|
1999-05-29 14:22:24 +00:00
|
|
|
|
-e main -s
|
|
|
|
|
|
!#
|
|
|
|
|
|
|
|
|
|
|
|
;;;; guile-test --- run the Guile test suite
|
|
|
|
|
|
;;;; Jim Blandy <jimb@red-bean.com> --- May 1999
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
;;;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
;;;; any later version.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
;;;; GNU General Public License for more details.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
|
;;;; along with this software; see the file COPYING. If not, write to
|
|
|
|
|
|
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
;;;; Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; Usage: [guile -e main -s] guile-test [OPTIONS] [TEST ...]
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Run tests from the Guile test suite. Report failures and
|
|
|
|
|
|
;;;; unexpected passes to the standard output, along with a summary of
|
|
|
|
|
|
;;;; all the results. Record each reported test outcome in the log
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; file, `guile.log'. The exit status is #f if any of the tests
|
|
|
|
|
|
;;;; fail or pass unexpectedly.
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Normally, guile-test scans the test directory, and executes all
|
|
|
|
|
|
;;;; files whose names end in `.test'. (It assumes they contain
|
|
|
|
|
|
;;;; Scheme code.) However, you can have it execute specific tests by
|
|
|
|
|
|
;;;; listing their filenames on the command line.
|
|
|
|
|
|
;;;;
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; The option '--test-suite' can be given to specify the test
|
|
|
|
|
|
;;;; directory. If no such option is given, the test directory is
|
|
|
|
|
|
;;;; taken from the environment variable TEST_SUITE_DIR (if defined),
|
|
|
|
|
|
;;;; otherwise a default directory that is hardcoded in this file is
|
|
|
|
|
|
;;;; used (see "Installation" below).
|
|
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; If present, the `--log-file LOG' option tells `guile-test' to put
|
|
|
|
|
|
;;;; the log output in a file named LOG.
|
|
|
|
|
|
;;;;
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; If present, the '--debug' option will enable a debugging mode.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; Installation:
|
|
|
|
|
|
;;;;
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; If you change the #! line at the top of this script to point at
|
|
|
|
|
|
;;;; the Guile interpreter you want to test, you can call this script
|
|
|
|
|
|
;;;; as an executable instead of having to pass it as a parameter to
|
|
|
|
|
|
;;;; guile via "guile -e main -s guile-test". Further, you can edit
|
|
|
|
|
|
;;;; the definition of default-test-suite to point to the parent
|
|
|
|
|
|
;;;; directory of the `tests' tree, which makes it unnecessary to set
|
|
|
|
|
|
;;;; the environment variable `TEST_SUITE_DIR'.
|
|
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Shortcomings:
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; At the moment, due to a simple-minded implementation, test files
|
|
|
|
|
|
;;;; must live in the test directory, and you must specify their names
|
|
|
|
|
|
;;;; relative to the top of the test directory. If you want to send
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;;; me a patch that fixes this, but still leaves sane test names in
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; the log file, that would be great. At the moment, all the tests
|
|
|
|
|
|
;;;; I care about are in the test directory, though.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; It would be nice if you could specify the Guile interpreter you
|
|
|
|
|
|
;;;; want to test on the command line. As it stands, if you want to
|
|
|
|
|
|
;;;; change which Guile interpreter you're testing, you need to edit
|
|
|
|
|
|
;;;; the #! line at the top of this file, which is stupid.
|
|
|
|
|
|
|
2001-01-26 13:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
;;; User configurable settings:
|
|
|
|
|
|
(define default-test-suite
|
|
|
|
|
|
(string-append (getenv "HOME") "/guile-core/test-suite"))
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(use-modules (test-suite lib)
|
|
|
|
|
|
(ice-9 getopt-long)
|
|
|
|
|
|
(ice-9 and-let*))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; General utilities, that probably should be in a library somewhere.
|
|
|
|
|
|
|
2001-01-26 13:44:57 +00:00
|
|
|
|
;;; Enable debugging
|
|
|
|
|
|
(define (enable-debug-mode)
|
|
|
|
|
|
(write-line %load-path)
|
|
|
|
|
|
(set! %load-verbosely #t)
|
|
|
|
|
|
(debug-enable 'backtrace 'debug))
|
|
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;; Traverse the directory tree at ROOT, applying F to the name of
|
|
|
|
|
|
;;; each file in the tree, including ROOT itself. For a subdirectory
|
|
|
|
|
|
;;; SUB, if (F SUB) is true, we recurse into SUB. Do not follow
|
|
|
|
|
|
;;; symlinks.
|
|
|
|
|
|
(define (for-each-file f root)
|
|
|
|
|
|
|
|
|
|
|
|
;; A "hard directory" is a path that denotes a directory and is not a
|
|
|
|
|
|
;; symlink.
|
|
|
|
|
|
(define (file-is-hard-directory? filename)
|
|
|
|
|
|
(eq? (stat:type (lstat filename)) 'directory))
|
|
|
|
|
|
|
|
|
|
|
|
(let visit ((root root))
|
|
|
|
|
|
(let ((should-recur (f root)))
|
|
|
|
|
|
(if (and should-recur (file-is-hard-directory? root))
|
|
|
|
|
|
(let ((dir (opendir root)))
|
|
|
|
|
|
(let loop ()
|
|
|
|
|
|
(let ((entry (readdir dir)))
|
|
|
|
|
|
(cond
|
|
|
|
|
|
((eof-object? entry) #f)
|
|
|
|
|
|
((or (string=? entry ".")
|
|
|
|
|
|
(string=? entry ".."))
|
|
|
|
|
|
(loop))
|
|
|
|
|
|
(else
|
|
|
|
|
|
(visit (string-append root "/" entry))
|
|
|
|
|
|
(loop))))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; The test driver.
|
|
|
|
|
|
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(define (test-file-name test-dir test)
|
|
|
|
|
|
(in-vicinity test-dir test))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; Return a list of all the test files in the test tree.
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(define (enumerate-tests test-dir)
|
|
|
|
|
|
|
|
|
|
|
|
(let ((root-len (+ 1 (string-length test-dir)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(tests '()))
|
|
|
|
|
|
(for-each-file (lambda (file)
|
|
|
|
|
|
(if (has-suffix? file ".test")
|
|
|
|
|
|
(let ((short-name
|
|
|
|
|
|
(substring file root-len)))
|
|
|
|
|
|
(set! tests (cons short-name tests))))
|
|
|
|
|
|
#t)
|
2001-01-26 13:44:57 +00:00
|
|
|
|
test-dir)
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;; for-each-file presents the files in whatever order it finds
|
|
|
|
|
|
;; them in the directory. We sort them here, so they'll always
|
|
|
|
|
|
;; appear in the same order. This makes it easier to compare test
|
|
|
|
|
|
;; log files mechanically.
|
|
|
|
|
|
(sort tests string<?)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (main args)
|
|
|
|
|
|
(let ((options (getopt-long args
|
2001-01-26 13:44:57 +00:00
|
|
|
|
`((test-suite
|
|
|
|
|
|
(single-char #\t)
|
|
|
|
|
|
(value #t))
|
|
|
|
|
|
(log-file
|
|
|
|
|
|
(single-char #\l)
|
|
|
|
|
|
(value #t))
|
|
|
|
|
|
(debug
|
|
|
|
|
|
(single-char #\d))))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(define (opt tag default)
|
|
|
|
|
|
(let ((pair (assq tag options)))
|
|
|
|
|
|
(if pair (cdr pair) default)))
|
2001-01-26 13:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
(if (opt 'debug #f)
|
|
|
|
|
|
(enable-debug-mode))
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((test-suite
|
|
|
|
|
|
(or (opt 'test-suite #f)
|
|
|
|
|
|
(getenv "TEST_SUITE_DIR")
|
|
|
|
|
|
default-test-suite))
|
|
|
|
|
|
(tests
|
|
|
|
|
|
(let ((foo (opt '() '())))
|
|
|
|
|
|
(if (null? foo)
|
|
|
|
|
|
(enumerate-tests test-suite)
|
|
|
|
|
|
foo)))
|
|
|
|
|
|
(log-file
|
|
|
|
|
|
(opt 'log-file "guile.log")))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;; Open the log file.
|
|
|
|
|
|
(let ((log-port (open-output-file log-file)))
|
|
|
|
|
|
|
|
|
|
|
|
;; Register some reporters.
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(let ((global-pass #t)
|
|
|
|
|
|
(counter (make-count-reporter)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(register-reporter (car counter))
|
|
|
|
|
|
(register-reporter (make-log-reporter log-port))
|
|
|
|
|
|
(register-reporter user-reporter)
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(register-reporter (lambda results
|
|
|
|
|
|
(case (car results)
|
|
|
|
|
|
((fail upass unresolved error)
|
|
|
|
|
|
(set! global-pass #f)))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;; Run the tests.
|
|
|
|
|
|
(for-each (lambda (test)
|
|
|
|
|
|
(with-test-prefix test
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(load (test-file-name test-suite test))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
tests)
|
|
|
|
|
|
|
|
|
|
|
|
;; Display the final counts, both to the user and in the log
|
|
|
|
|
|
;; file.
|
|
|
|
|
|
(let ((counts ((cadr counter))))
|
|
|
|
|
|
(print-counts counts)
|
|
|
|
|
|
(print-counts counts log-port))
|
|
|
|
|
|
|
2001-01-26 13:44:57 +00:00
|
|
|
|
(close-port log-port)
|
|
|
|
|
|
(quit global-pass))))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
|
|
;;; mode: scheme
|
|
|
|
|
|
;;; End:
|