1 ;;; cus-test.el --- tests for custom types and load problems
3 ;; Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Author: Markus Rost <markus.rost@mathematik.uni-regensburg.de>
7 ;; Maintainer: Markus Rost <rost@math.ohio-state.edu>
8 ;; Created: 13 Sep 1998
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This file provides simple tests to detect custom options with
29 ;; incorrect customization types and load problems for custom and
30 ;; autoload dependencies.
32 ;; The basic tests can be run in batch mode. Invoke them with
34 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-opts
36 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-deps
38 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-libs
40 ;; src/emacs -batch -l admin/cus-test.el -f cus-test-noloads
42 ;; in the emacs source directory.
44 ;; For interactive use: Load this file. Then
46 ;; M-x cus-test-apropos REGEXP RET
48 ;; checks the options matching REGEXP. In particular
50 ;; M-x cus-test-apropos RET
52 ;; checks all options. The detected options are stored in the
53 ;; variable `cus-test-errors'.
55 ;; Only those options are checked which have been already loaded.
56 ;; Therefore `cus-test-apropos' is more efficient after loading many
59 ;; M-x cus-test-load-custom-loads
61 ;; loads all (!) custom dependencies and
63 ;; M-x cus-test-load-libs
65 ;; loads all (!) libraries with autoloads.
67 ;; Options with a custom-get property, usually defined by a :get
68 ;; declaration, are stored in the variable
70 ;; `cus-test-vars-with-custom-get'
72 ;; Options with a state of 'changed ("changed outside the customize
73 ;; buffer") are stored in the variable
75 ;; `cus-test-vars-with-changed-state'
77 ;; These lists are prepared just in case one wants to investigate
78 ;; those options further.
80 ;; The command `cus-test-opts' tests many (all?) custom options.
82 ;; The command `cus-test-deps' is like `cus-test-load-custom-loads'
83 ;; but reports about load errors.
85 ;; The command `cus-test-libs' runs for all libraries with autoloads
86 ;; separate emacs processes of the form "emacs -batch -l LIB".
88 ;; The command `cus-test-noloads' returns a list of variables which
89 ;; are somewhere declared as custom options, but not loaded by
90 ;; `custom-load-symbol'.
92 ;; Some results from October 2002:
94 ;; 4523 options tested
95 ;; The following variables might have problems:
96 ;; ps-mule-font-info-database-default
100 ;; 288 features required
102 ;; The following load problems appeared:
103 ;; (killing x-win (file-error Cannot open load file x-win))
104 ;; Symbol faces has loaddefs as custom dependency
105 ;; (reftex-index-support reftex-vars (void-function reftex-set-dirty))
106 ;; (eshell-script em-script (void-variable eshell-directory-name))
107 ;; (pcomplete em-cmpl (void-function eshell-under-windows-p))
108 ;; (eshell-ext esh-ext (void-function eshell-under-windows-p))
111 ;; 422 libraries had no load errors
112 ;; The following load problems appeared:
113 ;; (eudc-export error 255)
114 ;; (ada-xref error 255)
115 ;; (ada-stmt error 255)
117 ;; The following options were not loaded by custom-load-symbol:
118 ;; edt-bottom-scroll-margin
119 ;; edt-keep-current-page-delimiter
120 ;; edt-top-scroll-margin
121 ;; edt-use-EDT-control-key-bindings
123 ;; grep-find-use-xargs
126 ;; outline-minor-mode-hook
132 ;;; Workarounds. For a smooth run and to avoid some side effects.
134 (defvar cus-test-after-load-libs-hook nil
135 "Used to switch off undesired side effects of loading libraries.")
137 (defvar cus-test-skip-list nil
138 "List of variables to disregard by `cus-test-apropos'.")
140 (defvar cus-test-libs-noloads nil
141 "List of libraries not to load by `cus-test-load-libs'.")
143 ;; The file eudc-export.el loads libraries "bbdb" and "bbdb-com" which
144 ;; are not part of GNU Emacs: (locate-library "bbdb") => nil
145 ;; We avoid the resulting errors from loading eudc-export.el:
149 ;; This avoids a hang of `cus-test-apropos' in 21.2.
150 ;; (add-to-list 'cus-test-skip-list 'sh-alias-alist)
152 ;; Loading dunnet in batch mode leads to a Dead end.
153 (let (noninteractive) (load "dunnet"))
154 (add-to-list 'cus-test-libs-noloads
"dunnet")
157 (setq viper-mode nil
)
159 ;; Don't create a file `save-place-file'.
160 (eval-after-load "saveplace"
161 '(remove-hook 'kill-emacs-hook
'save-place-kill-emacs-hook
))
163 ;; Don't create a file `abbrev-file-name'.
164 (setq save-abbrevs nil
)
166 ;; Avoid compile logs from adviced functions.
167 (eval-after-load "bytecomp"
168 '(setq ad-default-compilation-action
'never
))
173 ;; We want to log all messages.
174 (setq message-log-max t
)
179 (defvar cus-test-errors nil
180 "List of problematic variables found by `cus-test-apropos'.")
182 (defvar cus-test-tested-variables nil
183 "List of options tested by last call of `cus-test-apropos'.")
185 ;; I haven't understood this :get stuff. The symbols with a
186 ;; custom-get property are stored here.
187 (defvar cus-test-vars-with-custom-get nil
188 "Set by `cus-test-apropos' to a list of options with :get property.")
190 (defvar cus-test-vars-with-changed-state nil
191 "Set by `cus-test-apropos' to a list of options with state 'changed.")
193 (defvar cus-test-deps-errors nil
194 "List of require/load problems found by `cus-test-deps'.")
196 (defvar cus-test-deps-required nil
197 "List of dependencies required by `cus-test-deps'.
198 Only unloaded features will be require'd.")
200 (defvar cus-test-deps-loaded nil
201 "List of dependencies loaded by `cus-test-deps'.")
203 (defvar cus-test-libs-errors nil
204 "List of load problems found by `cus-test-load-libs' or `cus-test-libs'.")
206 (defvar cus-test-libs-loaded nil
207 "List of files loaded by `cus-test-load-libs' or `cus-test-libs'.")
209 (defvar cus-test-vars-not-cus-loaded nil
210 "A list of options not loaded by `custom-load-symbol'.
211 Set by `cus-test-noloads'.")
213 ;; (defvar cus-test-vars-cus-loaded nil
214 ;; "A list of options loaded by `custom-load-symbol'.")
216 (defun cus-test-apropos (regexp)
217 "Check the options matching REGEXP.
218 The detected problematic options are stored in `cus-test-errors'."
219 (interactive "sVariable regexp: ")
220 (setq cus-test-errors nil
)
221 (setq cus-test-tested-variables nil
)
224 (push symbol cus-test-tested-variables
)
225 ;; Be verbose in case we hang.
226 (message "Cus Test running...%s %s"
227 (length cus-test-tested-variables
) symbol
)
228 (condition-case alpha
229 (let* ((type (custom-variable-type symbol
))
230 (conv (widget-convert type
))
231 (get (or (get symbol
'custom-get
) 'default-value
))
234 (when (default-boundp symbol
)
235 (push (funcall get symbol
) values
)
236 (push (eval (car (get symbol
'standard-value
))) values
))
238 (push (symbol-value symbol
) values
))
239 ;; That does not work.
240 ;; (push (widget-get conv :value) values)
243 (mapc (lambda (value)
244 (unless (widget-apply conv
:match value
)
245 (setq mismatch
'mismatch
)))
248 ;; Store symbols with a custom-get property.
249 (when (get symbol
'custom-get
)
250 (add-to-list 'cus-test-vars-with-custom-get symbol
))
252 ;; Changed outside the customize buffer?
253 ;; This routine is not very much tested.
255 (or (get symbol
'customized-value
)
256 (get symbol
'saved-value
)
257 (get symbol
'standard-value
))))
260 (not (equal (eval (car c-value
)) (symbol-value symbol
)))
261 (add-to-list 'cus-test-vars-with-changed-state symbol
)))
264 (push symbol cus-test-errors
)))
267 (push symbol cus-test-errors
)
268 (message "Error for %s: %s" symbol alpha
))))
269 (cus-test-get-options regexp
))
270 (message "%s options tested"
271 (length cus-test-tested-variables
))
272 (cus-test-errors-display))
274 (defun cus-test-get-options (regexp)
275 "Return a list of custom options matching REGEXP."
281 ;; (user-variable-p symbol)
282 (get symbol
'standard-value
)
283 ;; (get symbol 'saved-value)
284 (get symbol
'custom-type
))
285 (string-match regexp
(symbol-name symbol
))
286 (not (member symbol cus-test-skip-list
))
287 (push symbol found
))))
290 (defun cus-test-errors-display ()
291 "Report about the errors found by cus-test."
292 (with-output-to-temp-buffer "*cus-test-errors*"
293 (set-buffer standard-output
)
294 (insert (format "Cus Test tested %s variables.\
295 See `cus-test-tested-variables'.\n\n"
296 (length cus-test-tested-variables
)))
297 (if (not cus-test-errors
)
298 (insert "No errors found by cus-test.")
299 (insert "The following variables seem to have problems:\n\n")
300 (dolist (e cus-test-errors
)
301 (insert (symbol-name e
) "\n")))))
303 (defun cus-test-load-custom-loads ()
304 "Call `custom-load-symbol' on all atoms."
306 (mapatoms 'custom-load-symbol
)
307 (run-hooks 'cus-test-after-load-libs-hook
))
309 (defun cus-test-load-libs ()
310 "Load the libraries with autoloads.
311 Don't load libraries in `cus-test-libs-noloads'."
313 (setq cus-test-libs-errors nil
)
314 (setq cus-test-libs-loaded nil
)
317 (condition-case alpha
318 (unless (member file cus-test-libs-noloads
)
320 (push file cus-test-libs-loaded
))
322 (push (cons file alpha
) cus-test-libs-errors
)
323 (message "Error for %s: %s" file alpha
))))
324 (cus-test-get-autoload-deps))
325 (message "%s libraries loaded successfully"
326 (length cus-test-libs-loaded
))
327 (if (not cus-test-libs-errors
)
328 (message "No load problems encountered")
329 (message "The following load problems appeared:")
330 (cus-test-message cus-test-libs-errors
))
331 (run-hooks 'cus-test-after-load-libs-hook
))
333 (defun cus-test-get-autoload-deps ()
334 "Return the list of libraries with autoloads."
336 (insert-file-contents (locate-library "loaddefs"))
337 ;; This is from `customize-option'.
340 (search-forward "\n;;; Generated autoloads from " nil t
)
341 (goto-char (match-end 0))
342 (setq file
(buffer-substring (point)
343 (progn (end-of-line) (point))))
344 (setq file
(file-name-nondirectory file
))
345 (string-match "\\.el\\'" file
)
346 (setq file
(substring file
0 (match-beginning 0)))
347 (setq deps
(nconc deps
(list file
))))
350 (defun cus-test-message (list)
351 "Print the members of LIST line by line."
352 (dolist (m list
) (message "%s" m
)))
355 ;;; The routines for batch mode:
357 (defun cus-test-opts ()
358 "Test custom options.
359 This function is suitable for batch mode. E.g., invoke
361 src/emacs -batch -l admin/cus-test.el -f cus-test-opts
363 in the Emacs source directory."
365 (message "Running %s" 'cus-test-load-libs
)
367 (message "Running %s" 'cus-test-load-custom-loads
)
368 (cus-test-load-custom-loads)
369 (message "Running %s" 'cus-test-apropos
)
370 (cus-test-apropos "")
371 (if (not cus-test-errors
)
372 (message "No problems found")
373 (message "The following options might have problems:")
374 (cus-test-message cus-test-errors
)))
376 (defun cus-test-deps ()
377 "Run a verbose version of `custom-load-symbol' on all atoms.
378 This function is suitable for batch mode. E.g., invoke
380 src/emacs -batch -l admin/cus-test.el -f cus-test-deps
382 in the Emacs source directory."
384 (setq cus-test-deps-errors nil
)
385 (setq cus-test-deps-required nil
)
386 (setq cus-test-deps-loaded nil
)
388 ;; This code is mainly from `custom-load-symbol'.
390 (let ((custom-load-recursion t
))
391 (dolist (load (get symbol
'custom-loads
))
394 ;; (condition-case nil (require load) (error nil))
395 (condition-case alpha
396 (unless (featurep load
)
398 (push (list symbol load
) cus-test-deps-required
))
400 (push (list symbol load alpha
) cus-test-deps-errors
)
401 (message "Require problem: %s %s %s" symbol load alpha
))))
402 ((equal load
"loaddefs")
404 (message "Symbol %s has loaddefs as custom dependency" symbol
)
405 cus-test-deps-errors
))
406 ;; This is subsumed by the test below, but it's much
408 ((assoc load load-history
))
410 ;; (assoc (locate-library load) load-history)
411 ;; but has been optimized not to load locate-library
413 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load
)
416 (dolist (loaded load-history
)
417 (and (stringp (car loaded
))
418 (string-match regexp
(car loaded
))
421 ;; Without this, we would load cus-edit recursively.
422 ;; We are still loading it when we call this,
423 ;; and it is not in load-history yet.
424 ((equal load
"cus-edit"))
425 ;; This would ignore load problems with files in
427 ;; ((locate-library (concat term-file-prefix load)))
429 ;; (condition-case nil (load load) (error nil))
430 (condition-case alpha
433 (push (list symbol load
) cus-test-deps-loaded
))
435 (push (list symbol load alpha
) cus-test-deps-errors
)
436 (message "Load Problem: %s %s %s" symbol load alpha
))))
438 (message "%s features required"
439 (length cus-test-deps-required
))
440 (message "%s files loaded"
441 (length cus-test-deps-loaded
))
442 (if (not cus-test-deps-errors
)
443 (message "No load problems encountered")
444 (message "The following load problems appeared:")
445 (cus-test-message cus-test-deps-errors
))
446 (run-hooks 'cus-test-after-load-libs-hook
))
448 (defun cus-test-libs ()
449 "Load the libraries with autoloads in separate processes.
450 This function is useful to detect load problems of libraries.
451 It is suitable for batch mode. E.g., invoke
453 src/emacs -batch -l admin/cus-test.el -f cus-test-libs
455 in the Emacs source directory."
458 (setq cus-test-libs-errors nil
)
459 (setq cus-test-libs-loaded nil
)
460 (cd source-directory
)
461 (if (not (file-executable-p "src/emacs"))
462 (error "No Emacs executable in %ssrc" default-directory
))
465 (condition-case alpha
467 (setq fn
(locate-library file
))
469 (error "Library %s not found" file
))
470 (setq cmd
(concat "src/emacs -batch -l " fn
))
471 (setq status
(call-process shell-file-name nil nil nil
472 shell-command-switch cmd
))
476 (push file cus-test-libs-loaded
))
478 (push (cons file alpha
) cus-test-libs-errors
)
479 (message "Error for %s: %s" file alpha
))))
480 (cus-test-get-autoload-deps))
481 (message "Default Directory: %s" default-directory
)
482 (message "%s libraries had no load errors"
483 (length cus-test-libs-loaded
))
484 (if (not cus-test-libs-errors
)
485 (message "No load problems encountered")
486 (message "The following load problems appeared:")
487 (cus-test-message cus-test-libs-errors
))
488 (run-hooks 'cus-test-after-load-libs-hook
)))
490 (defun cus-test-noloads ()
491 "Find custom options not loaded by `custom-load-symbol'.
492 Calling this function after `cus-test-load-libs' is not meaningful.
493 It is suitable for batch mode. E.g., invoke
495 src/emacs -batch -l admin/cus-test.el -f cus-test-noloads
497 in the Emacs source directory."
501 (message "Running %s" 'cus-test-load-custom-loads
)
502 (cus-test-load-custom-loads)
504 (cus-test-get-options ""))
506 (message "Running %s" 'cus-test-load-libs
)
508 (setq cus-test-vars-not-cus-loaded
509 (cus-test-get-options ""))
511 (dolist (o cus-loaded
)
512 (setq cus-test-vars-not-cus-loaded
513 (delete o cus-test-vars-not-cus-loaded
)))
515 (if (not cus-test-vars-not-cus-loaded
)
516 (message "No options not loaded by custom-load-symbol found")
517 (message "The following options were not loaded by custom-load-symbol:")
519 (sort cus-test-vars-not-cus-loaded
'string
<)))))
521 ;; And last but not least a quiz:
523 ;; Evaluation of the form (customize-option 'debug-on-error) yields a
524 ;; *Customize* buffer with a mismatch mess. Why?
528 ;;; arch-tag: a4991a31-548d-48fb-8ba1-1ebbe68eb2e7
529 ;;; cus-test.el ends here