1 ;;; cus-test.el --- tests for custom types and load problems
3 ;; Copyright (C) 1998, 2000, 2002, 2006 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, 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 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-noloads
43 ;; in the emacs source directory.
45 ;; For interactive use: Load this file. Then
47 ;; M-x cus-test-apropos REGEXP RET
49 ;; checks the options matching REGEXP. In particular
51 ;; M-x cus-test-apropos RET
53 ;; checks all options. The detected options are stored in the
54 ;; variable `cus-test-errors'.
56 ;; Only those options are checked which have been already loaded.
57 ;; Therefore `cus-test-apropos' is more efficient after loading many
60 ;; M-x cus-test-load-custom-loads
62 ;; loads all (!) custom dependencies and
64 ;; M-x cus-test-load-libs
66 ;; loads all (!) libraries with autoloads.
68 ;; Options with a custom-get property, usually defined by a :get
69 ;; declaration, are stored in the variable
71 ;; `cus-test-vars-with-custom-get'
73 ;; Options with a state of 'changed ("changed outside the customize
74 ;; buffer") are stored in the variable
76 ;; `cus-test-vars-with-changed-state'
78 ;; These lists are prepared just in case one wants to investigate
79 ;; those options further.
81 ;; The command `cus-test-opts' tests many (all?) custom options.
83 ;; The command `cus-test-deps' is like `cus-test-load-custom-loads'
84 ;; but reports about load errors.
86 ;; The command `cus-test-libs' runs for all libraries with autoloads
87 ;; separate emacs processes of the form "emacs -batch -l LIB".
89 ;; The command `cus-test-noloads' returns a list of variables which
90 ;; are somewhere declared as custom options, but not loaded by
91 ;; `custom-load-symbol'.
93 ;; Some results from October 2002:
95 ;; 4523 options tested
96 ;; The following variables might have problems:
97 ;; ps-mule-font-info-database-default
101 ;; 288 features required
103 ;; The following load problems appeared:
104 ;; (killing x-win (file-error Cannot open load file x-win))
105 ;; Symbol faces has loaddefs as custom dependency
106 ;; (reftex-index-support reftex-vars (void-function reftex-set-dirty))
107 ;; (eshell-script em-script (void-variable eshell-directory-name))
108 ;; (pcomplete em-cmpl (void-function eshell-under-windows-p))
109 ;; (eshell-ext esh-ext (void-function eshell-under-windows-p))
112 ;; 422 libraries had no load errors
113 ;; The following load problems appeared:
114 ;; (eudc-export error 255)
115 ;; (ada-xref error 255)
116 ;; (ada-stmt error 255)
118 ;; The following options were not loaded by custom-load-symbol:
119 ;; edt-bottom-scroll-margin
120 ;; edt-keep-current-page-delimiter
121 ;; edt-top-scroll-margin
122 ;; edt-use-EDT-control-key-bindings
124 ;; grep-find-use-xargs
127 ;; outline-minor-mode-hook
133 ;;; Workarounds. For a smooth run and to avoid some side effects.
135 (defvar cus-test-after-load-libs-hook nil
136 "Used to switch off undesired side effects of loading libraries.")
138 (defvar cus-test-skip-list nil
139 "List of variables to disregard by `cus-test-apropos'.")
141 (defvar cus-test-libs-noloads nil
142 "List of libraries not to load by `cus-test-load-libs'.")
144 ;; The file eudc-export.el loads libraries "bbdb" and "bbdb-com" which
145 ;; are not part of GNU Emacs: (locate-library "bbdb") => nil
146 ;; We avoid the resulting errors from loading eudc-export.el:
150 ;; This avoids a hang of `cus-test-apropos' in 21.2.
151 ;; (add-to-list 'cus-test-skip-list 'sh-alias-alist)
153 ;; Loading dunnet in batch mode leads to a Dead end.
154 (let (noninteractive) (load "dunnet"))
155 (add-to-list 'cus-test-libs-noloads
"dunnet")
158 (setq viper-mode nil
)
160 ;; Don't create a file `save-place-file'.
161 (eval-after-load "saveplace"
162 '(remove-hook 'kill-emacs-hook
'save-place-kill-emacs-hook
))
164 ;; Don't create a file `abbrev-file-name'.
165 (setq save-abbrevs nil
)
167 ;; Avoid compile logs from adviced functions.
168 (eval-after-load "bytecomp"
169 '(setq ad-default-compilation-action
'never
))
174 ;; We want to log all messages.
175 (setq message-log-max t
)
180 (defvar cus-test-errors nil
181 "List of problematic variables found by `cus-test-apropos'.")
183 (defvar cus-test-tested-variables nil
184 "List of options tested by last call of `cus-test-apropos'.")
186 ;; I haven't understood this :get stuff. The symbols with a
187 ;; custom-get property are stored here.
188 (defvar cus-test-vars-with-custom-get nil
189 "Set by `cus-test-apropos' to a list of options with :get property.")
191 (defvar cus-test-vars-with-changed-state nil
192 "Set by `cus-test-apropos' to a list of options with state 'changed.")
194 (defvar cus-test-deps-errors nil
195 "List of require/load problems found by `cus-test-deps'.")
197 (defvar cus-test-deps-required nil
198 "List of dependencies required by `cus-test-deps'.
199 Only unloaded features will be require'd.")
201 (defvar cus-test-deps-loaded nil
202 "List of dependencies loaded by `cus-test-deps'.")
204 (defvar cus-test-libs-errors nil
205 "List of load problems found by `cus-test-load-libs' or `cus-test-libs'.")
207 (defvar cus-test-libs-loaded nil
208 "List of files loaded by `cus-test-load-libs' or `cus-test-libs'.")
210 (defvar cus-test-vars-not-cus-loaded nil
211 "A list of options not loaded by `custom-load-symbol'.
212 Set by `cus-test-noloads'.")
214 ;; (defvar cus-test-vars-cus-loaded nil
215 ;; "A list of options loaded by `custom-load-symbol'.")
217 (defun cus-test-apropos (regexp)
218 "Check the options matching REGEXP.
219 The detected problematic options are stored in `cus-test-errors'."
220 (interactive "sVariable regexp: ")
221 (setq cus-test-errors nil
)
222 (setq cus-test-tested-variables nil
)
225 (push symbol cus-test-tested-variables
)
226 ;; Be verbose in case we hang.
227 (message "Cus Test running...%s %s"
228 (length cus-test-tested-variables
) symbol
)
229 (condition-case alpha
230 (let* ((type (custom-variable-type symbol
))
231 (conv (widget-convert type
))
232 (get (or (get symbol
'custom-get
) 'default-value
))
235 (when (default-boundp symbol
)
236 (push (funcall get symbol
) values
)
237 (push (eval (car (get symbol
'standard-value
))) values
))
239 (push (symbol-value symbol
) values
))
240 ;; That does not work.
241 ;; (push (widget-get conv :value) values)
244 (mapc (lambda (value)
245 (unless (widget-apply conv
:match value
)
246 (setq mismatch
'mismatch
)))
249 ;; Store symbols with a custom-get property.
250 (when (get symbol
'custom-get
)
251 (add-to-list 'cus-test-vars-with-custom-get symbol
))
253 ;; Changed outside the customize buffer?
254 ;; This routine is not very much tested.
256 (or (get symbol
'customized-value
)
257 (get symbol
'saved-value
)
258 (get symbol
'standard-value
))))
261 (not (equal (eval (car c-value
)) (symbol-value symbol
)))
262 (add-to-list 'cus-test-vars-with-changed-state symbol
)))
265 (push symbol cus-test-errors
)))
268 (push symbol cus-test-errors
)
269 (message "Error for %s: %s" symbol alpha
))))
270 (cus-test-get-options regexp
))
271 (message "%s options tested"
272 (length cus-test-tested-variables
))
273 (cus-test-errors-display))
275 (defun cus-test-get-options (regexp)
276 "Return a list of custom options matching REGEXP."
282 ;; (user-variable-p symbol)
283 (get symbol
'standard-value
)
284 ;; (get symbol 'saved-value)
285 (get symbol
'custom-type
))
286 (string-match regexp
(symbol-name symbol
))
287 (not (member symbol cus-test-skip-list
))
288 (push symbol found
))))
291 (defun cus-test-errors-display ()
292 "Report about the errors found by cus-test."
293 (with-output-to-temp-buffer "*cus-test-errors*"
294 (set-buffer standard-output
)
295 (insert (format "Cus Test tested %s variables.\
296 See `cus-test-tested-variables'.\n\n"
297 (length cus-test-tested-variables
)))
298 (if (not cus-test-errors
)
299 (insert "No errors found by cus-test.")
300 (insert "The following variables seem to have problems:\n\n")
301 (dolist (e cus-test-errors
)
302 (insert (symbol-name e
) "\n")))))
304 (defun cus-test-load-custom-loads ()
305 "Call `custom-load-symbol' on all atoms."
307 (mapatoms 'custom-load-symbol
)
308 (run-hooks 'cus-test-after-load-libs-hook
))
310 (defun cus-test-load-libs ()
311 "Load the libraries with autoloads.
312 Don't load libraries in `cus-test-libs-noloads'."
314 (setq cus-test-libs-errors nil
)
315 (setq cus-test-libs-loaded nil
)
318 (condition-case alpha
319 (unless (member file cus-test-libs-noloads
)
321 (push file cus-test-libs-loaded
))
323 (push (cons file alpha
) cus-test-libs-errors
)
324 (message "Error for %s: %s" file alpha
))))
325 (cus-test-get-autoload-deps))
326 (message "%s libraries loaded successfully"
327 (length cus-test-libs-loaded
))
328 (if (not cus-test-libs-errors
)
329 (message "No load problems encountered")
330 (message "The following load problems appeared:")
331 (cus-test-message cus-test-libs-errors
))
332 (run-hooks 'cus-test-after-load-libs-hook
))
334 (defun cus-test-get-autoload-deps ()
335 "Return the list of libraries with autoloads."
337 (insert-file-contents (locate-library "loaddefs"))
338 ;; This is from `customize-option'.
341 (search-forward "\n;;; Generated autoloads from " nil t
)
342 (goto-char (match-end 0))
343 (setq file
(buffer-substring (point)
344 (progn (end-of-line) (point))))
345 (setq file
(file-name-nondirectory file
))
346 (string-match "\\.el\\'" file
)
347 (setq file
(substring file
0 (match-beginning 0)))
348 (setq deps
(nconc deps
(list file
))))
351 (defun cus-test-message (list)
352 "Print the members of LIST line by line."
353 (dolist (m list
) (message "%s" m
)))
356 ;;; The routines for batch mode:
358 (defun cus-test-opts ()
359 "Test custom options.
360 This function is suitable for batch mode. E.g., invoke
362 src/emacs -batch -l admin/cus-test.el -f cus-test-opts
364 in the Emacs source directory."
366 (message "Running %s" 'cus-test-load-libs
)
368 (message "Running %s" 'cus-test-load-custom-loads
)
369 (cus-test-load-custom-loads)
370 (message "Running %s" 'cus-test-apropos
)
371 (cus-test-apropos "")
372 (if (not cus-test-errors
)
373 (message "No problems found")
374 (message "The following options might have problems:")
375 (cus-test-message cus-test-errors
)))
377 (defun cus-test-deps ()
378 "Run a verbose version of `custom-load-symbol' on all atoms.
379 This function is suitable for batch mode. E.g., invoke
381 src/emacs -batch -l admin/cus-test.el -f cus-test-deps
383 in the Emacs source directory."
385 (setq cus-test-deps-errors nil
)
386 (setq cus-test-deps-required nil
)
387 (setq cus-test-deps-loaded nil
)
389 ;; This code is mainly from `custom-load-symbol'.
391 (let ((custom-load-recursion t
))
392 (dolist (load (get symbol
'custom-loads
))
395 ;; (condition-case nil (require load) (error nil))
396 (condition-case alpha
397 (unless (featurep load
)
399 (push (list symbol load
) cus-test-deps-required
))
401 (push (list symbol load alpha
) cus-test-deps-errors
)
402 (message "Require problem: %s %s %s" symbol load alpha
))))
403 ((equal load
"loaddefs")
405 (message "Symbol %s has loaddefs as custom dependency" symbol
)
406 cus-test-deps-errors
))
407 ;; This is subsumed by the test below, but it's much
409 ((assoc load load-history
))
411 ;; (assoc (locate-library load) load-history)
412 ;; but has been optimized not to load locate-library
414 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load
)
417 (dolist (loaded load-history
)
418 (and (stringp (car loaded
))
419 (string-match regexp
(car loaded
))
422 ;; Without this, we would load cus-edit recursively.
423 ;; We are still loading it when we call this,
424 ;; and it is not in load-history yet.
425 ((equal load
"cus-edit"))
426 ;; This would ignore load problems with files in
428 ;; ((locate-library (concat term-file-prefix load)))
430 ;; (condition-case nil (load load) (error nil))
431 (condition-case alpha
434 (push (list symbol load
) cus-test-deps-loaded
))
436 (push (list symbol load alpha
) cus-test-deps-errors
)
437 (message "Load Problem: %s %s %s" symbol load alpha
))))
439 (message "%s features required"
440 (length cus-test-deps-required
))
441 (message "%s files loaded"
442 (length cus-test-deps-loaded
))
443 (if (not cus-test-deps-errors
)
444 (message "No load problems encountered")
445 (message "The following load problems appeared:")
446 (cus-test-message cus-test-deps-errors
))
447 (run-hooks 'cus-test-after-load-libs-hook
))
449 (defun cus-test-libs ()
450 "Load the libraries with autoloads in separate processes.
451 This function is useful to detect load problems of libraries.
452 It is suitable for batch mode. E.g., invoke
454 src/emacs -batch -l admin/cus-test.el -f cus-test-libs
456 in the Emacs source directory."
459 (setq cus-test-libs-errors nil
)
460 (setq cus-test-libs-loaded nil
)
461 (cd source-directory
)
462 (if (not (file-executable-p "src/emacs"))
463 (error "No Emacs executable in %ssrc" default-directory
))
466 (condition-case alpha
468 (setq fn
(locate-library file
))
470 (error "Library %s not found" file
))
471 (setq cmd
(concat "src/emacs -batch -l " fn
))
472 (setq status
(call-process shell-file-name nil nil nil
473 shell-command-switch cmd
))
477 (push file cus-test-libs-loaded
))
479 (push (cons file alpha
) cus-test-libs-errors
)
480 (message "Error for %s: %s" file alpha
))))
481 (cus-test-get-autoload-deps))
482 (message "Default Directory: %s" default-directory
)
483 (message "%s libraries had no load errors"
484 (length cus-test-libs-loaded
))
485 (if (not cus-test-libs-errors
)
486 (message "No load problems encountered")
487 (message "The following load problems appeared:")
488 (cus-test-message cus-test-libs-errors
))
489 (run-hooks 'cus-test-after-load-libs-hook
)))
491 (defun cus-test-noloads ()
492 "Find custom options not loaded by `custom-load-symbol'.
493 Calling this function after `cus-test-load-libs' is not meaningful.
494 It is suitable for batch mode. E.g., invoke
496 src/emacs -batch -l admin/cus-test.el -f cus-test-noloads
498 in the Emacs source directory."
502 (message "Running %s" 'cus-test-load-custom-loads
)
503 (cus-test-load-custom-loads)
505 (cus-test-get-options ""))
507 (message "Running %s" 'cus-test-load-libs
)
509 (setq cus-test-vars-not-cus-loaded
510 (cus-test-get-options ""))
512 (dolist (o cus-loaded
)
513 (setq cus-test-vars-not-cus-loaded
514 (delete o cus-test-vars-not-cus-loaded
)))
516 (if (not cus-test-vars-not-cus-loaded
)
517 (message "No options not loaded by custom-load-symbol found")
518 (message "The following options were not loaded by custom-load-symbol:")
520 (sort cus-test-vars-not-cus-loaded
'string
<)))))
522 ;; And last but not least a quiz:
524 ;; Evaluation of the form (customize-option 'debug-on-error) yields a
525 ;; *Customize* buffer with a mismatch mess. Why?
529 ;;; arch-tag: a4991a31-548d-48fb-8ba1-1ebbe68eb2e7
530 ;;; cus-test.el ends here