1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; test-suite/lib.scm --- generic support for testing
|
2011-01-26 00:16:10 +01:00
|
|
|
|
;;;; Copyright (C) 1999, 2000, 2001, 2004, 2006, 2007, 2009, 2010,
|
|
|
|
|
|
;;;; 2011 Free Software Foundation, Inc.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; 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.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; 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
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; GNU Lesser General Public License for more details.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; 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
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
2001-02-28 11:25:40 +00:00
|
|
|
|
(define-module (test-suite lib)
|
2010-11-17 23:04:11 +01:00
|
|
|
|
#:use-module (ice-9 stack-catch)
|
|
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
|
|
#:autoload (srfi srfi-1) (append-map)
|
|
|
|
|
|
#:autoload (system base compile) (compile)
|
|
|
|
|
|
#:export (
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
2001-02-28 11:25:40 +00:00
|
|
|
|
;; Exceptions which are commonly being tested for.
|
2010-01-30 22:54:20 +01:00
|
|
|
|
exception:syntax-pattern-unmatched
|
* libguile/eval.c (scm_m_let, scm_m_letstar, scm_m_letrec,
scm_m_expand_body, check_bindings): Extracted syntax checking of
bindings to new static function check_bindings.
(scm_m_let, memoize_named_let): Extracted handling of named let to
new static function memoize_named_let.
(transform_bindings, scm_m_let, scm_m_letstar, scm_m_letrec): Use
ASSERT_SYNTAX to signal syntax errors. Be more specific about the
kind of error that was detected. Avoid use of SCM_CDRLOC. Avoid
unnecessary consing when creating the memoized code.
* test-suite/lib.scm (exception:bad-variable): New.
* test-suite/tests/syntax.test (exception:bad-binding,
exception:duplicate-binding): New.
(exception:duplicate-bindings): Removed.
Adapted tests for 'let', 'let*' and 'letrec' to the new way of
error reporting.
2003-10-18 12:07:39 +00:00
|
|
|
|
exception:bad-variable
|
2003-10-07 22:00:05 +00:00
|
|
|
|
exception:missing-expression
|
2001-03-02 01:38:01 +00:00
|
|
|
|
exception:out-of-range exception:unbound-var
|
2004-08-23 10:48:51 +00:00
|
|
|
|
exception:used-before-defined
|
2001-03-02 01:38:01 +00:00
|
|
|
|
exception:wrong-num-args exception:wrong-type-arg
|
2004-05-29 22:09:52 +00:00
|
|
|
|
exception:numerical-overflow
|
2006-06-13 07:48:42 +00:00
|
|
|
|
exception:struct-set!-denied
|
2007-06-07 08:36:13 +00:00
|
|
|
|
exception:system-error
|
2010-01-07 11:00:37 +01:00
|
|
|
|
exception:encoding-error
|
2006-06-13 07:48:42 +00:00
|
|
|
|
exception:miscellaneous-error
|
2007-01-18 23:10:13 +00:00
|
|
|
|
exception:string-contains-nul
|
2009-06-19 00:47:11 +02:00
|
|
|
|
exception:read-error
|
2010-04-09 00:30:10 +02:00
|
|
|
|
exception:null-pointer-error
|
2010-05-26 23:00:58 +02:00
|
|
|
|
exception:vm-error
|
2001-02-28 11:25:40 +00:00
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;; Reporting passes and failures.
|
2001-02-28 11:25:40 +00:00
|
|
|
|
run-test
|
|
|
|
|
|
pass-if expect-fail
|
|
|
|
|
|
pass-if-exception expect-fail-exception
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;; Naming groups of tests in a regular fashion.
|
2010-11-17 23:04:11 +01:00
|
|
|
|
with-test-prefix
|
|
|
|
|
|
with-test-prefix*
|
|
|
|
|
|
with-test-prefix/c&e
|
|
|
|
|
|
current-test-prefix
|
2003-10-07 22:00:05 +00:00
|
|
|
|
format-test-name
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
2007-10-21 20:45:45 +00:00
|
|
|
|
;; Using the debugging evaluator.
|
|
|
|
|
|
with-debugging-evaluator with-debugging-evaluator*
|
|
|
|
|
|
|
2010-03-04 00:39:18 +01:00
|
|
|
|
;; Using a given locale
|
|
|
|
|
|
with-locale with-locale* with-latin1-locale with-latin1-locale*
|
2009-08-28 06:27:00 -07:00
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;; Reporting results in various ways.
|
|
|
|
|
|
register-reporter unregister-reporter reporter-registered?
|
|
|
|
|
|
make-count-reporter print-counts
|
2001-08-01 09:57:01 +00:00
|
|
|
|
make-log-reporter
|
1999-05-31 21:27:20 +00:00
|
|
|
|
full-reporter
|
2003-10-07 22:00:05 +00:00
|
|
|
|
user-reporter))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; If you're using Emacs's Scheme mode:
|
|
|
|
|
|
;;;; (put 'with-test-prefix 'scheme-indent-function 1)
|
|
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
;;;; CORE FUNCTIONS
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; The function (run-test name expected-result thunk) is the heart of the
|
|
|
|
|
|
;;;; testing environment. The first parameter NAME is a unique name for the
|
|
|
|
|
|
;;;; test to be executed (for an explanation of this parameter see below under
|
|
|
|
|
|
;;;; TEST NAMES). The second parameter EXPECTED-RESULT is a boolean value
|
|
|
|
|
|
;;;; that indicates whether the corresponding test is expected to pass. If
|
|
|
|
|
|
;;;; EXPECTED-RESULT is #t the test is expected to pass, if EXPECTED-RESULT is
|
|
|
|
|
|
;;;; #f the test is expected to fail. Finally, THUNK is the function that
|
|
|
|
|
|
;;;; actually performs the test. For example:
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; (run-test "integer addition" #t (lambda () (= 2 (+ 1 1))))
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; To report success, THUNK should either return #t or throw 'pass. To
|
|
|
|
|
|
;;;; report failure, THUNK should either return #f or throw 'fail. If THUNK
|
|
|
|
|
|
;;;; returns a non boolean value or throws 'unresolved, this indicates that
|
|
|
|
|
|
;;;; the test did not perform as expected. For example the property that was
|
|
|
|
|
|
;;;; to be tested could not be tested because something else went wrong.
|
|
|
|
|
|
;;;; THUNK may also throw 'untested to indicate that the test was deliberately
|
|
|
|
|
|
;;;; not performed, for example because the test case is not complete yet.
|
|
|
|
|
|
;;;; Finally, if THUNK throws 'unsupported, this indicates that this test
|
|
|
|
|
|
;;;; requires some feature that is not available in the configured testing
|
|
|
|
|
|
;;;; environment. All other exceptions thrown by THUNK are considered as
|
|
|
|
|
|
;;;; errors.
|
|
|
|
|
|
;;;;
|
2001-02-28 11:25:40 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Convenience macros for tests expected to pass or fail
|
|
|
|
|
|
;;;;
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;; * (pass-if name body) is a short form for
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; (run-test name #t (lambda () body))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;; * (expect-fail name body) is a short form for
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; (run-test name #f (lambda () body))
|
|
|
|
|
|
;;;;
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;; For example:
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; (pass-if "integer addition" (= 2 (+ 1 1)))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Convenience macros to test for exceptions
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; The following macros take exception parameters which are pairs
|
|
|
|
|
|
;;;; (type . message), where type is a symbol that denotes an exception type
|
|
|
|
|
|
;;;; like 'wrong-type-arg or 'out-of-range, and message is a string holding a
|
|
|
|
|
|
;;;; regular expression that describes the error message for the exception
|
|
|
|
|
|
;;;; like "Argument .* out of range".
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; * (pass-if-exception name exception body) will pass if the execution of
|
|
|
|
|
|
;;;; body causes the given exception to be thrown. If no exception is
|
|
|
|
|
|
;;;; thrown, the test fails. If some other exception is thrown, is is an
|
|
|
|
|
|
;;;; error.
|
|
|
|
|
|
;;;; * (expect-fail-exception name exception body) will pass unexpectedly if
|
|
|
|
|
|
;;;; the execution of body causes the given exception to be thrown. If no
|
|
|
|
|
|
;;;; exception is thrown, the test fails expectedly. If some other
|
|
|
|
|
|
;;;; exception is thrown, it is an error.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;;; TEST NAMES
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Every test in the test suite has a unique name, to help
|
|
|
|
|
|
;;;; developers find tests that are failing (or unexpectedly passing),
|
|
|
|
|
|
;;;; and to help gather statistics.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; A test name is a list of printable objects. For example:
|
|
|
|
|
|
;;;; ("ports.scm" "file" "read and write back list of strings")
|
|
|
|
|
|
;;;; ("ports.scm" "pipe" "read")
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; Test names may contain arbitrary objects, but they always have
|
|
|
|
|
|
;;;; the following properties:
|
|
|
|
|
|
;;;; - Test names can be compared with EQUAL?.
|
|
|
|
|
|
;;;; - Test names can be reliably stored and retrieved with the standard WRITE
|
|
|
|
|
|
;;;; and READ procedures; doing so preserves their identity.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; For example:
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; (pass-if "simple addition" (= 4 (+ 2 2)))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; In that case, the test name is the list ("simple addition").
|
|
|
|
|
|
;;;;
|
2003-05-30 10:35:05 +00:00
|
|
|
|
;;;; In the case of simple tests the expression that is tested would often
|
|
|
|
|
|
;;;; suffice as a test name by itself. Therefore, the convenience macros
|
|
|
|
|
|
;;;; pass-if and expect-fail provide a shorthand notation that allows to omit
|
|
|
|
|
|
;;;; a test name in such cases.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; * (pass-if expression) is a short form for
|
|
|
|
|
|
;;;; (run-test 'expression #t (lambda () expression))
|
|
|
|
|
|
;;;; * (expect-fail expression) is a short form for
|
|
|
|
|
|
;;;; (run-test 'expression #f (lambda () expression))
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; For example:
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; (pass-if (= 2 (+ 1 1)))
|
|
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; The WITH-TEST-PREFIX syntax and WITH-TEST-PREFIX* procedure establish
|
|
|
|
|
|
;;;; a prefix for the names of all tests whose results are reported
|
|
|
|
|
|
;;;; within their dynamic scope. For example:
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; (begin
|
|
|
|
|
|
;;;; (with-test-prefix "basic arithmetic"
|
|
|
|
|
|
;;;; (pass-if "addition" (= (+ 2 2) 4))
|
2000-03-22 21:18:57 +00:00
|
|
|
|
;;;; (pass-if "subtraction" (= (- 4 2) 2)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; (pass-if "multiplication" (= (* 2 2) 4)))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; In that example, the three test names are:
|
|
|
|
|
|
;;;; ("basic arithmetic" "addition"),
|
2000-03-22 21:18:57 +00:00
|
|
|
|
;;;; ("basic arithmetic" "subtraction"), and
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; ("multiplication").
|
|
|
|
|
|
;;;;
|
Misc textual editing
* doc/ref/api-scheduling.texi (Asyncs): "queueing" -> "queuing".
* benchmark-suite/lib.scm, doc/sources/unix.texi (Unix conventions),
test-suite/lib.scm: "postpend" -> "append".
* doc/ref/api-compound.texi (Array Syntax, Dictionary Types),
doc/ref/api-control.texi (Catch), doc/ref/api-data.texi (Complex
Numbers, Conversion, Random, Symbol Props, Symbol Uninterned),
doc/ref/api-options.texi (Build Config, Common Feature Symbols),
doc/ref/api-regex.texi (Match Structures),
doc/ref/api-undocumented.texi, doc/ref/compiler.texi (Tree-IL,
GLIL), doc/ref/data-rep.texi (Immediate objects), doc/ref/goops.texi
(Slot Description Example), doc/ref/history.texi (A Scheme of Many
Maintainers, Status), doc/ref/libguile-program.texi (Available
Functionality), doc/ref/misc-modules.texi (Formatted Output),
doc/ref/mod-getopt-long.texi (getopt-long Reference),
doc/ref/posix.texi (Network Socket Address, Network Sockets and
Communication), doc/ref/srfi-modules.texi (SRFI-1 Association Lists,
SRFI-10, SRFI-19 String to date, SRFI-27 Random Sources),
doc/ref/vm.texi (Instruction Set, Top-Level Environment
Instructions, Procedure Call and Return Instructions),
doc/sources/unix.texi (Unix conventions): Correct spacing after
"i.e." and "e.g.".
2011-02-13 22:13:33 +00:00
|
|
|
|
;;;; WITH-TEST-PREFIX can be nested. Each WITH-TEST-PREFIX appends
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; a new element to the current prefix:
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; (with-test-prefix "arithmetic"
|
|
|
|
|
|
;;;; (with-test-prefix "addition"
|
|
|
|
|
|
;;;; (pass-if "integer" (= (+ 2 2) 4))
|
|
|
|
|
|
;;;; (pass-if "complex" (= (+ 2+3i 4+5i) 6+8i)))
|
|
|
|
|
|
;;;; (with-test-prefix "subtraction"
|
|
|
|
|
|
;;;; (pass-if "integer" (= (- 2 2) 0))
|
|
|
|
|
|
;;;; (pass-if "complex" (= (- 2+3i 1+2i) 1+1i))))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; The four test names here are:
|
|
|
|
|
|
;;;; ("arithmetic" "addition" "integer")
|
|
|
|
|
|
;;;; ("arithmetic" "addition" "complex")
|
|
|
|
|
|
;;;; ("arithmetic" "subtraction" "integer")
|
|
|
|
|
|
;;;; ("arithmetic" "subtraction" "complex")
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; To print a name for a human reader, we DISPLAY its elements,
|
|
|
|
|
|
;;;; separated by ": ". So, the last set of test names would be
|
|
|
|
|
|
;;;; reported as:
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; arithmetic: addition: integer
|
|
|
|
|
|
;;;; arithmetic: addition: complex
|
|
|
|
|
|
;;;; arithmetic: subtraction: integer
|
|
|
|
|
|
;;;; arithmetic: subtraction: complex
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; The Guile benchmarks use with-test-prefix to include the name of
|
|
|
|
|
|
;;;; the source file containing the test in the test name, to help
|
|
|
|
|
|
;;;; developers to find failing tests, and to provide each file with its
|
|
|
|
|
|
;;;; own namespace.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; REPORTERS
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; A reporter is a function which we apply to each test outcome.
|
|
|
|
|
|
;;;; Reporters can log results, print interesting results to the
|
|
|
|
|
|
;;;; standard output, collect statistics, etc.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; A reporter function takes two mandatory arguments, RESULT and TEST, and
|
|
|
|
|
|
;;;; possibly additional arguments depending on RESULT; its return value
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;; is ignored. RESULT has one of the following forms:
|
|
|
|
|
|
;;;;
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;; pass - The test named TEST passed.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; upass - The test named TEST passed unexpectedly.
|
|
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; fail - The test named TEST failed.
|
|
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; xfail - The test named TEST failed, as expected.
|
|
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; unresolved - The test named TEST did not perform as expected, for
|
|
|
|
|
|
;;;; example the property that was to be tested could not be
|
|
|
|
|
|
;;;; tested because something else went wrong.
|
|
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; untested - The test named TEST was not actually performed, for
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;; example because the test case is not complete yet.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; unsupported - The test named TEST requires some feature that is not
|
|
|
|
|
|
;;;; available in the configured testing environment.
|
|
|
|
|
|
;;;; Additional arguments are ignored.
|
|
|
|
|
|
;;;; error - An error occurred while the test named TEST was
|
|
|
|
|
|
;;;; performed. Since this result means that the system caught
|
|
|
|
|
|
;;;; an exception it could not handle, the exception arguments
|
|
|
|
|
|
;;;; are passed as additional arguments.
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This library provides some standard reporters for logging results
|
|
|
|
|
|
;;;; to a file, reporting interesting results to the user, and
|
|
|
|
|
|
;;;; collecting totals.
|
1999-05-31 21:27:20 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You can use the REGISTER-REPORTER function and friends to add
|
|
|
|
|
|
;;;; whatever reporting functions you like. If you don't register any
|
|
|
|
|
|
;;;; reporters, the library uses FULL-REPORTER, which simply writes
|
|
|
|
|
|
;;;; all results to the standard output.
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; MISCELLANEOUS
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
|
2001-02-28 11:25:40 +00:00
|
|
|
|
;;; Define some exceptions which are commonly being tested for.
|
2010-01-30 22:54:20 +01:00
|
|
|
|
(define exception:syntax-pattern-unmatched
|
|
|
|
|
|
(cons 'syntax-error "source expression failed to match any pattern"))
|
* libguile/eval.c (scm_m_let, scm_m_letstar, scm_m_letrec,
scm_m_expand_body, check_bindings): Extracted syntax checking of
bindings to new static function check_bindings.
(scm_m_let, memoize_named_let): Extracted handling of named let to
new static function memoize_named_let.
(transform_bindings, scm_m_let, scm_m_letstar, scm_m_letrec): Use
ASSERT_SYNTAX to signal syntax errors. Be more specific about the
kind of error that was detected. Avoid use of SCM_CDRLOC. Avoid
unnecessary consing when creating the memoized code.
* test-suite/lib.scm (exception:bad-variable): New.
* test-suite/tests/syntax.test (exception:bad-binding,
exception:duplicate-binding): New.
(exception:duplicate-bindings): Removed.
Adapted tests for 'let', 'let*' and 'letrec' to the new way of
error reporting.
2003-10-18 12:07:39 +00:00
|
|
|
|
(define exception:bad-variable
|
|
|
|
|
|
(cons 'syntax-error "Bad variable"))
|
2003-10-07 22:00:05 +00:00
|
|
|
|
(define exception:missing-expression
|
|
|
|
|
|
(cons 'misc-error "^missing or extra expression"))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
(define exception:out-of-range
|
2004-09-23 17:57:55 +00:00
|
|
|
|
(cons 'out-of-range "^.*out of range"))
|
2001-03-02 01:38:01 +00:00
|
|
|
|
(define exception:unbound-var
|
|
|
|
|
|
(cons 'unbound-variable "^Unbound variable"))
|
2004-08-23 10:48:51 +00:00
|
|
|
|
(define exception:used-before-defined
|
|
|
|
|
|
(cons 'unbound-variable "^Variable used before given a value"))
|
2001-03-02 01:38:01 +00:00
|
|
|
|
(define exception:wrong-num-args
|
|
|
|
|
|
(cons 'wrong-number-of-args "^Wrong number of arguments"))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
(define exception:wrong-type-arg
|
2004-09-23 17:57:55 +00:00
|
|
|
|
(cons 'wrong-type-arg "^Wrong type"))
|
2004-05-29 22:09:52 +00:00
|
|
|
|
(define exception:numerical-overflow
|
|
|
|
|
|
(cons 'numerical-overflow "^Numerical overflow"))
|
2006-06-13 07:48:42 +00:00
|
|
|
|
(define exception:struct-set!-denied
|
|
|
|
|
|
(cons 'misc-error "^set! denied for field"))
|
2007-06-07 08:36:13 +00:00
|
|
|
|
(define exception:system-error
|
|
|
|
|
|
(cons 'system-error ".*"))
|
2010-01-07 11:00:37 +01:00
|
|
|
|
(define exception:encoding-error
|
2011-01-26 00:16:10 +01:00
|
|
|
|
(cons 'encoding-error "(cannot convert to output locale|input (locale conversion|decoding) error)"))
|
2006-06-13 07:48:42 +00:00
|
|
|
|
(define exception:miscellaneous-error
|
|
|
|
|
|
(cons 'misc-error "^.*"))
|
2009-06-19 00:47:11 +02:00
|
|
|
|
(define exception:read-error
|
|
|
|
|
|
(cons 'read-error "^.*$"))
|
2010-04-09 00:30:10 +02:00
|
|
|
|
(define exception:null-pointer-error
|
|
|
|
|
|
(cons 'null-pointer-error "^.*$"))
|
2010-05-26 23:00:58 +02:00
|
|
|
|
(define exception:vm-error
|
|
|
|
|
|
(cons 'vm-error "^.*$"))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
|
2007-01-18 23:10:13 +00:00
|
|
|
|
;; as per throw in scm_to_locale_stringn()
|
|
|
|
|
|
(define exception:string-contains-nul
|
|
|
|
|
|
(cons 'misc-error "^string contains #\\\\nul character"))
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;; Display all parameters to the default output port, followed by a newline.
|
|
|
|
|
|
(define (display-line . objs)
|
|
|
|
|
|
(for-each display objs)
|
|
|
|
|
|
(newline))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Display all parameters to the given output port, followed by a newline.
|
|
|
|
|
|
(define (display-line-port port . objs)
|
|
|
|
|
|
(for-each (lambda (obj) (display obj port)) objs)
|
|
|
|
|
|
(newline port))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;; CORE FUNCTIONS
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;; The central testing routine.
|
|
|
|
|
|
;;; The idea is taken from Greg, the GNUstep regression test environment.
|
|
|
|
|
|
(define run-test #f)
|
|
|
|
|
|
(let ((test-running #f))
|
|
|
|
|
|
(define (local-run-test name expect-pass thunk)
|
|
|
|
|
|
(if test-running
|
|
|
|
|
|
(error "Nested calls to run-test are not permitted.")
|
|
|
|
|
|
(let ((test-name (full-name name)))
|
|
|
|
|
|
(set! test-running #t)
|
|
|
|
|
|
(catch #t
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(let ((result (thunk)))
|
|
|
|
|
|
(if (eq? result #t) (throw 'pass))
|
|
|
|
|
|
(if (eq? result #f) (throw 'fail))
|
|
|
|
|
|
(throw 'unresolved)))
|
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
|
(case key
|
2001-08-01 09:57:01 +00:00
|
|
|
|
((pass)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(report (if expect-pass 'pass 'upass) test-name))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
((fail)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(report (if expect-pass 'fail 'xfail) test-name))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
((unresolved untested unsupported)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(report key test-name))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
((quit)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(report 'unresolved test-name)
|
|
|
|
|
|
(quit))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(else
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(report 'error test-name (cons key args))))))
|
|
|
|
|
|
(set! test-running #f))))
|
|
|
|
|
|
(set! run-test local-run-test))
|
|
|
|
|
|
|
|
|
|
|
|
;;; A short form for tests that are expected to pass, taken from Greg.
|
2009-05-18 23:45:35 +02:00
|
|
|
|
(define-syntax pass-if
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name)
|
|
|
|
|
|
;; presume this is a simple test, i.e. (pass-if (even? 2))
|
|
|
|
|
|
;; where the body should also be the name.
|
|
|
|
|
|
(run-test 'name #t (lambda () name)))
|
|
|
|
|
|
((_ name rest ...)
|
|
|
|
|
|
(run-test name #t (lambda () rest ...)))))
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A short form for tests that are expected to fail, taken from Greg.
|
2009-05-18 23:45:35 +02:00
|
|
|
|
(define-syntax expect-fail
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name)
|
|
|
|
|
|
;; presume this is a simple test, i.e. (expect-fail (even? 2))
|
|
|
|
|
|
;; where the body should also be the name.
|
|
|
|
|
|
(run-test 'name #f (lambda () name)))
|
|
|
|
|
|
((_ name rest ...)
|
|
|
|
|
|
(run-test name #f (lambda () rest ...)))))
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
2001-02-28 11:25:40 +00:00
|
|
|
|
;;; A helper function to implement the macros that test for exceptions.
|
|
|
|
|
|
(define (run-test-exception name exception expect-pass thunk)
|
|
|
|
|
|
(run-test name expect-pass
|
|
|
|
|
|
(lambda ()
|
2001-03-05 11:05:02 +00:00
|
|
|
|
(stack-catch (car exception)
|
2001-02-28 11:25:40 +00:00
|
|
|
|
(lambda () (thunk) #f)
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(lambda (key proc message . rest)
|
|
|
|
|
|
(cond
|
|
|
|
|
|
;; handle explicit key
|
|
|
|
|
|
((string-match (cdr exception) message)
|
|
|
|
|
|
#t)
|
|
|
|
|
|
;; handle `(error ...)' which uses `misc-error' for key and doesn't
|
|
|
|
|
|
;; yet format the message and args (we have to do it here).
|
|
|
|
|
|
((and (eq? 'misc-error (car exception))
|
|
|
|
|
|
(list? rest)
|
|
|
|
|
|
(string-match (cdr exception)
|
|
|
|
|
|
(apply simple-format #f message (car rest))))
|
|
|
|
|
|
#t)
|
2003-10-10 21:49:27 +00:00
|
|
|
|
;; handle syntax errors which use `syntax-error' for key and don't
|
|
|
|
|
|
;; yet format the message and args (we have to do it here).
|
|
|
|
|
|
((and (eq? 'syntax-error (car exception))
|
|
|
|
|
|
(list? rest)
|
|
|
|
|
|
(string-match (cdr exception)
|
|
|
|
|
|
(apply simple-format #f message (car rest))))
|
|
|
|
|
|
#t)
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;; unhandled; throw again
|
|
|
|
|
|
(else
|
|
|
|
|
|
(apply throw key proc message rest))))))))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A short form for tests that expect a certain exception to be thrown.
|
2009-05-18 23:45:35 +02:00
|
|
|
|
(define-syntax pass-if-exception
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name exception body rest ...)
|
|
|
|
|
|
(run-test-exception name exception #t (lambda () body rest ...)))))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A short form for tests expected to fail to throw a certain exception.
|
2009-05-18 23:45:35 +02:00
|
|
|
|
(define-syntax expect-fail-exception
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ name exception body rest ...)
|
|
|
|
|
|
(run-test-exception name exception #f (lambda () body rest ...)))))
|
2001-02-28 11:25:40 +00:00
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
;;;; TEST NAMES
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;;; Turn a test name into a nice human-readable string.
|
|
|
|
|
|
(define (format-test-name name)
|
2010-01-07 11:00:37 +01:00
|
|
|
|
;; Choose a Unicode-capable encoding so that the string port can contain any
|
|
|
|
|
|
;; valid Unicode character.
|
|
|
|
|
|
(with-fluids ((%default-port-encoding "UTF-8"))
|
|
|
|
|
|
(call-with-output-string
|
|
|
|
|
|
(lambda (port)
|
|
|
|
|
|
(let loop ((name name)
|
|
|
|
|
|
(separator ""))
|
|
|
|
|
|
(if (pair? name)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display separator port)
|
|
|
|
|
|
(display (car name) port)
|
|
|
|
|
|
(loop (cdr name) ": "))))))))
|
2000-05-08 17:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
;;;; For a given test-name, deliver the full name including all prefixes.
|
|
|
|
|
|
(define (full-name name)
|
|
|
|
|
|
(append (current-test-prefix) (list name)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A fluid containing the current test prefix, as a list.
|
2011-11-23 12:40:33 +01:00
|
|
|
|
(define prefix-fluid (make-fluid '()))
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(define (current-test-prefix)
|
|
|
|
|
|
(fluid-ref prefix-fluid))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; Postpend PREFIX to the current name prefix while evaluting THUNK.
|
|
|
|
|
|
;;; The name prefix is only changed within the dynamic scope of the
|
|
|
|
|
|
;;; call to with-test-prefix*. Return the value returned by THUNK.
|
|
|
|
|
|
(define (with-test-prefix* prefix thunk)
|
|
|
|
|
|
(with-fluids ((prefix-fluid
|
|
|
|
|
|
(append (fluid-ref prefix-fluid) (list prefix))))
|
|
|
|
|
|
(thunk)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; (with-test-prefix PREFIX BODY ...)
|
|
|
|
|
|
;;; Postpend PREFIX to the current name prefix while evaluating BODY ...
|
|
|
|
|
|
;;; The name prefix is only changed within the dynamic scope of the
|
|
|
|
|
|
;;; with-test-prefix expression. Return the value returned by the last
|
|
|
|
|
|
;;; BODY expression.
|
2010-11-17 23:04:11 +01:00
|
|
|
|
(define-syntax with-test-prefix
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ prefix body ...)
|
|
|
|
|
|
(with-test-prefix* prefix (lambda () body ...)))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax c&e
|
|
|
|
|
|
(syntax-rules (pass-if pass-if-exception)
|
|
|
|
|
|
"Run the given tests both with the evaluator and the compiler/VM."
|
|
|
|
|
|
((_ (pass-if test-name exp))
|
|
|
|
|
|
(begin (pass-if (string-append test-name " (eval)")
|
|
|
|
|
|
(primitive-eval 'exp))
|
|
|
|
|
|
(pass-if (string-append test-name " (compile)")
|
|
|
|
|
|
(compile 'exp #:to 'value #:env (current-module)))))
|
|
|
|
|
|
((_ (pass-if-exception test-name exc exp))
|
|
|
|
|
|
(begin (pass-if-exception (string-append test-name " (eval)")
|
|
|
|
|
|
exc (primitive-eval 'exp))
|
|
|
|
|
|
(pass-if-exception (string-append test-name " (compile)")
|
|
|
|
|
|
exc (compile 'exp #:to 'value
|
|
|
|
|
|
#:env (current-module)))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; (with-test-prefix/c&e PREFIX BODY ...)
|
|
|
|
|
|
;;; Same as `with-test-prefix', but the enclosed tests are run both with
|
|
|
|
|
|
;;; the compiler/VM and the evaluator.
|
|
|
|
|
|
(define-syntax with-test-prefix/c&e
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ section-name exp ...)
|
|
|
|
|
|
(with-test-prefix section-name (c&e exp) ...))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
2007-10-21 20:45:45 +00:00
|
|
|
|
;;; Call THUNK using the debugging evaluator.
|
|
|
|
|
|
(define (with-debugging-evaluator* thunk)
|
|
|
|
|
|
(let ((dopts #f))
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda ()
|
remove a number of debug options
* libguile/private-options.h (SCM_BREAKPOINTS_P, SCM_TRACE_P)
(SCM_REC_PROCNAMES_P, SCM_BACKTRACE_INDENT, SCM_N_FRAMES)
(SCM_BACKTRACE_MAXDEPTH, SCM_DEVAL_P): Remove these internal names.
* libguile/eval.c (scm_debug_opts): Remove the corresponding debug
options -- breakpoints, trace, procnames, indent, frames, maxdepth,
and debug.
* libguile/debug.c (scm_debug_options): Remove SCM_N_FRAMES check.
* test-suite/lib.scm (with-debugging-evaluator*):
* module/scripts/summarize-guile-TODO.scm:
* module/statprof.scm (statprof-reset):
* module/ice-9/boot-9.scm (turn-on-debugging): Remove useless
debug-enable 'debug calls.
* module/ice-9/deprecated.scm (debug-enable): As it seems that 'debug is
a particulatly common option that we just removed, add a deprecation
shim.
* doc/ref/api-options.texi (Debugger options): Update the set of debug
options.
2010-09-24 20:49:46 +02:00
|
|
|
|
(set! dopts (debug-options)))
|
2007-10-21 20:45:45 +00:00
|
|
|
|
thunk
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(debug-options dopts)))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Evaluate BODY... using the debugging evaluator.
|
|
|
|
|
|
(define-macro (with-debugging-evaluator . body)
|
|
|
|
|
|
`(with-debugging-evaluator* (lambda () ,@body)))
|
|
|
|
|
|
|
2009-08-28 06:27:00 -07:00
|
|
|
|
;;; Call THUNK with a given locale
|
|
|
|
|
|
(define (with-locale* nloc thunk)
|
|
|
|
|
|
(let ((loc #f))
|
|
|
|
|
|
(dynamic-wind
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(if (defined? 'setlocale)
|
|
|
|
|
|
(begin
|
2010-03-03 23:57:50 +01:00
|
|
|
|
(set! loc (false-if-exception (setlocale LC_ALL)))
|
|
|
|
|
|
(if (or (not loc)
|
|
|
|
|
|
(not (false-if-exception (setlocale LC_ALL nloc))))
|
2009-08-28 06:27:00 -07:00
|
|
|
|
(throw 'unresolved)))
|
|
|
|
|
|
(throw 'unresolved)))
|
|
|
|
|
|
thunk
|
|
|
|
|
|
(lambda ()
|
2010-03-03 23:57:50 +01:00
|
|
|
|
(if (and (defined? 'setlocale) loc)
|
2009-08-28 06:27:00 -07:00
|
|
|
|
(setlocale LC_ALL loc))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Evaluate BODY... using the given locale.
|
2010-03-03 23:57:50 +01:00
|
|
|
|
(define-syntax with-locale
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ loc body ...)
|
|
|
|
|
|
(with-locale* loc (lambda () body ...)))))
|
2007-10-21 20:45:45 +00:00
|
|
|
|
|
2010-03-04 00:39:18 +01:00
|
|
|
|
;;; Try out several ISO-8859-1 locales and run THUNK under the one that works
|
|
|
|
|
|
;;; (if any).
|
|
|
|
|
|
(define (with-latin1-locale* thunk)
|
|
|
|
|
|
(define %locales
|
|
|
|
|
|
(append-map (lambda (name)
|
|
|
|
|
|
(list (string-append name ".ISO-8859-1")
|
|
|
|
|
|
(string-append name ".iso88591")
|
|
|
|
|
|
(string-append name ".ISO8859-1")))
|
|
|
|
|
|
'("ca_ES" "da_DK" "de_DE" "es_ES" "es_MX" "en_GB" "en_US"
|
|
|
|
|
|
"fr_FR" "pt_PT" "nl_NL" "sv_SE")))
|
|
|
|
|
|
|
|
|
|
|
|
(let loop ((locales %locales))
|
|
|
|
|
|
(if (null? locales)
|
|
|
|
|
|
(throw 'unresolved)
|
|
|
|
|
|
(catch 'unresolved
|
|
|
|
|
|
(lambda ()
|
|
|
|
|
|
(with-locale* (car locales) thunk))
|
|
|
|
|
|
(lambda (key . args)
|
|
|
|
|
|
(loop (cdr locales)))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Evaluate BODY... using an ISO-8859-1 locale or throw `unresolved' if none
|
|
|
|
|
|
;;; was found.
|
|
|
|
|
|
(define-syntax with-latin1-locale
|
|
|
|
|
|
(syntax-rules ()
|
|
|
|
|
|
((_ body ...)
|
|
|
|
|
|
(with-latin1-locale* (lambda () body ...)))))
|
|
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; REPORTERS
|
2001-08-01 09:57:01 +00:00
|
|
|
|
;;;;
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; The global list of reporters.
|
|
|
|
|
|
(define reporters '())
|
|
|
|
|
|
|
1999-05-31 21:27:20 +00:00
|
|
|
|
;;; The default reporter, to be used only if no others exist.
|
|
|
|
|
|
(define default-reporter #f)
|
|
|
|
|
|
|
1999-05-29 14:22:24 +00:00
|
|
|
|
;;; Add the procedure REPORTER to the current set of reporter functions.
|
|
|
|
|
|
;;; Signal an error if that reporter procedure object is already registered.
|
|
|
|
|
|
(define (register-reporter reporter)
|
|
|
|
|
|
(if (memq reporter reporters)
|
|
|
|
|
|
(error "register-reporter: reporter already registered: " reporter))
|
|
|
|
|
|
(set! reporters (cons reporter reporters)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Remove the procedure REPORTER from the current set of reporter
|
|
|
|
|
|
;;; functions. Signal an error if REPORTER is not currently registered.
|
|
|
|
|
|
(define (unregister-reporter reporter)
|
|
|
|
|
|
(if (memq reporter reporters)
|
|
|
|
|
|
(set! reporters (delq! reporter reporters))
|
|
|
|
|
|
(error "unregister-reporter: reporter not registered: " reporter)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Return true iff REPORTER is in the current set of reporter functions.
|
|
|
|
|
|
(define (reporter-registered? reporter)
|
|
|
|
|
|
(if (memq reporter reporters) #t #f))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Send RESULT to all currently registered reporter functions.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(define (report . args)
|
1999-05-31 21:27:20 +00:00
|
|
|
|
(if (pair? reporters)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(for-each (lambda (reporter) (apply reporter args))
|
1999-05-31 21:27:20 +00:00
|
|
|
|
reporters)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(apply default-reporter args)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;;; Some useful standard reporters:
|
|
|
|
|
|
;;;; Count reporters count the occurrence of each test result type.
|
|
|
|
|
|
;;;; Log reporters write all test results to a given log file.
|
|
|
|
|
|
;;;; Full reporters write all test results to the standard output.
|
|
|
|
|
|
;;;; User reporters write interesting test results to the standard output.
|
|
|
|
|
|
|
|
|
|
|
|
;;; The complete list of possible test results.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(define result-tags
|
2000-05-08 17:42:03 +00:00
|
|
|
|
'((pass "PASS" "passes: ")
|
|
|
|
|
|
(fail "FAIL" "failures: ")
|
|
|
|
|
|
(upass "UPASS" "unexpected passes: ")
|
|
|
|
|
|
(xfail "XFAIL" "expected failures: ")
|
|
|
|
|
|
(unresolved "UNRESOLVED" "unresolved test cases: ")
|
|
|
|
|
|
(untested "UNTESTED" "untested test cases: ")
|
|
|
|
|
|
(unsupported "UNSUPPORTED" "unsupported test cases: ")
|
|
|
|
|
|
(error "ERROR" "errors: ")))
|
|
|
|
|
|
|
|
|
|
|
|
;;; The list of important test results.
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(define important-result-tags
|
2000-05-08 17:42:03 +00:00
|
|
|
|
'(fail upass unresolved error))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Display a single test result in formatted form to the given port
|
|
|
|
|
|
(define (print-result port result name . args)
|
|
|
|
|
|
(let* ((tag (assq result result-tags))
|
|
|
|
|
|
(label (if tag (cadr tag) #f)))
|
|
|
|
|
|
(if label
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display label port)
|
|
|
|
|
|
(display ": " port)
|
|
|
|
|
|
(display (format-test-name name) port)
|
|
|
|
|
|
(if (pair? args)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(display " - arguments: " port)
|
|
|
|
|
|
(write args port)))
|
|
|
|
|
|
(newline port))
|
|
|
|
|
|
(error "(test-suite lib) FULL-REPORTER: unrecognized result: "
|
|
|
|
|
|
result))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; Return a list of the form (COUNTER RESULTS), where:
|
|
|
|
|
|
;;; - COUNTER is a reporter procedure, and
|
|
|
|
|
|
;;; - RESULTS is a procedure taking no arguments which returns the
|
|
|
|
|
|
;;; results seen so far by COUNTER. The return value is an alist
|
|
|
|
|
|
;;; mapping outcome symbols (`pass', `fail', etc.) onto counts.
|
|
|
|
|
|
(define (make-count-reporter)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(let ((counts (map (lambda (tag) (cons (car tag) 0)) result-tags)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(list
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(lambda (result name . args)
|
|
|
|
|
|
(let ((pair (assq result counts)))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(if pair
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(set-cdr! pair (+ 1 (cdr pair)))
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(error "count-reporter: unexpected test result: "
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(cons result (cons name args))))))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(lambda ()
|
|
|
|
|
|
(append counts '())))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Print a count reporter's results nicely. Pass this function the value
|
|
|
|
|
|
;;; returned by a count reporter's RESULTS procedure.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(define (print-counts results . port?)
|
2001-08-01 09:57:01 +00:00
|
|
|
|
(let ((port (if (pair? port?)
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(car port?)
|
|
|
|
|
|
(current-output-port))))
|
|
|
|
|
|
(newline port)
|
|
|
|
|
|
(display-line-port port "Totals for this test run:")
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (tag)
|
|
|
|
|
|
(let ((result (assq (car tag) results)))
|
|
|
|
|
|
(if result
|
|
|
|
|
|
(display-line-port port (caddr tag) (cdr result))
|
|
|
|
|
|
(display-line-port port
|
|
|
|
|
|
"Test suite bug: "
|
|
|
|
|
|
"no total available for `" (car tag) "'"))))
|
|
|
|
|
|
result-tags)
|
|
|
|
|
|
(newline port)))
|
1999-05-29 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
;;; Return a reporter procedure which prints all results to the file
|
|
|
|
|
|
;;; FILE, in human-readable form. FILE may be a filename, or a port.
|
|
|
|
|
|
(define (make-log-reporter file)
|
|
|
|
|
|
(let ((port (if (output-port? file) file
|
|
|
|
|
|
(open-output-file file))))
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(lambda args
|
|
|
|
|
|
(apply print-result port args)
|
1999-05-29 14:22:24 +00:00
|
|
|
|
(force-output port))))
|
|
|
|
|
|
|
1999-05-31 21:27:20 +00:00
|
|
|
|
;;; A reporter that reports all results to the user.
|
2000-05-08 17:42:03 +00:00
|
|
|
|
(define (full-reporter . args)
|
|
|
|
|
|
(apply print-result (current-output-port) args))
|
1999-05-31 21:27:20 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A reporter procedure which shows interesting results (failures,
|
2000-05-08 17:42:03 +00:00
|
|
|
|
;;; unexpected passes etc.) to the user.
|
|
|
|
|
|
(define (user-reporter result name . args)
|
|
|
|
|
|
(if (memq result important-result-tags)
|
|
|
|
|
|
(apply full-reporter result name args)))
|
1999-05-31 21:27:20 +00:00
|
|
|
|
|
|
|
|
|
|
(set! default-reporter full-reporter)
|