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)
115 ;;; Workarounds. For a smooth run and to avoid some side effects.
117 (defvar cus-test-after-load-libs-hook nil
118 "Used to switch off undesired side effects of loading libraries.")
120 (defvar cus-test-skip-list nil
121 "List of variables to disregard by `cus-test-apropos'.")
123 (defvar cus-test-noloads nil
124 "List of libraries not to load by `cus-test-load-libs'.")
126 ;; The file eudc-export.el loads libraries "bbdb" and "bbdb-com" which
127 ;; are not part of GNU Emacs: (locate-library "bbdb") => nil
128 ;; We avoid the resulting errors from loading eudc-export.el:
132 ;; This avoids a hang of `cus-test-apropos' in 21.2.
133 ;; (add-to-list 'cus-test-skip-list 'sh-alias-alist)
135 ;; Don't create a file `filesets-menu-cache-file'.
136 (setq filesets-menu-cache-file
"")
137 ;; Disable filesets hooks.
139 'cus-test-after-load-libs-hook
141 (remove-hook 'menu-bar-update-hook
'filesets-build-menu-maybe
)
142 (remove-hook 'kill-emacs-hook
'filesets-exit
)
143 (remove-hook 'kill-buffer-hook
'filesets-remove-from-ubl
)
144 (remove-hook 'first-change-hook
'filesets-reset-filename-on-change
)
147 ;; Loading dunnet in batch mode leads to a Dead end.
148 (let (noninteractive) (load "dunnet"))
149 (add-to-list 'cus-test-noloads
"dunnet")
152 (setq viper-mode nil
)
154 ;; Don't create a file `save-place-file'.
155 (eval-after-load "saveplace"
156 '(remove-hook 'kill-emacs-hook
'save-place-kill-emacs-hook
))
158 ;; Don't create a file `abbrev-file-name'.
159 (setq save-abbrevs nil
)
161 ;; Avoid compile logs from adviced functions.
162 (eval-after-load "bytecomp"
163 '(setq ad-default-compilation-action
'never
))
168 ;; We want to log all messages.
169 (setq message-log-max t
)
174 (defvar cus-test-errors nil
175 "List of problematic variables found by `cus-test-apropos'.")
177 (defvar cus-test-tested-variables nil
178 "List of options tested by last call of `cus-test-apropos'.")
180 (defvar cus-test-deps-errors nil
181 "List of require/load problems found by `cus-test-deps'.")
183 (defvar cus-test-deps-required nil
184 "List of dependencies required by `cus-test-deps'.
185 Only unloaded features will be require'd.")
187 (defvar cus-test-deps-loaded nil
188 "List of dependencies loaded by `cus-test-deps'.")
190 (defvar cus-test-libs-errors nil
191 "List of load problems found by `cus-test-load-libs' or `cus-test-libs'.")
193 (defvar cus-test-libs-loaded nil
194 "List of files loaded by `cus-test-load-libs' or `cus-test-libs'.")
196 ;; I haven't understood this :get stuff. The symbols with a
197 ;; custom-get property are stored here.
198 (defvar cus-test-vars-with-custom-get nil
199 "Set by `cus-test-apropos' to a list of options with :get property.")
201 (defvar cus-test-vars-with-changed-state nil
202 "Set by `cus-test-apropos' to a list of options with state 'changed.")
204 (defun cus-test-apropos (regexp)
205 "Check the options matching REGEXP.
206 The detected problematic options are stored in `cus-test-errors'."
207 (interactive "sVariable regexp: ")
208 (setq cus-test-errors nil
)
209 (setq cus-test-tested-variables nil
)
212 (push symbol cus-test-tested-variables
)
213 ;; Be verbose in case we hang.
214 (message "Cus Test running...%s %s"
215 (length cus-test-tested-variables
) symbol
)
216 (condition-case alpha
217 (let* ((type (custom-variable-type symbol
))
218 (conv (widget-convert type
))
219 (get (or (get symbol
'custom-get
) 'default-value
))
222 (when (default-boundp symbol
)
223 (push (funcall get symbol
) values
)
224 (push (eval (car (get symbol
'standard-value
))) values
))
226 (push (symbol-value symbol
) values
))
227 ;; That does not work.
228 ;; (push (widget-get conv :value) values)
231 (mapc (lambda (value)
232 (unless (widget-apply conv
:match value
)
233 (setq mismatch
'mismatch
)))
236 ;; Store symbols with a custom-get property.
237 (when (get symbol
'custom-get
)
238 (add-to-list 'cus-test-vars-with-custom-get symbol
))
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 symbol
)))
252 (push symbol cus-test-errors
)))
255 (push symbol cus-test-errors
)
256 (message "Error for %s: %s" symbol alpha
))))
257 (cus-test-get-options regexp
))
258 (message "%s options tested"
259 (length cus-test-tested-variables
))
260 (cus-test-errors-display))
262 (defun cus-test-get-options (regexp)
263 "Return a list of custom options matching REGEXP."
269 ;; (user-variable-p symbol)
270 (get symbol
'standard-value
)
271 ;; (get symbol 'saved-value)
272 (get symbol
'custom-type
))
273 (string-match regexp
(symbol-name symbol
))
274 (not (member symbol cus-test-skip-list
))
275 (push symbol found
))))
278 (defun cus-test-errors-display ()
279 "Report about the errors found by cus-test."
280 (with-output-to-temp-buffer "*cus-test-errors*"
281 (set-buffer standard-output
)
282 (insert (format "Cus Test tested %s variables.\
283 See `cus-test-tested-variables'.\n\n"
284 (length cus-test-tested-variables
)))
285 (if (not cus-test-errors
)
286 (insert "No errors found by cus-test.")
287 (insert "The following variables seem to have problems:\n\n")
288 (dolist (E cus-test-errors
)
289 (insert (symbol-name E
) "\n")))))
291 (defun cus-test-load-custom-loads ()
292 "Call `custom-load-symbol' on all atoms."
294 (mapatoms 'custom-load-symbol
)
295 (run-hooks 'cus-test-after-load-libs-hook
))
297 (defun cus-test-load-libs ()
298 "Load the libraries with autoloads.
299 Don't load libraries in `cus-test-noloads'."
301 (setq cus-test-libs-errors nil
)
302 (setq cus-test-libs-loaded nil
)
305 (condition-case alpha
306 (unless (member file cus-test-noloads
)
308 (push file cus-test-libs-loaded
))
310 (push (cons file alpha
) cus-test-libs-errors
)
311 (message "Error for %s: %s" file alpha
))))
312 (cus-test-get-autoload-deps))
313 (message "%s libraries loaded successfully"
314 (length cus-test-libs-loaded
))
315 (if (not cus-test-libs-errors
)
316 (message "No load problems encountered")
317 (message "The following load problems appeared:")
318 (cus-test-message cus-test-libs-errors
))
319 (run-hooks 'cus-test-after-load-libs-hook
))
321 (defun cus-test-get-autoload-deps ()
322 "Return the list of libraries with autoloads."
324 (insert-file-contents (locate-library "loaddefs"))
325 ;; This is from `customize-option'.
328 (search-forward "\n;;; Generated autoloads from " nil t
)
329 (goto-char (match-end 0))
330 (setq file
(buffer-substring (point)
331 (progn (end-of-line) (point))))
332 (setq file
(file-name-nondirectory file
))
333 (string-match "\\.el\\'" file
)
334 (setq file
(substring file
0 (match-beginning 0)))
335 (setq deps
(nconc deps
(list file
))))
338 (defun cus-test-message (list)
339 "Print the members of LIST line by line."
340 (dolist (m list
) (message "%s" m
)))
343 ;;; The routines for batch mode:
345 (defun cus-test-opts ()
346 "Test custom options.
347 This function is suitable for batch mode. E.g., invoke
349 src/emacs -batch -l admin/cus-test.el -f cus-test-opts
351 in the emacs source directory."
353 (message "Running %s" 'cus-test-load-libs
)
355 (message "Running %s" 'cus-test-load-custom-loads
)
356 (cus-test-load-custom-loads)
357 (message "Running %s" 'cus-test-apropos
)
358 (cus-test-apropos "")
359 (if (not cus-test-errors
)
360 (message "No problems found")
361 (message "The following options might have problems:")
362 (cus-test-message cus-test-errors
)))
364 (defun cus-test-deps ()
365 "Run a verbose version of `custom-load-symbol' on all atoms.
366 This function is suitable for batch mode. E.g., invoke
368 src/emacs -batch -l admin/cus-test.el -f cus-test-deps
370 in the emacs source directory."
372 (setq cus-test-deps-errors nil
)
373 (setq cus-test-deps-required nil
)
374 (setq cus-test-deps-loaded nil
)
376 ;; This code is mainly from `custom-load-symbol'.
378 (unless custom-load-recursion
379 (let ((custom-load-recursion t
))
380 (dolist (load (get symbol
'custom-loads
))
383 ;; (condition-case nil (require load) (error nil))
384 (condition-case alpha
385 (unless (featurep load
)
387 (push (list symbol load
) cus-test-deps-required
))
389 (push (list symbol load alpha
) cus-test-deps-errors
)
390 (message "Require problem: %s %s %s" symbol load alpha
))))
391 ((equal load
"loaddefs")
393 (message "Symbol %s has loaddefs as custom dependency" symbol
)
394 cus-test-deps-errors
))
395 ;; This is subsumed by the test below, but it's much
397 ((assoc load load-history
))
399 ;; (assoc (locate-library load) load-history)
400 ;; but has been optimized not to load locate-library
402 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load
)
405 (dolist (loaded load-history
)
406 (and (stringp (car loaded
))
407 (string-match regexp
(car loaded
))
410 ;; Without this, we would load cus-edit recursively.
411 ;; We are still loading it when we call this,
412 ;; and it is not in load-history yet.
413 ((equal load
"cus-edit"))
414 ;; This would ignore load problems with files in
416 ;; ((locate-library (concat term-file-prefix load)))
418 ;; (condition-case nil (load load) (error nil))
419 (condition-case alpha
422 (push (list symbol load
) cus-test-deps-loaded
))
424 (push (list symbol load alpha
) cus-test-deps-errors
)
425 (message "Load Problem: %s %s %s" symbol load alpha
))))
427 (message "%s features required"
428 (length cus-test-deps-required
))
429 (message "%s files loaded"
430 (length cus-test-deps-loaded
))
431 (if (not cus-test-deps-errors
)
432 (message "No load problems encountered")
433 (message "The following load problems appeared:")
434 (cus-test-message cus-test-deps-errors
))
435 (run-hooks 'cus-test-after-load-libs-hook
))
437 (defun cus-test-libs ()
438 "Load the libraries with autoloads in separate processes.
439 This function is useful to detect load problems of libraries.
440 It is suitable for batch mode. E.g., invoke
442 src/emacs -batch -l admin/cus-test.el -f cus-test-libs
444 in the emacs source directory."
447 (setq cus-test-libs-errors nil
)
448 (setq cus-test-libs-loaded nil
)
449 (cd source-directory
)
450 (if (not (file-executable-p "src/emacs"))
451 (error "No Emacs executable in %ssrc" default-directory
))
454 (condition-case alpha
456 (setq fn
(locate-library file
))
458 (error "Library %s not found" file
))
459 (setq cmd
(concat "src/emacs -batch -l " fn
))
460 (setq status
(call-process shell-file-name nil nil nil
461 shell-command-switch cmd
))
465 (push file cus-test-libs-loaded
))
467 (push (cons file alpha
) cus-test-libs-errors
)
468 (message "Error for %s: %s" file alpha
))))
469 (cus-test-get-autoload-deps))
470 (message "Default Directory: %s" default-directory
)
471 (message "%s libraries had no load errors"
472 (length cus-test-libs-loaded
))
473 (if (not cus-test-libs-errors
)
474 (message "No load problems encountered")
475 (message "The following load problems appeared:")
476 (cus-test-message cus-test-libs-errors
))
477 (run-hooks 'cus-test-after-load-libs-hook
)))
481 ;;; cus-test.el ends here