1 ;;; cus-test.el --- tests for custom types and load problems
3 ;; Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc.
5 ;; Author: Markus Rost <markus.rost@mathematik.uni-regensburg.de>
6 ;; Maintainer: Markus Rost <rost@math.ohio-state.edu>
7 ;; Created: 13 Sep 1998
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This file provides simple tests to detect custom options with
30 ;; incorrect customization types and load problems for custom and
31 ;; autoload dependencies.
33 ;; The basic tests can be run in batch mode. Invoke them with
35 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-opts
37 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-deps
39 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-libs
41 ;; in the emacs source directory.
43 ;; For interactive use: Load this file. Then
45 ;; M-x cus-test-apropos REGEXP RET
47 ;; checks the options matching REGEXP. In particular
49 ;; M-x cus-test-apropos RET
51 ;; checks all options. The detected options are stored in the
52 ;; variable `cus-test-errors'.
54 ;; Only those options are checked which have been already loaded.
55 ;; Therefore `cus-test-apropos' is more efficient after loading many
58 ;; M-x cus-test-load-custom-loads
60 ;; loads all (!) custom dependencies and
62 ;; M-x cus-test-load-libs
64 ;; loads all (!) libraries with autoloads.
66 ;; Options with a custom-get property, usually defined by a :get
67 ;; declaration, are stored in the variable
69 ;; `cus-test-vars-with-custom-get'
71 ;; Options with a state of 'changed ("changed outside the customize
72 ;; buffer") are stored in the variable
74 ;; `cus-test-vars-with-changed-state'
76 ;; These lists are prepared just in case one wants to investigate
77 ;; those options further.
79 ;; The command `cus-test-opts' tests many (all?) custom options.
81 ;; The command `cus-test-deps' is like `cus-test-load-custom-loads'
82 ;; but reports about load errors.
84 ;; The command `cus-test-libs' runs for all libraries with autoloads
85 ;; separate emacs processes of the form "emacs -batch -l LIB".
87 ;; Some results from October 2002:
89 ;; 4523 options tested
90 ;; The following variables might have problems:
91 ;; ps-mule-font-info-database-default
95 ;; 288 features required
97 ;; The following load problems appeared:
98 ;; (killing x-win (file-error Cannot open load file x-win))
99 ;; Symbol faces has loaddefs as custom dependency
100 ;; (reftex-index-support reftex-vars (void-function reftex-set-dirty))
101 ;; (eshell-script em-script (void-variable eshell-directory-name))
102 ;; (pcomplete em-cmpl (void-function eshell-under-windows-p))
103 ;; (eshell-ext esh-ext (void-function eshell-under-windows-p))
106 ;; 422 libraries had no load errors
107 ;; The following load problems appeared:
108 ;; (eudc-export error 255)
109 ;; (ada-xref error 255)
110 ;; (ada-stmt error 255)
114 ;;; Workarounds. For a smooth run and to avoid some side effects.
116 (defvar cus-test-after-load-libs-hook nil
117 "Used to switch off undesired side effects of loading libraries.")
119 (defvar cus-test-skip-list nil
120 "List of variables to disregard by `cus-test-apropos'.")
122 (defvar cus-test-noloads nil
123 "List of libraries not to load by `cus-test-load-libs'.")
125 ;; The file eudc-export.el loads libraries "bbdb" and "bbdb-com" which
126 ;; are not part of GNU Emacs: (locate-library "bbdb") => nil
127 ;; We avoid the resulting errors from loading eudc-export.el:
131 ;; This avoids a hang of `cus-test-apropos' in 21.2.
132 ;; (add-to-list 'cus-test-skip-list 'sh-alias-alist)
134 ;; Don't create a file `filesets-menu-cache-file'.
135 (setq filesets-menu-cache-file
"")
136 ;; Disable filesets hooks.
138 'cus-test-after-load-libs-hook
140 (remove-hook 'menu-bar-update-hook
'filesets-build-menu-maybe
)
141 (remove-hook 'kill-emacs-hook
'filesets-exit
)
142 (remove-hook 'kill-buffer-hook
'filesets-remove-from-ubl
)
143 (remove-hook 'first-change-hook
'filesets-reset-filename-on-change
)
146 ;; Loading dunnet in batch mode leads to a Dead end.
147 (let (noninteractive) (load "dunnet"))
148 (add-to-list 'cus-test-noloads
"dunnet")
151 (setq viper-mode nil
)
153 ;; Don't create a file `save-place-file'.
154 (eval-after-load "saveplace"
155 '(remove-hook 'kill-emacs-hook
'save-place-kill-emacs-hook
))
157 ;; Don't create a file `abbrev-file-name'.
158 (setq save-abbrevs nil
)
160 ;; Avoid compile logs from adviced functions.
161 (eval-after-load "bytecomp"
162 '(setq ad-default-compilation-action
'never
))
167 ;; We want to log all messages.
168 (setq message-log-max t
)
173 (defvar cus-test-errors nil
174 "List of problematic variables found by `cus-test-apropos'.")
176 (defvar cus-test-tested-variables nil
177 "List of options tested by last call of `cus-test-apropos'.")
179 (defvar cus-test-deps-errors nil
180 "List of require/load problems found by `cus-test-deps'.")
182 (defvar cus-test-deps-required nil
183 "List of dependencies required by `cus-test-deps'.
184 Only unloaded features will be require'd.")
186 (defvar cus-test-deps-loaded nil
187 "List of dependencies loaded by `cus-test-deps'.")
189 (defvar cus-test-libs-errors nil
190 "List of load problems found by `cus-test-load-libs' or `cus-test-libs'.")
192 (defvar cus-test-libs-loaded nil
193 "List of files loaded by `cus-test-load-libs' or `cus-test-libs'.")
195 ;; I haven't understood this :get stuff. The symbols with a
196 ;; custom-get property are stored here.
197 (defvar cus-test-vars-with-custom-get nil
198 "Set by `cus-test-apropos' to a list of options with :get property.")
200 (defvar cus-test-vars-with-changed-state nil
201 "Set by `cus-test-apropos' to a list of options with state 'changed.")
203 (defun cus-test-apropos (regexp)
204 "Check the options matching REGEXP.
205 The detected problematic options are stored in `cus-test-errors'."
206 (interactive "sVariable regexp: ")
207 (setq cus-test-errors nil
)
208 (setq cus-test-tested-variables nil
)
211 (push symbol cus-test-tested-variables
)
212 ;; Be verbose in case we hang.
213 (message "Cus Test running...%s %s"
214 (length cus-test-tested-variables
) symbol
)
215 (condition-case alpha
216 (let* ((type (custom-variable-type symbol
))
217 (conv (widget-convert type
))
218 (get (or (get symbol
'custom-get
) 'default-value
))
221 (when (default-boundp symbol
)
222 (push (funcall get symbol
) values
)
223 (push (eval (car (get symbol
'standard-value
))) values
))
225 (push (symbol-value symbol
) values
))
226 ;; That does not work.
227 ;; (push (widget-get conv :value) values)
230 (mapc (lambda (value)
231 (unless (widget-apply conv
:match value
)
232 (setq mismatch
'mismatch
)))
235 ;; Store symbols with a custom-get property.
236 (when (get symbol
'custom-get
)
237 (add-to-list 'cus-test-vars-with-custom-get
240 ;; Changed outside the customize buffer?
241 ;; This routine is not very much tested.
243 (or (get symbol
'customized-value
)
244 (get symbol
'saved-value
)
245 (get symbol
'standard-value
))))
248 (not (equal (eval (car c-value
)) (symbol-value symbol
)))
249 (add-to-list 'cus-test-vars-with-changed-state
253 (push symbol cus-test-errors
)))
256 (push symbol cus-test-errors
)
257 (message "Error for %s: %s" symbol alpha
))))
258 (cus-test-get-options regexp
))
259 (message "%s options tested"
260 (length cus-test-tested-variables
))
261 (cus-test-errors-display))
263 (defun cus-test-get-options (regexp)
264 "Return a list of custom options matching REGEXP."
270 ;; (user-variable-p symbol)
271 (get symbol
'standard-value
)
272 ;; (get symbol 'saved-value)
273 (get symbol
'custom-type
))
274 (string-match regexp
(symbol-name symbol
))
275 (not (member symbol cus-test-skip-list
))
276 (push symbol found
))))
279 (defun cus-test-errors-display ()
280 "Report about the errors found by cus-test."
281 (with-output-to-temp-buffer "*cus-test-errors*"
282 (set-buffer standard-output
)
283 (insert (format "Cus Test tested %s variables.\
284 See `cus-test-tested-variables'.\n\n"
285 (length cus-test-tested-variables
)))
286 (if (not cus-test-errors
)
287 (insert "No errors found by cus-test.")
288 (insert "The following variables seem to have problems:\n\n")
289 (dolist (E cus-test-errors
)
290 (insert (symbol-name E
) "\n")))))
292 (defun cus-test-load-custom-loads ()
293 "Call `custom-load-symbol' on all atoms."
295 (mapatoms 'custom-load-symbol
)
296 (run-hooks 'cus-test-after-load-libs-hook
))
298 (defun cus-test-load-libs ()
299 "Load the libraries with autoloads.
300 Don't load libraries in `cus-test-noloads'."
302 (setq cus-test-libs-errors nil
)
303 (setq cus-test-libs-loaded nil
)
306 (condition-case alpha
307 (unless (member file cus-test-noloads
)
309 (push file cus-test-libs-loaded
))
311 (push (cons file alpha
) cus-test-libs-errors
)
312 (message "Error for %s: %s" file alpha
))))
313 (cus-test-get-autoload-deps))
314 (message "%s libraries loaded successfully"
315 (length cus-test-libs-loaded
))
316 (if (not cus-test-libs-errors
)
317 (message "No load problems encountered")
318 (message "The following load problems appeared:")
319 (cus-test-message cus-test-libs-errors
))
320 (run-hooks 'cus-test-after-load-libs-hook
))
322 (defun cus-test-get-autoload-deps ()
323 "Return the list of libraries with autoloads."
325 (insert-file-contents (locate-library "loaddefs"))
326 ;; This is from `customize-option'.
329 (search-forward "\n;;; Generated autoloads from " nil t
)
330 (goto-char (match-end 0))
331 (setq file
(buffer-substring (point)
332 (progn (end-of-line) (point))))
333 (setq file
(file-name-nondirectory file
))
334 (string-match "\\.el\\'" file
)
335 (setq file
(substring file
0 (match-beginning 0)))
336 (setq deps
(nconc deps
(list file
))))
339 (defun cus-test-message (list)
340 "Print the members of LIST line by line."
341 (dolist (m list
) (message "%s" m
)))
344 ;;; The routines for batch mode:
346 (defun cus-test-opts ()
347 "Test custom options.
348 This function is suitable for batch mode. E.g., invoke
350 src/emacs -batch -l admin/cus-test.el -f cus-test-opts
352 in the emacs source directory."
354 (message "Running %s" 'cus-test-load-libs
)
356 (message "Running %s" 'cus-test-load-custom-loads
)
357 (cus-test-load-custom-loads)
358 (message "Running %s" 'cus-test-apropos
)
359 (cus-test-apropos "")
360 (if (not cus-test-errors
)
361 (message "No problems found")
362 (message "The following options might have problems:")
363 (cus-test-message cus-test-errors
)))
365 (defun cus-test-deps ()
366 "Run a verbose version of `custom-load-symbol' on all atoms.
367 This function is suitable for batch mode. E.g., invoke
369 src/emacs -batch -l admin/cus-test.el -f cus-test-deps
371 in the emacs source directory."
373 (setq cus-test-deps-errors nil
)
374 (setq cus-test-deps-required nil
)
375 (setq cus-test-deps-loaded nil
)
377 ;; This code is mainly from `custom-load-symbol'.
379 (unless custom-load-recursion
380 (let ((custom-load-recursion t
))
381 (dolist (load (get symbol
'custom-loads
))
384 ;; (condition-case nil (require load) (error nil))
385 (condition-case alpha
386 (unless (featurep load
)
388 (push (list symbol load
) cus-test-deps-required
))
390 (push (list symbol load alpha
) cus-test-deps-errors
)
391 (message "Require problem: %s %s %s" symbol load alpha
))))
392 ((equal load
"loaddefs")
394 (message "Symbol %s has loaddefs as custom dependency" symbol
)
395 cus-test-deps-errors
))
396 ;; This is subsumed by the test below, but it's much
398 ((assoc load load-history
))
400 ;; (assoc (locate-library load) load-history)
401 ;; but has been optimized not to load locate-library
403 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load
)
406 (dolist (loaded load-history
)
407 (and (stringp (car loaded
))
408 (string-match regexp
(car loaded
))
411 ;; Without this, we would load cus-edit recursively.
412 ;; We are still loading it when we call this,
413 ;; and it is not in load-history yet.
414 ((equal load
"cus-edit"))
415 ;; This would ignore load problems with files in
417 ;; ((locate-library (concat term-file-prefix load)))
419 ;; (condition-case nil (load load) (error nil))
420 (condition-case alpha
423 (push (list symbol load
) cus-test-deps-loaded
))
425 (push (list symbol load alpha
) cus-test-deps-errors
)
426 (message "Load Problem: %s %s %s" symbol load alpha
))))
428 (message "%s features required"
429 (length cus-test-deps-required
))
430 (message "%s files loaded"
431 (length cus-test-deps-loaded
))
432 (if (not cus-test-deps-errors
)
433 (message "No load problems encountered")
434 (message "The following load problems appeared:")
435 (cus-test-message cus-test-deps-errors
))
436 (run-hooks 'cus-test-after-load-libs-hook
))
438 (defun cus-test-libs ()
439 "Load the libraries with autoloads in separate processes.
440 This function is useful to detect load problems of libraries.
441 It is suitable for batch mode. E.g., invoke
443 src/emacs -batch -l admin/cus-test.el -f cus-test-libs
445 in the emacs source directory."
448 (setq cus-test-libs-errors nil
)
449 (setq cus-test-libs-loaded nil
)
450 (cd source-directory
)
451 (if (not (file-executable-p "src/emacs"))
452 (error "No Emacs executable in %ssrc" default-directory
))
455 (condition-case alpha
457 (setq fn
(locate-library file
))
459 (error "Library %s not found" file
))
460 (setq cmd
(concat "src/emacs -batch -l " fn
))
461 (setq status
(call-process shell-file-name nil nil nil
462 shell-command-switch cmd
))
466 (push file cus-test-libs-loaded
))
468 (push (cons file alpha
) cus-test-libs-errors
)
469 (message "Error for %s: %s" file alpha
))))
470 (cus-test-get-autoload-deps))
471 (message "Default Directory: %s" default-directory
)
472 (message "%s libraries had no load errors"
473 (length cus-test-libs-loaded
))
474 (if (not cus-test-libs-errors
)
475 (message "No load problems encountered")
476 (message "The following load problems appeared:")
477 (cus-test-message cus-test-libs-errors
))
478 (run-hooks 'cus-test-after-load-libs-hook
)))
482 ;;; cus-test.el ends here