lib.scm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. ;;;; test-suite/lib.scm --- generic support for testing
  2. ;;;; Copyright (C) 1999, 2000, 2001, 2004, 2006, 2007 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This program is free software; you can redistribute it and/or modify
  5. ;;;; it under the terms of the GNU General Public License as published by
  6. ;;;; the Free Software Foundation; either version 2, or (at your option)
  7. ;;;; any later version.
  8. ;;;;
  9. ;;;; This program is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;;;; GNU General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU General Public License
  15. ;;;; along with this software; see the file COPYING. If not, write to
  16. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. ;;;; Boston, MA 02110-1301 USA
  18. (define-module (test-suite lib)
  19. :use-module (ice-9 stack-catch)
  20. :use-module (ice-9 regex)
  21. :export (
  22. ;; Exceptions which are commonly being tested for.
  23. exception:bad-variable
  24. exception:missing-expression
  25. exception:out-of-range exception:unbound-var
  26. exception:used-before-defined
  27. exception:wrong-num-args exception:wrong-type-arg
  28. exception:numerical-overflow
  29. exception:struct-set!-denied
  30. exception:system-error
  31. exception:miscellaneous-error
  32. exception:string-contains-nul
  33. ;; Reporting passes and failures.
  34. run-test
  35. pass-if expect-fail
  36. pass-if-exception expect-fail-exception
  37. ;; Naming groups of tests in a regular fashion.
  38. with-test-prefix with-test-prefix* current-test-prefix
  39. format-test-name
  40. ;; Using the debugging evaluator.
  41. with-debugging-evaluator with-debugging-evaluator*
  42. ;; Reporting results in various ways.
  43. register-reporter unregister-reporter reporter-registered?
  44. make-count-reporter print-counts
  45. make-log-reporter
  46. full-reporter
  47. user-reporter))
  48. ;;;; If you're using Emacs's Scheme mode:
  49. ;;;; (put 'with-test-prefix 'scheme-indent-function 1)
  50. ;;;; CORE FUNCTIONS
  51. ;;;;
  52. ;;;; The function (run-test name expected-result thunk) is the heart of the
  53. ;;;; testing environment. The first parameter NAME is a unique name for the
  54. ;;;; test to be executed (for an explanation of this parameter see below under
  55. ;;;; TEST NAMES). The second parameter EXPECTED-RESULT is a boolean value
  56. ;;;; that indicates whether the corresponding test is expected to pass. If
  57. ;;;; EXPECTED-RESULT is #t the test is expected to pass, if EXPECTED-RESULT is
  58. ;;;; #f the test is expected to fail. Finally, THUNK is the function that
  59. ;;;; actually performs the test. For example:
  60. ;;;;
  61. ;;;; (run-test "integer addition" #t (lambda () (= 2 (+ 1 1))))
  62. ;;;;
  63. ;;;; To report success, THUNK should either return #t or throw 'pass. To
  64. ;;;; report failure, THUNK should either return #f or throw 'fail. If THUNK
  65. ;;;; returns a non boolean value or throws 'unresolved, this indicates that
  66. ;;;; the test did not perform as expected. For example the property that was
  67. ;;;; to be tested could not be tested because something else went wrong.
  68. ;;;; THUNK may also throw 'untested to indicate that the test was deliberately
  69. ;;;; not performed, for example because the test case is not complete yet.
  70. ;;;; Finally, if THUNK throws 'unsupported, this indicates that this test
  71. ;;;; requires some feature that is not available in the configured testing
  72. ;;;; environment. All other exceptions thrown by THUNK are considered as
  73. ;;;; errors.
  74. ;;;;
  75. ;;;;
  76. ;;;; Convenience macros for tests expected to pass or fail
  77. ;;;;
  78. ;;;; * (pass-if name body) is a short form for
  79. ;;;; (run-test name #t (lambda () body))
  80. ;;;; * (expect-fail name body) is a short form for
  81. ;;;; (run-test name #f (lambda () body))
  82. ;;;;
  83. ;;;; For example:
  84. ;;;;
  85. ;;;; (pass-if "integer addition" (= 2 (+ 1 1)))
  86. ;;;;
  87. ;;;;
  88. ;;;; Convenience macros to test for exceptions
  89. ;;;;
  90. ;;;; The following macros take exception parameters which are pairs
  91. ;;;; (type . message), where type is a symbol that denotes an exception type
  92. ;;;; like 'wrong-type-arg or 'out-of-range, and message is a string holding a
  93. ;;;; regular expression that describes the error message for the exception
  94. ;;;; like "Argument .* out of range".
  95. ;;;;
  96. ;;;; * (pass-if-exception name exception body) will pass if the execution of
  97. ;;;; body causes the given exception to be thrown. If no exception is
  98. ;;;; thrown, the test fails. If some other exception is thrown, is is an
  99. ;;;; error.
  100. ;;;; * (expect-fail-exception name exception body) will pass unexpectedly if
  101. ;;;; the execution of body causes the given exception to be thrown. If no
  102. ;;;; exception is thrown, the test fails expectedly. If some other
  103. ;;;; exception is thrown, it is an error.
  104. ;;;; TEST NAMES
  105. ;;;;
  106. ;;;; Every test in the test suite has a unique name, to help
  107. ;;;; developers find tests that are failing (or unexpectedly passing),
  108. ;;;; and to help gather statistics.
  109. ;;;;
  110. ;;;; A test name is a list of printable objects. For example:
  111. ;;;; ("ports.scm" "file" "read and write back list of strings")
  112. ;;;; ("ports.scm" "pipe" "read")
  113. ;;;;
  114. ;;;; Test names may contain arbitrary objects, but they always have
  115. ;;;; the following properties:
  116. ;;;; - Test names can be compared with EQUAL?.
  117. ;;;; - Test names can be reliably stored and retrieved with the standard WRITE
  118. ;;;; and READ procedures; doing so preserves their identity.
  119. ;;;;
  120. ;;;; For example:
  121. ;;;;
  122. ;;;; (pass-if "simple addition" (= 4 (+ 2 2)))
  123. ;;;;
  124. ;;;; In that case, the test name is the list ("simple addition").
  125. ;;;;
  126. ;;;; In the case of simple tests the expression that is tested would often
  127. ;;;; suffice as a test name by itself. Therefore, the convenience macros
  128. ;;;; pass-if and expect-fail provide a shorthand notation that allows to omit
  129. ;;;; a test name in such cases.
  130. ;;;;
  131. ;;;; * (pass-if expression) is a short form for
  132. ;;;; (run-test 'expression #t (lambda () expression))
  133. ;;;; * (expect-fail expression) is a short form for
  134. ;;;; (run-test 'expression #f (lambda () expression))
  135. ;;;;
  136. ;;;; For example:
  137. ;;;;
  138. ;;;; (pass-if (= 2 (+ 1 1)))
  139. ;;;;
  140. ;;;; The WITH-TEST-PREFIX syntax and WITH-TEST-PREFIX* procedure establish
  141. ;;;; a prefix for the names of all tests whose results are reported
  142. ;;;; within their dynamic scope. For example:
  143. ;;;;
  144. ;;;; (begin
  145. ;;;; (with-test-prefix "basic arithmetic"
  146. ;;;; (pass-if "addition" (= (+ 2 2) 4))
  147. ;;;; (pass-if "subtraction" (= (- 4 2) 2)))
  148. ;;;; (pass-if "multiplication" (= (* 2 2) 4)))
  149. ;;;;
  150. ;;;; In that example, the three test names are:
  151. ;;;; ("basic arithmetic" "addition"),
  152. ;;;; ("basic arithmetic" "subtraction"), and
  153. ;;;; ("multiplication").
  154. ;;;;
  155. ;;;; WITH-TEST-PREFIX can be nested. Each WITH-TEST-PREFIX postpends
  156. ;;;; a new element to the current prefix:
  157. ;;;;
  158. ;;;; (with-test-prefix "arithmetic"
  159. ;;;; (with-test-prefix "addition"
  160. ;;;; (pass-if "integer" (= (+ 2 2) 4))
  161. ;;;; (pass-if "complex" (= (+ 2+3i 4+5i) 6+8i)))
  162. ;;;; (with-test-prefix "subtraction"
  163. ;;;; (pass-if "integer" (= (- 2 2) 0))
  164. ;;;; (pass-if "complex" (= (- 2+3i 1+2i) 1+1i))))
  165. ;;;;
  166. ;;;; The four test names here are:
  167. ;;;; ("arithmetic" "addition" "integer")
  168. ;;;; ("arithmetic" "addition" "complex")
  169. ;;;; ("arithmetic" "subtraction" "integer")
  170. ;;;; ("arithmetic" "subtraction" "complex")
  171. ;;;;
  172. ;;;; To print a name for a human reader, we DISPLAY its elements,
  173. ;;;; separated by ": ". So, the last set of test names would be
  174. ;;;; reported as:
  175. ;;;;
  176. ;;;; arithmetic: addition: integer
  177. ;;;; arithmetic: addition: complex
  178. ;;;; arithmetic: subtraction: integer
  179. ;;;; arithmetic: subtraction: complex
  180. ;;;;
  181. ;;;; The Guile benchmarks use with-test-prefix to include the name of
  182. ;;;; the source file containing the test in the test name, to help
  183. ;;;; developers to find failing tests, and to provide each file with its
  184. ;;;; own namespace.
  185. ;;;; REPORTERS
  186. ;;;;
  187. ;;;; A reporter is a function which we apply to each test outcome.
  188. ;;;; Reporters can log results, print interesting results to the
  189. ;;;; standard output, collect statistics, etc.
  190. ;;;;
  191. ;;;; A reporter function takes two mandatory arguments, RESULT and TEST, and
  192. ;;;; possibly additional arguments depending on RESULT; its return value
  193. ;;;; is ignored. RESULT has one of the following forms:
  194. ;;;;
  195. ;;;; pass - The test named TEST passed.
  196. ;;;; Additional arguments are ignored.
  197. ;;;; upass - The test named TEST passed unexpectedly.
  198. ;;;; Additional arguments are ignored.
  199. ;;;; fail - The test named TEST failed.
  200. ;;;; Additional arguments are ignored.
  201. ;;;; xfail - The test named TEST failed, as expected.
  202. ;;;; Additional arguments are ignored.
  203. ;;;; unresolved - The test named TEST did not perform as expected, for
  204. ;;;; example the property that was to be tested could not be
  205. ;;;; tested because something else went wrong.
  206. ;;;; Additional arguments are ignored.
  207. ;;;; untested - The test named TEST was not actually performed, for
  208. ;;;; example because the test case is not complete yet.
  209. ;;;; Additional arguments are ignored.
  210. ;;;; unsupported - The test named TEST requires some feature that is not
  211. ;;;; available in the configured testing environment.
  212. ;;;; Additional arguments are ignored.
  213. ;;;; error - An error occurred while the test named TEST was
  214. ;;;; performed. Since this result means that the system caught
  215. ;;;; an exception it could not handle, the exception arguments
  216. ;;;; are passed as additional arguments.
  217. ;;;;
  218. ;;;; This library provides some standard reporters for logging results
  219. ;;;; to a file, reporting interesting results to the user, and
  220. ;;;; collecting totals.
  221. ;;;;
  222. ;;;; You can use the REGISTER-REPORTER function and friends to add
  223. ;;;; whatever reporting functions you like. If you don't register any
  224. ;;;; reporters, the library uses FULL-REPORTER, which simply writes
  225. ;;;; all results to the standard output.
  226. ;;;; MISCELLANEOUS
  227. ;;;;
  228. ;;; Define some exceptions which are commonly being tested for.
  229. (define exception:bad-variable
  230. (cons 'syntax-error "Bad variable"))
  231. (define exception:missing-expression
  232. (cons 'misc-error "^missing or extra expression"))
  233. (define exception:out-of-range
  234. (cons 'out-of-range "^.*out of range"))
  235. (define exception:unbound-var
  236. (cons 'unbound-variable "^Unbound variable"))
  237. (define exception:used-before-defined
  238. (cons 'unbound-variable "^Variable used before given a value"))
  239. (define exception:wrong-num-args
  240. (cons 'wrong-number-of-args "^Wrong number of arguments"))
  241. (define exception:wrong-type-arg
  242. (cons 'wrong-type-arg "^Wrong type"))
  243. (define exception:numerical-overflow
  244. (cons 'numerical-overflow "^Numerical overflow"))
  245. (define exception:struct-set!-denied
  246. (cons 'misc-error "^set! denied for field"))
  247. (define exception:system-error
  248. (cons 'system-error ".*"))
  249. (define exception:miscellaneous-error
  250. (cons 'misc-error "^.*"))
  251. ;; as per throw in scm_to_locale_stringn()
  252. (define exception:string-contains-nul
  253. (cons 'misc-error "^string contains #\\\\nul character"))
  254. ;;; Display all parameters to the default output port, followed by a newline.
  255. (define (display-line . objs)
  256. (for-each display objs)
  257. (newline))
  258. ;;; Display all parameters to the given output port, followed by a newline.
  259. (define (display-line-port port . objs)
  260. (for-each (lambda (obj) (display obj port)) objs)
  261. (newline port))
  262. ;;;; CORE FUNCTIONS
  263. ;;;;
  264. ;;; The central testing routine.
  265. ;;; The idea is taken from Greg, the GNUstep regression test environment.
  266. (define run-test #f)
  267. (let ((test-running #f))
  268. (define (local-run-test name expect-pass thunk)
  269. (if test-running
  270. (error "Nested calls to run-test are not permitted.")
  271. (let ((test-name (full-name name)))
  272. (set! test-running #t)
  273. (catch #t
  274. (lambda ()
  275. (let ((result (thunk)))
  276. (if (eq? result #t) (throw 'pass))
  277. (if (eq? result #f) (throw 'fail))
  278. (throw 'unresolved)))
  279. (lambda (key . args)
  280. (case key
  281. ((pass)
  282. (report (if expect-pass 'pass 'upass) test-name))
  283. ((fail)
  284. (report (if expect-pass 'fail 'xfail) test-name))
  285. ((unresolved untested unsupported)
  286. (report key test-name))
  287. ((quit)
  288. (report 'unresolved test-name)
  289. (quit))
  290. (else
  291. (report 'error test-name (cons key args))))))
  292. (set! test-running #f))))
  293. (set! run-test local-run-test))
  294. ;;; A short form for tests that are expected to pass, taken from Greg.
  295. (defmacro pass-if (name . rest)
  296. (if (and (null? rest) (pair? name))
  297. ;; presume this is a simple test, i.e. (pass-if (even? 2))
  298. ;; where the body should also be the name.
  299. `(run-test ',name #t (lambda () ,name))
  300. `(run-test ,name #t (lambda () ,@rest))))
  301. ;;; A short form for tests that are expected to fail, taken from Greg.
  302. (defmacro expect-fail (name . rest)
  303. (if (and (null? rest) (pair? name))
  304. ;; presume this is a simple test, i.e. (expect-fail (even? 2))
  305. ;; where the body should also be the name.
  306. `(run-test ',name #f (lambda () ,name))
  307. `(run-test ,name #f (lambda () ,@rest))))
  308. ;;; A helper function to implement the macros that test for exceptions.
  309. (define (run-test-exception name exception expect-pass thunk)
  310. (run-test name expect-pass
  311. (lambda ()
  312. (stack-catch (car exception)
  313. (lambda () (thunk) #f)
  314. (lambda (key proc message . rest)
  315. (cond
  316. ;; handle explicit key
  317. ((string-match (cdr exception) message)
  318. #t)
  319. ;; handle `(error ...)' which uses `misc-error' for key and doesn't
  320. ;; yet format the message and args (we have to do it here).
  321. ((and (eq? 'misc-error (car exception))
  322. (list? rest)
  323. (string-match (cdr exception)
  324. (apply simple-format #f message (car rest))))
  325. #t)
  326. ;; handle syntax errors which use `syntax-error' for key and don't
  327. ;; yet format the message and args (we have to do it here).
  328. ((and (eq? 'syntax-error (car exception))
  329. (list? rest)
  330. (string-match (cdr exception)
  331. (apply simple-format #f message (car rest))))
  332. #t)
  333. ;; unhandled; throw again
  334. (else
  335. (apply throw key proc message rest))))))))
  336. ;;; A short form for tests that expect a certain exception to be thrown.
  337. (defmacro pass-if-exception (name exception body . rest)
  338. `(,run-test-exception ,name ,exception #t (lambda () ,body ,@rest)))
  339. ;;; A short form for tests expected to fail to throw a certain exception.
  340. (defmacro expect-fail-exception (name exception body . rest)
  341. `(,run-test-exception ,name ,exception #f (lambda () ,body ,@rest)))
  342. ;;;; TEST NAMES
  343. ;;;;
  344. ;;;; Turn a test name into a nice human-readable string.
  345. (define (format-test-name name)
  346. (call-with-output-string
  347. (lambda (port)
  348. (let loop ((name name)
  349. (separator ""))
  350. (if (pair? name)
  351. (begin
  352. (display separator port)
  353. (display (car name) port)
  354. (loop (cdr name) ": ")))))))
  355. ;;;; For a given test-name, deliver the full name including all prefixes.
  356. (define (full-name name)
  357. (append (current-test-prefix) (list name)))
  358. ;;; A fluid containing the current test prefix, as a list.
  359. (define prefix-fluid (make-fluid))
  360. (fluid-set! prefix-fluid '())
  361. (define (current-test-prefix)
  362. (fluid-ref prefix-fluid))
  363. ;;; Postpend PREFIX to the current name prefix while evaluting THUNK.
  364. ;;; The name prefix is only changed within the dynamic scope of the
  365. ;;; call to with-test-prefix*. Return the value returned by THUNK.
  366. (define (with-test-prefix* prefix thunk)
  367. (with-fluids ((prefix-fluid
  368. (append (fluid-ref prefix-fluid) (list prefix))))
  369. (thunk)))
  370. ;;; (with-test-prefix PREFIX BODY ...)
  371. ;;; Postpend PREFIX to the current name prefix while evaluating BODY ...
  372. ;;; The name prefix is only changed within the dynamic scope of the
  373. ;;; with-test-prefix expression. Return the value returned by the last
  374. ;;; BODY expression.
  375. (defmacro with-test-prefix (prefix . body)
  376. `(with-test-prefix* ,prefix (lambda () ,@body)))
  377. ;;; Call THUNK using the debugging evaluator.
  378. (define (with-debugging-evaluator* thunk)
  379. (let ((dopts #f))
  380. (dynamic-wind
  381. (lambda ()
  382. (set! dopts (debug-options))
  383. (debug-enable 'debug))
  384. thunk
  385. (lambda ()
  386. (debug-options dopts)))))
  387. ;;; Evaluate BODY... using the debugging evaluator.
  388. (define-macro (with-debugging-evaluator . body)
  389. `(with-debugging-evaluator* (lambda () ,@body)))
  390. ;;;; REPORTERS
  391. ;;;;
  392. ;;; The global list of reporters.
  393. (define reporters '())
  394. ;;; The default reporter, to be used only if no others exist.
  395. (define default-reporter #f)
  396. ;;; Add the procedure REPORTER to the current set of reporter functions.
  397. ;;; Signal an error if that reporter procedure object is already registered.
  398. (define (register-reporter reporter)
  399. (if (memq reporter reporters)
  400. (error "register-reporter: reporter already registered: " reporter))
  401. (set! reporters (cons reporter reporters)))
  402. ;;; Remove the procedure REPORTER from the current set of reporter
  403. ;;; functions. Signal an error if REPORTER is not currently registered.
  404. (define (unregister-reporter reporter)
  405. (if (memq reporter reporters)
  406. (set! reporters (delq! reporter reporters))
  407. (error "unregister-reporter: reporter not registered: " reporter)))
  408. ;;; Return true iff REPORTER is in the current set of reporter functions.
  409. (define (reporter-registered? reporter)
  410. (if (memq reporter reporters) #t #f))
  411. ;;; Send RESULT to all currently registered reporter functions.
  412. (define (report . args)
  413. (if (pair? reporters)
  414. (for-each (lambda (reporter) (apply reporter args))
  415. reporters)
  416. (apply default-reporter args)))
  417. ;;;; Some useful standard reporters:
  418. ;;;; Count reporters count the occurrence of each test result type.
  419. ;;;; Log reporters write all test results to a given log file.
  420. ;;;; Full reporters write all test results to the standard output.
  421. ;;;; User reporters write interesting test results to the standard output.
  422. ;;; The complete list of possible test results.
  423. (define result-tags
  424. '((pass "PASS" "passes: ")
  425. (fail "FAIL" "failures: ")
  426. (upass "UPASS" "unexpected passes: ")
  427. (xfail "XFAIL" "expected failures: ")
  428. (unresolved "UNRESOLVED" "unresolved test cases: ")
  429. (untested "UNTESTED" "untested test cases: ")
  430. (unsupported "UNSUPPORTED" "unsupported test cases: ")
  431. (error "ERROR" "errors: ")))
  432. ;;; The list of important test results.
  433. (define important-result-tags
  434. '(fail upass unresolved error))
  435. ;;; Display a single test result in formatted form to the given port
  436. (define (print-result port result name . args)
  437. (let* ((tag (assq result result-tags))
  438. (label (if tag (cadr tag) #f)))
  439. (if label
  440. (begin
  441. (display label port)
  442. (display ": " port)
  443. (display (format-test-name name) port)
  444. (if (pair? args)
  445. (begin
  446. (display " - arguments: " port)
  447. (write args port)))
  448. (newline port))
  449. (error "(test-suite lib) FULL-REPORTER: unrecognized result: "
  450. result))))
  451. ;;; Return a list of the form (COUNTER RESULTS), where:
  452. ;;; - COUNTER is a reporter procedure, and
  453. ;;; - RESULTS is a procedure taking no arguments which returns the
  454. ;;; results seen so far by COUNTER. The return value is an alist
  455. ;;; mapping outcome symbols (`pass', `fail', etc.) onto counts.
  456. (define (make-count-reporter)
  457. (let ((counts (map (lambda (tag) (cons (car tag) 0)) result-tags)))
  458. (list
  459. (lambda (result name . args)
  460. (let ((pair (assq result counts)))
  461. (if pair
  462. (set-cdr! pair (+ 1 (cdr pair)))
  463. (error "count-reporter: unexpected test result: "
  464. (cons result (cons name args))))))
  465. (lambda ()
  466. (append counts '())))))
  467. ;;; Print a count reporter's results nicely. Pass this function the value
  468. ;;; returned by a count reporter's RESULTS procedure.
  469. (define (print-counts results . port?)
  470. (let ((port (if (pair? port?)
  471. (car port?)
  472. (current-output-port))))
  473. (newline port)
  474. (display-line-port port "Totals for this test run:")
  475. (for-each
  476. (lambda (tag)
  477. (let ((result (assq (car tag) results)))
  478. (if result
  479. (display-line-port port (caddr tag) (cdr result))
  480. (display-line-port port
  481. "Test suite bug: "
  482. "no total available for `" (car tag) "'"))))
  483. result-tags)
  484. (newline port)))
  485. ;;; Return a reporter procedure which prints all results to the file
  486. ;;; FILE, in human-readable form. FILE may be a filename, or a port.
  487. (define (make-log-reporter file)
  488. (let ((port (if (output-port? file) file
  489. (open-output-file file))))
  490. (lambda args
  491. (apply print-result port args)
  492. (force-output port))))
  493. ;;; A reporter that reports all results to the user.
  494. (define (full-reporter . args)
  495. (apply print-result (current-output-port) args))
  496. ;;; A reporter procedure which shows interesting results (failures,
  497. ;;; unexpected passes etc.) to the user.
  498. (define (user-reporter result name . args)
  499. (if (memq result important-result-tags)
  500. (apply full-reporter result name args)))
  501. (set! default-reporter full-reporter)