M Makefile.am => Makefile.am +4 -3
@@ 293,10 293,11 @@ endif BUILD_DAEMON
TESTS = $(SCM_TESTS) $(SH_TESTS)
-AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)"
+AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)" GUILE_AUTO_COMPILE=0
-SCM_LOG_COMPILER = $(top_builddir)/test-env $(GUILE)
-AM_SCM_LOG_FLAGS = --no-auto-compile -L "$(top_srcdir)"
+SCM_LOG_DRIVER = $(top_builddir)/test-env $(GUILE) --no-auto-compile \
+ -e main $(top_srcdir)/build-aux/test-driver.scm
+AM_SCM_LOG_DRIVER_FLAGS = --brief=yes
SH_LOG_COMPILER = $(top_builddir)/test-env $(SHELL)
AM_SH_LOG_FLAGS = -x -e
A build-aux/test-driver.scm => build-aux/test-driver.scm +189 -0
@@ 0,0 1,189 @@
+;;;; test-driver.scm - Guile test driver for Automake testsuite harness
+
+(define script-version "2016-04-03.12") ;UTC
+
+;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
+;;;
+;;; 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 3 of the License, 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 program. If not, see <http://www.gnu.org/licenses/>.
+
+;;;; Commentary:
+;;;
+;;; This script provides a Guile test driver using the SRFI-64 Scheme API for
+;;; test suites. SRFI-64 is distributed with Guile since version 2.0.9.
+;;;
+;;;; Code:
+
+(use-modules (ice-9 getopt-long)
+ (ice-9 pretty-print)
+ (srfi srfi-26)
+ (srfi srfi-64))
+
+(define (show-help)
+ (display "Usage:
+ test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
+ [--expect-failure={yes|no}] [--color-tests={yes|no}]
+ [--enable-hard-errors={yes|no}] [--brief={yes|no}}] [--]
+ TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
+The '--test-name', '--log-file' and '--trs-file' options are mandatory.\n"))
+
+(define %options
+ '((test-name (value #t))
+ (log-file (value #t))
+ (trs-file (value #t))
+ (color-tests (value #t))
+ (expect-failure (value #t)) ;XXX: not implemented yet
+ (enable-hard-errors (value #t)) ;not implemented in SRFI-64
+ (brief (value #t))
+ (help (single-char #\h) (value #f))
+ (version (single-char #\V) (value #f))))
+
+(define (option->boolean options key)
+ "Return #t if the value associated with KEY in OPTIONS is \"yes\"."
+ (and=> (option-ref options key #f) (cut string=? <> "yes")))
+
+(define* (test-display field value #:optional (port (current-output-port))
+ #:key pretty?)
+ "Display \"FIELD: VALUE\\n\" on PORT."
+ (if pretty?
+ (begin
+ (format port "~A:~%" field)
+ (pretty-print value port #:per-line-prefix "+ "))
+ (format port "~A: ~A~%" field value)))
+
+(define* (result->string symbol #:key colorize?)
+ "Return SYMBOL as an upper case string. Use colors when COLORIZE is #t."
+ (let ((result (string-upcase (symbol->string symbol))))
+ (if colorize?
+ (string-append (case symbol
+ ((pass) "[0;32m") ;green
+ ((xfail) "[1;32m") ;light green
+ ((skip) "[1;34m") ;blue
+ ((fail xpass) "[0;31m") ;red
+ ((error) "[0;35m")) ;magenta
+ result
+ "[m") ;no color
+ result)))
+
+(define* (test-runner-gnu test-name #:key color? brief? out-port trs-port)
+ "Return an custom SRFI-64 test runner. TEST-NAME is a string specifying the
+file name of the current the test. COLOR? specifies whether to use colors,
+and BRIEF?, well, you know. OUT-PORT and TRS-PORT must be output ports. The
+current output port is supposed to be redirected to a '.log' file."
+
+ (define (test-on-test-begin-gnu runner)
+ ;; Procedure called at the start of an individual test case, before the
+ ;; test expression (and expected value) are evaluated.
+ (let ((result (cute assq-ref (test-result-alist runner) <>)))
+ (test-display "test-name" (result 'test-name))
+ (test-display "location"
+ (string-append (result 'source-file) ":"
+ (number->string (result 'source-line))))
+ (test-display "source" (result 'source-form) #:pretty? #t)))
+
+ (define (test-on-test-end-gnu runner)
+ ;; Procedure called at the end of an individual test case, when the result
+ ;; of the test is available.
+ (let* ((results (test-result-alist runner))
+ (result? (cut assq <> results))
+ (result (cut assq-ref results <>)))
+ (unless brief?
+ ;; Display the result of each test case on the console.
+ (test-display
+ (result->string (test-result-kind runner) #:colorize? color?)
+ (string-append test-name " - " (test-runner-test-name runner))
+ out-port))
+ (when (result? 'expected-value)
+ (test-display "expected-value" (result 'expected-value)))
+ (when (result? 'expected-error)
+ (test-display "expected-error" (result 'expected-error) #:pretty? #t))
+ (when (result? 'actual-value)
+ (test-display "actual-value" (result 'actual-value)))
+ (when (result? 'actual-error)
+ (test-display "actual-error" (result 'actual-error) #:pretty? #t))
+ (test-display "result" (result->string (result 'result-kind)))
+ (newline)
+ (test-display ":test-result"
+ (string-append (result->string (test-result-kind runner))
+ " " (test-runner-test-name runner))
+ trs-port)))
+
+ (define (test-on-group-end-gnu runner)
+ ;; Procedure called by a 'test-end', including at the end of a test-group.
+ (let ((fail (or (positive? (test-runner-fail-count runner))
+ (positive? (test-runner-xpass-count runner))))
+ (skip (or (positive? (test-runner-skip-count runner))
+ (positive? (test-runner-xfail-count runner)))))
+ ;; XXX: The global results need some refinements for XPASS.
+ (test-display ":global-test-result"
+ (if fail "FAIL" (if skip "SKIP" "PASS"))
+ trs-port)
+ (test-display ":recheck"
+ (if fail "yes" "no")
+ trs-port)
+ (test-display ":copy-in-global-log"
+ (if (or fail skip) "yes" "no")
+ trs-port)
+ (when brief?
+ ;; Display the global test group result on the console.
+ (test-display (result->string (if fail 'fail (if skip 'skip 'pass))
+ #:colorize? color?)
+ test-name
+ out-port))
+ #f))
+
+ (let ((runner (test-runner-null)))
+ (test-runner-on-test-begin! runner test-on-test-begin-gnu)
+ (test-runner-on-test-end! runner test-on-test-end-gnu)
+ (test-runner-on-group-end! runner test-on-group-end-gnu)
+ (test-runner-on-bad-end-name! runner test-on-bad-end-name-simple)
+ runner))
+
+
+;;;
+;;; Entry point.
+;;;
+
+(define (main . args)
+ (let* ((opts (getopt-long (command-line) %options))
+ (option (cut option-ref opts <> <>)))
+ (cond
+ ((option 'help #f) (show-help))
+ ((option 'version #f) (format #t "test-driver.scm ~A" script-version))
+ (else
+ (let ((log (open-file (option 'log-file "") "w0"))
+ (trs (open-file (option 'trs-file "") "wl"))
+ (out (duplicate-port (current-output-port) "wl")))
+ (redirect-port log (current-output-port))
+ (redirect-port log (current-warning-port))
+ (redirect-port log (current-error-port))
+ (test-with-runner
+ (test-runner-gnu (option 'test-name #f)
+ #:color? (option->boolean opts 'color-tests)
+ #:brief? (option->boolean opts 'brief)
+ #:out-port out #:trs-port trs)
+ (load-from-path (option 'test-name #f)))
+ (close-port log)
+ (close-port trs)
+ (close-port out))))
+ (exit 0)))
+
+;;; Local Variables:
+;;; eval: (add-hook 'write-file-functions 'time-stamp)
+;;; time-stamp-start: "(define script-version \""
+;;; time-stamp-format: "%:y-%02m-%02d.%02H"
+;;; time-stamp-time-zone: "UTC"
+;;; time-stamp-end: "\") ;UTC"
+;;; End:
+
+;;;; test-driver.scm ends here.
M doc/guix.texi => doc/guix.texi +11 -5
@@ 596,12 596,18 @@ It is also possible to run a subset of the tests by defining the
make check TESTS="tests/store.scm tests/cpio.scm"
@end example
+By default, tests results are displayed at a file level. In order to
+see the details of every individual test cases, it is possible to define
+the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
+
+@example
+make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
+@end example
+
Upon failure, please email @email{bug-guix@@gnu.org} and attach the
-@file{test-suite.log} file. When @file{tests/@var{something}.scm}
-fails, please also attach the @file{@var{something}.log} file available
-in the top-level build directory. Please specify the Guix version being
-used as well as version numbers of the dependencies
-(@pxref{Requirements}) in your message.
+@file{test-suite.log} file. Please specify the Guix version being used
+as well as version numbers of the dependencies (@pxref{Requirements}) in
+your message.
@node Setting Up the Daemon
@section Setting Up the Daemon
M test-env.in => test-env.in +4 -0
@@ 31,6 31,10 @@ unset CDPATH
if [ -x "@abs_top_builddir@/guix-daemon" ]
then
+ # Silence the daemon's output, which is often useless, as well as that of
+ # Bash (such as "Terminated" messages when 'guix-daemon' is killed.)
+ exec 2> /dev/null
+
NIX_STORE_DIR="@GUIX_TEST_ROOT@/store"
# Do that because store.scm calls `canonicalize-path' on it.
M tests/base32.scm => tests/base32.scm +0 -3
@@ 101,6 101,3 @@
l))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/build-utils.scm => tests/build-utils.scm +0 -3
@@ 141,6 141,3 @@
(equal? str "hello world\n")))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/builders.scm => tests/builders.scm +0 -3
@@ 113,6 113,3 @@
(file-exists? (string-append out "/bin/hello")))))
(test-end "builders")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/challenge.scm => tests/challenge.scm +0 -3
@@ 106,9 106,6 @@
(test-end)
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'with-derivation-narinfo* 'scheme-indent-function 2)
;;; End:
M tests/containers.scm => tests/containers.scm +3 -6
@@ 26,14 26,14 @@
(define (assert-exit x)
(primitive-exit (if x 0 1)))
+(test-begin "containers")
+
;; Skip these tests unless user namespaces are available and the setgroups
;; file (introduced in Linux 3.19 to address a security issue) exists.
(unless (and (user-namespace-supported?)
(unprivileged-user-namespace-supported?)
(setgroups-supported?))
- (exit 77))
-
-(test-begin "containers")
+ (test-skip 7))
(test-assert "call-with-container, exit with 0 when there is no error"
(zero?
@@ 142,6 142,3 @@
(zero? result)))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/cpan.scm => tests/cpan.scm +0 -3
@@ 98,6 98,3 @@
(pk 'fail x #f)))))
(test-end "cpan")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/cpio.scm => tests/cpio.scm +0 -3
@@ 79,6 79,3 @@
(stat:size (stat file))))))))))))))
(test-end "cpio")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/cran.scm => tests/cran.scm +0 -3
@@ 131,6 131,3 @@ lines. And: this line continues the description.")
(pk 'fail x #f))))))
(test-end "cran")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/cve.scm => tests/cve.scm +0 -3
@@ 64,6 64,3 @@
(lookup "openoffice.org" "2.3.0"))))
(test-end "cve")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/derivations.scm => tests/derivations.scm +0 -3
@@ 1008,6 1008,3 @@
(call-with-input-file out get-string-all))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/elpa.scm => tests/elpa.scm +0 -3
@@ 104,6 104,3 @@ information about package NAME. (Function 'elpa-package-info'.)"
(eval-test-with-elpa "auctex"))
(test-end "elpa")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/file-systems.scm => tests/file-systems.scm +0 -3
@@ 51,6 51,3 @@
(equal? form '(uuid "foobar"))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/gem.scm => tests/gem.scm +0 -3
@@ 77,6 77,3 @@
(pk 'fail x #f)))))
(test-end "gem")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/gexp.scm => tests/gexp.scm +0 -3
@@ 784,9 784,6 @@
(test-end "gexp")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;; Local Variables:
;; eval: (put 'test-assertm 'scheme-indent-function 1)
;; End:
M tests/gnu-maintenance.scm => tests/gnu-maintenance.scm +0 -3
@@ 39,6 39,3 @@
("gnutls" "gnutls-3.2.18-w32.zip")))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/grafts.scm => tests/grafts.scm +0 -3
@@ 159,6 159,3 @@
(string=? (readlink two) one))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/graph.scm => tests/graph.scm +0 -3
@@ 276,6 276,3 @@ edges."
(list p1a p1b p0)))))))
(test-end "graph")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/gremlin.scm => tests/gremlin.scm +0 -3
@@ 64,6 64,3 @@
"ORIGIN/foo")))
(test-end "gremlin")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/hackage.scm => tests/hackage.scm +0 -3
@@ 160,6 160,3 @@ library
(x (pk 'fail x #f))))
(test-end "hackage")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/hash.scm => tests/hash.scm +0 -3
@@ 126,6 126,3 @@ In Guile <= 2.0.9, CBIPs were always fully buffered, so the
(list hello hash world))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/import-utils.scm => tests/import-utils.scm +0 -3
@@ 34,6 34,3 @@
(beautify-description "A function to establish world peace"))
(test-end "import-utils")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/lint.scm => tests/lint.scm +0 -3
@@ 581,9 581,6 @@ requests."
(test-end "lint")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;; Local Variables:
;; eval: (put 'with-http-server 'scheme-indent-function 1)
;; eval: (put 'with-warnings 'scheme-indent-function 0)
M tests/monads.scm => tests/monads.scm +0 -3
@@ 258,6 258,3 @@
'())))
(test-end "monads")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/nar.scm => tests/nar.scm +0 -3
@@ 320,9 320,6 @@
(test-end "nar")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'with-file-tree 'scheme-indent-function 2)
;;; End:
M tests/packages.scm => tests/packages.scm +0 -3
@@ 799,9 799,6 @@
(test-end "packages")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'dummy-package 'scheme-indent-function 1)
;;; End:
M tests/pk-crypto.scm => tests/pk-crypto.scm +0 -3
@@ 287,6 287,3 @@
(canonical-sexp->sexp (sexp->canonical-sexp sexp))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/pki.scm => tests/pki.scm +0 -3
@@ 119,6 119,3 @@
(corrupt-signature 'c))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/profiles.scm => tests/profiles.scm +0 -3
@@ 320,9 320,6 @@
(test-end "profiles")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'dummy-package 'scheme-indent-function 1)
;;; End:
M tests/publish.scm => tests/publish.scm +0 -3
@@ 121,6 121,3 @@ References: ~a~%"
(response-code (http-get (publish-uri (string-append "/nar/invalid"))))))
(test-end "publish")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/pypi.scm => tests/pypi.scm +0 -3
@@ 106,6 106,3 @@ baz > 13.37")
(pk 'fail x #f)))))
(test-end "pypi")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/records.scm => tests/records.scm +0 -3
@@ 305,6 305,3 @@ Description: 1st line,
'("a")))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/scripts-build.scm => tests/scripts-build.scm +0 -3
@@ 103,6 103,3 @@
(eq? dep findutils)))))))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/scripts.scm => tests/scripts.scm +0 -3
@@ 64,9 64,6 @@
(test-end "scripts")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'with-environment-variable 'scheme-indent-function 2)
;;; End:
M tests/services.scm => tests/services.scm +0 -3
@@ 119,6 119,3 @@
(null? (e s3)))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/sets.scm => tests/sets.scm +0 -3
@@ 47,6 47,3 @@
(set-contains? s3 b))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/size.scm => tests/size.scm +0 -3
@@ 88,9 88,6 @@
(test-end "size")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'match* 'scheme-indent-function 1)
;;; End:
M tests/snix.scm => tests/snix.scm +0 -3
@@ 71,6 71,3 @@
(pk 'fail x #f))))
(test-end "snix")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/store.scm => tests/store.scm +0 -3
@@ 911,6 911,3 @@
(path-info-deriver (query-path-info %store o))))))
(test-end "store")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/substitute.scm => tests/substitute.scm +0 -3
@@ 275,9 275,6 @@ a file for NARINFO."
(test-end "substitute")
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
-
;;; Local Variables:
;;; eval: (put 'with-narinfo 'scheme-indent-function 1)
;;; eval: (put 'test-quit 'scheme-indent-function 2)
M tests/syscalls.scm => tests/syscalls.scm +0 -3
@@ 245,6 245,3 @@
(lo (interface-address lo)))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/system.scm => tests/system.scm +0 -3
@@ 72,6 72,3 @@
(eq? gnu (operating-system-store-file-system os))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/ui.scm => tests/ui.scm +0 -3
@@ 250,6 250,3 @@ Second line" 24))
(show-manifest-transaction store m t)))))))))
(test-end "ui")
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/union.scm => tests/union.scm +0 -3
@@ 125,6 125,3 @@
(eq? 'directory (stat:type (lstat "bin"))))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/upstream.scm => tests/upstream.scm +0 -3
@@ 44,6 44,3 @@
'("ftp://example.org/foo-1.tar.xz.sig"))))))
(test-end)
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))
M tests/utils.scm => tests/utils.scm +0 -3
@@ 336,6 336,3 @@
(test-end)
(false-if-exception (delete-file temp-file))
-
-
-(exit (= (test-runner-fail-count (test-runner-current)) 0))