guile-test 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!../libguile/guile \
  2. -e main -s
  3. !#
  4. ;;;; guile-test --- run the Guile test suite
  5. ;;;; Jim Blandy <jimb@red-bean.com> --- May 1999
  6. ;;;;
  7. ;;;; Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
  8. ;;;;
  9. ;;;; This program is free software; you can redistribute it and/or modify
  10. ;;;; it under the terms of the GNU General Public License as published by
  11. ;;;; the Free Software Foundation; either version 2, or (at your option)
  12. ;;;; any later version.
  13. ;;;;
  14. ;;;; This program is distributed in the hope that it will be useful,
  15. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;;; GNU General Public License for more details.
  18. ;;;;
  19. ;;;; You should have received a copy of the GNU General Public License
  20. ;;;; along with this software; see the file COPYING. If not, write to
  21. ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  22. ;;;; Boston, MA 02111-1307 USA
  23. ;;;; Usage: [guile -e main -s] guile-test [OPTIONS] [TEST ...]
  24. ;;;;
  25. ;;;; Run tests from the Guile test suite. Report failures and
  26. ;;;; unexpected passes to the standard output, along with a summary of
  27. ;;;; all the results. Record each reported test outcome in the log
  28. ;;;; file, `guile.log'. The exit status is #f if any of the tests
  29. ;;;; fail or pass unexpectedly.
  30. ;;;;
  31. ;;;; Normally, guile-test scans the test directory, and executes all
  32. ;;;; files whose names end in `.test'. (It assumes they contain
  33. ;;;; Scheme code.) However, you can have it execute specific tests by
  34. ;;;; listing their filenames on the command line.
  35. ;;;;
  36. ;;;; The option `--test-suite' can be given to specify the test
  37. ;;;; directory. If no such option is given, the test directory is
  38. ;;;; taken from the environment variable TEST_SUITE_DIR (if defined),
  39. ;;;; otherwise a default directory that is hardcoded in this file is
  40. ;;;; used (see "Installation" below).
  41. ;;;;
  42. ;;;; If present, the `--log-file LOG' option tells `guile-test' to put
  43. ;;;; the log output in a file named LOG.
  44. ;;;;
  45. ;;;; If present, the `--debug' option will enable a debugging mode.
  46. ;;;;
  47. ;;;; If present, the `--flag-unresolved' option will cause guile-test
  48. ;;;; to exit with failure status if any tests are UNRESOLVED.
  49. ;;;;
  50. ;;;;
  51. ;;;; Installation:
  52. ;;;;
  53. ;;;; If you change the #! line at the top of this script to point at
  54. ;;;; the Guile interpreter you want to test, you can call this script
  55. ;;;; as an executable instead of having to pass it as a parameter to
  56. ;;;; guile via "guile -e main -s guile-test". Further, you can edit
  57. ;;;; the definition of default-test-suite to point to the parent
  58. ;;;; directory of the `tests' tree, which makes it unnecessary to set
  59. ;;;; the environment variable `TEST_SUITE_DIR'.
  60. ;;;;
  61. ;;;;
  62. ;;;; Shortcomings:
  63. ;;;;
  64. ;;;; At the moment, due to a simple-minded implementation, test files
  65. ;;;; must live in the test directory, and you must specify their names
  66. ;;;; relative to the top of the test directory. If you want to send
  67. ;;;; me a patch that fixes this, but still leaves sane test names in
  68. ;;;; the log file, that would be great. At the moment, all the tests
  69. ;;;; I care about are in the test directory, though.
  70. ;;;;
  71. ;;;; It would be nice if you could specify the Guile interpreter you
  72. ;;;; want to test on the command line. As it stands, if you want to
  73. ;;;; change which Guile interpreter you're testing, you need to edit
  74. ;;;; the #! line at the top of this file, which is stupid.
  75. ;;; User configurable settings:
  76. (define default-test-suite
  77. (string-append (getenv "HOME") "/bogus-path/test-suite"))
  78. (use-modules (test-suite lib)
  79. (ice-9 getopt-long)
  80. ;;(ice-9 and-let-star)
  81. ;;(ice-9 rdelim)
  82. )
  83. ;;; Variables that will receive their actual values later.
  84. (define test-suite default-test-suite)
  85. (define tmp-dir #f)
  86. ;;; General utilities, that probably should be in a library somewhere.
  87. ;;; Enable debugging
  88. (define (enable-debug-mode)
  89. (write-line %load-path)
  90. (set! %load-verbosely #t)
  91. (debug-enable 'backtrace 'debug))
  92. ;;; Traverse the directory tree at ROOT, applying F to the name of
  93. ;;; each file in the tree, including ROOT itself. For a subdirectory
  94. ;;; SUB, if (F SUB) is true, we recurse into SUB. Do not follow
  95. ;;; symlinks.
  96. (define (for-each-file f root)
  97. ;; A "hard directory" is a path that denotes a directory and is not a
  98. ;; symlink.
  99. (define (file-is-hard-directory? filename)
  100. (eq? (stat:type (lstat filename)) 'directory))
  101. (let visit ((root root))
  102. (let ((should-recur (f root)))
  103. (if (and should-recur (file-is-hard-directory? root))
  104. (let ((dir (opendir root)))
  105. (let loop ()
  106. (let ((entry (readdir dir)))
  107. (cond
  108. ((eof-object? entry) #f)
  109. ((or (string=? entry ".")
  110. (string=? entry "..")
  111. (string=? entry "CVS")
  112. (string=? entry "RCS"))
  113. (loop))
  114. (else
  115. (visit (string-append root "/" entry))
  116. (loop))))))))))
  117. ;;; The test driver.
  118. ;;; Localizing test files and temporary data files.
  119. (define (data-file-name filename)
  120. (in-vicinity tmp-dir filename))
  121. (define (test-file-name test)
  122. (in-vicinity test-suite test))
  123. ;;; Return a list of all the test files in the test tree.
  124. (define (enumerate-tests test-dir)
  125. (let ((root-len (+ 1 (string-length test-dir)))
  126. (tests '()))
  127. (for-each-file (lambda (file)
  128. (if (has-suffix? file ".test")
  129. (let ((short-name
  130. (substring file root-len)))
  131. (set! tests (cons short-name tests))))
  132. #t)
  133. test-dir)
  134. ;; for-each-file presents the files in whatever order it finds
  135. ;; them in the directory. We sort them here, so they'll always
  136. ;; appear in the same order. This makes it easier to compare test
  137. ;; log files mechanically.
  138. (sort tests string<?)))
  139. (define (main args)
  140. (let ((options (getopt-long args
  141. `((test-suite
  142. (single-char #\t)
  143. (value #t))
  144. (flag-unresolved
  145. (single-char #\u))
  146. (log-file
  147. (single-char #\l)
  148. (value #t))
  149. (debug
  150. (single-char #\d))))))
  151. (define (opt tag default)
  152. (let ((pair (assq tag options)))
  153. (if pair (cdr pair) default)))
  154. (if (opt 'debug #f)
  155. (enable-debug-mode))
  156. (set! test-suite
  157. (or (opt 'test-suite #f)
  158. (getenv "TEST_SUITE_DIR")
  159. default-test-suite))
  160. ;; directory where temporary files are created.
  161. ;; when run from "make check", this must be under the build-dir,
  162. ;; not the src-dir.
  163. (set! tmp-dir (getcwd))
  164. (let* ((tests
  165. (let ((foo (opt '() '())))
  166. (if (null? foo)
  167. (enumerate-tests test-suite)
  168. foo)))
  169. (log-file
  170. (opt 'log-file "guile.log")))
  171. ;; Open the log file.
  172. (let ((log-port (open-output-file log-file)))
  173. ;; Register some reporters.
  174. (let ((global-pass #t)
  175. (counter (make-count-reporter)))
  176. (register-reporter (car counter))
  177. (register-reporter (make-log-reporter log-port))
  178. (register-reporter user-reporter)
  179. (register-reporter (lambda results
  180. (case (car results)
  181. ((unresolved)
  182. (and (opt 'flag-unresolved #f)
  183. (set! global-pass #f)))
  184. ((fail upass error)
  185. (set! global-pass #f)))))
  186. ;; Run the tests.
  187. (for-each (lambda (test)
  188. (with-test-prefix test
  189. (load (test-file-name test))))
  190. tests)
  191. ;; Display the final counts, both to the user and in the log
  192. ;; file.
  193. (let ((counts ((cadr counter))))
  194. (print-counts counts)
  195. (print-counts counts log-port))
  196. (close-port log-port)
  197. (quit global-pass))))))
  198. ;;; Local Variables:
  199. ;;; mode: scheme
  200. ;;; End: