-#!/home/dirk/bin/guile \
+#!../meta/guile \
-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.
-;;;;
+;;;; Copyright (C) 1999, 2001, 2006, 2010, 2014 Free Software Foundation, Inc.
+;;;;
+;;;; This program is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 3, 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
+;;;; GNU Lesser General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU Lesser General Public
+;;;; License along with this software; see the file COPYING.LESSER.
+;;;; If not, write to the Free Software Foundation, Inc., 51 Franklin
+;;;; Street, Fifth Floor, Boston, MA 02110-1301 USA
;;;; Usage: [guile -e main -s] guile-test [OPTIONS] [TEST ...]
;;;; Scheme code.) However, you can have it execute specific tests by
;;;; listing their filenames on the command line.
;;;;
-;;;; The option '--test-suite' can be given to specify the test
+;;;; 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
+;;;; otherwise a default directory that is hardcoded in this file is
;;;; used (see "Installation" below).
;;;;
;;;; If present, the `--log-file LOG' option tells `guile-test' to put
;;;; the log output in a file named LOG.
;;;;
-;;;; If present, the '--debug' option will enable a debugging mode.
+;;;; If present, the `--debug' option will enable a debugging mode.
+;;;;
+;;;; If present, the `--flag-unresolved' option will cause guile-test
+;;;; to exit with failure status if any tests are UNRESOLVED.
;;;;
;;;;
;;;; Installation:
;;;; change which Guile interpreter you're testing, you need to edit
;;;; the #! line at the top of this file, which is stupid.
+(define (main . args)
+ (let ((module (resolve-module '(test-suite guile-test))))
+ (apply (module-ref module 'main) args)))
+
+(define-module (test-suite guile-test)
+ :use-module (test-suite lib)
+ :use-module (ice-9 getopt-long)
+ :use-module (ice-9 and-let-star)
+ :use-module (ice-9 rdelim)
+ :use-module (system vm coverage)
+ :use-module (srfi srfi-11)
+ :use-module (system vm vm)
+ :export (main data-file-name test-file-name))
+
\f
;;; User configurable settings:
-(define default-test-suite
- (string-append (getenv "HOME") "/guile-core/test-suite"))
+(define (default-test-suite)
+ (let ((argv0 (car (program-arguments))))
+ (if (string=? (basename argv0) "guile-test")
+ (dirname argv0)
+ (error "Cannot find default test suite."))))
\f
-(use-modules (test-suite lib)
- (ice-9 getopt-long)
- (ice-9 and-let*))
+;;; Variables that will receive their actual values later.
+(define test-suite)
+
+(define tmp-dir #f)
\f
;;; General utilities, that probably should be in a library somewhere.
;;; symlinks.
(define (for-each-file f root)
- ;; A "hard directory" is a path that denotes a directory and is not a
+ ;; 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 ((dir (opendir root)))
(let loop ()
(let ((entry (readdir dir)))
- (cond
+ (cond
((eof-object? entry) #f)
((or (string=? entry ".")
- (string=? entry ".."))
+ (string=? entry "..")
+ (string=? entry "CVS")
+ (string=? entry "RCS"))
(loop))
(else
(visit (string-append root "/" entry))
\f
;;; The test driver.
-(define (test-file-name test-dir test)
- (in-vicinity test-dir test))
+\f
+;;; Localizing test files and temporary data files.
+
+(define (data-file-name filename)
+ (in-vicinity tmp-dir filename))
+
+(define (test-file-name test)
+ (in-vicinity test-suite test))
;;; Return a list of all the test files in the test tree.
(define (enumerate-tests test-dir)
-
(let ((root-len (+ 1 (string-length test-dir)))
(tests '()))
(for-each-file (lambda (file)
- (if (has-suffix? file ".test")
+ (if (string-suffix? ".test" file)
(let ((short-name
(substring file root-len)))
(set! tests (cons short-name tests))))
(define (main args)
(let ((options (getopt-long args
- `((test-suite
+ `((test-suite
(single-char #\t)
(value #t))
- (log-file
+ (flag-unresolved
+ (single-char #\u))
+ (log-file
(single-char #\l)
(value #t))
- (debug
+ (coverage
+ (single-char #\c))
+ (debug
(single-char #\d))))))
(define (opt tag default)
(let ((pair (assq tag options)))
(if (opt 'debug #f)
(enable-debug-mode))
- (let* ((test-suite
- (or (opt 'test-suite #f)
- (getenv "TEST_SUITE_DIR")
- default-test-suite))
- (tests
+ (set! test-suite
+ (or (opt 'test-suite #f)
+ (getenv "TEST_SUITE_DIR")
+ (default-test-suite)))
+
+ ;; directory where temporary files are created.
+ ;; when run from "make check", this must be under the build-dir,
+ ;; not the src-dir.
+ (set! tmp-dir (getcwd))
+
+ (let* ((tests
(let ((foo (opt '() '())))
- (if (null? foo)
+ (if (null? foo)
(enumerate-tests test-suite)
foo)))
- (log-file
+ (log-file
(opt 'log-file "guile.log")))
;; Open the log file.
(let ((log-port (open-output-file log-file)))
+ ;; Allow for arbitrary Unicode characters in the log file.
+ (set-port-encoding! log-port "UTF-8")
+
+ ;; Don't fail if we can't display a test name to stdout/stderr.
+ (set-port-conversion-strategy! (current-output-port) 'escape)
+ (set-port-conversion-strategy! (current-error-port) 'escape)
+
;; Register some reporters.
(let ((global-pass #t)
(counter (make-count-reporter)))
(register-reporter user-reporter)
(register-reporter (lambda results
(case (car results)
- ((fail upass unresolved error)
+ ((unresolved)
+ (and (opt 'flag-unresolved #f)
+ (set! global-pass #f)))
+ ((fail upass error)
(set! global-pass #f)))))
;; Run the tests.
- (for-each (lambda (test)
- (with-test-prefix test
- (load (test-file-name test-suite test))))
- tests)
+ (let ((run-tests
+ (lambda ()
+ (for-each (lambda (test)
+ (display (string-append "Running " test "\n"))
+ (when (defined? 'setlocale)
+ (setlocale LC_ALL "C"))
+ (with-test-prefix test
+ (load (test-file-name test))))
+ tests))))
+ (if (opt 'coverage #f)
+ (let-values (((coverage-data _)
+ (with-code-coverage (the-vm) run-tests)))
+ (let ((out (open-output-file "guile.info")))
+ (coverage-data->lcov coverage-data out)
+ (close out)))
+ (run-tests)))
;; Display the final counts, both to the user and in the log
;; file.