+ (if (not cus-test-errors)
+ (message "No problems found")
+ (message "The following options might have problems:")
+ (cus-test-message cus-test-errors)))
+
+(defun cus-test-deps ()
+ "Run a verbose version of `custom-load-symbol' on all atoms.
+This function is suitable for batch mode. E.g., invoke
+
+ src/emacs -batch -l admin/cus-test.el -f cus-test-deps
+
+in the Emacs source directory."
+ (interactive)
+ (setq cus-test-deps-errors nil)
+ (setq cus-test-deps-required nil)
+ (setq cus-test-deps-loaded nil)
+ (mapatoms
+ ;; This code is mainly from `custom-load-symbol'.
+ (lambda (symbol)
+ (let ((custom-load-recursion t))
+ (dolist (load (get symbol 'custom-loads))
+ (cond
+ ((symbolp load)
+ ;; (condition-case nil (require load) (error nil))
+ (condition-case alpha
+ (unless (featurep load)
+ (require load)
+ (push (list symbol load) cus-test-deps-required))
+ (error
+ (push (list symbol load alpha) cus-test-deps-errors)
+ (message "Require problem: %s %s %s" symbol load alpha))))
+ ((equal load "loaddefs")
+ (push
+ (message "Symbol %s has loaddefs as custom dependency" symbol)
+ cus-test-deps-errors))
+ ;; This is subsumed by the test below, but it's much
+ ;; faster.
+ ((assoc load load-history))
+ ;; This was just
+ ;; (assoc (locate-library load) load-history)
+ ;; but has been optimized not to load locate-library
+ ;; if not necessary.
+ ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load)
+ "\\(\\'\\|\\.\\)"))
+ (found nil))
+ (dolist (loaded load-history)
+ (and (stringp (car loaded))
+ (string-match regexp (car loaded))
+ (setq found t)))
+ found))
+ ;; Without this, we would load cus-edit recursively.
+ ;; We are still loading it when we call this,
+ ;; and it is not in load-history yet.
+ ((equal load "cus-edit"))
+ ;; This would ignore load problems with files in
+ ;; lisp/term/
+ ;; ((locate-library (concat term-file-prefix load)))
+ (t
+ ;; (condition-case nil (load load) (error nil))
+ (condition-case alpha
+ (progn
+ (load load)
+ (push (list symbol load) cus-test-deps-loaded))
+ (error
+ (push (list symbol load alpha) cus-test-deps-errors)
+ (message "Load Problem: %s %s %s" symbol load alpha))))
+ )))))
+ (message "%s features required"
+ (length cus-test-deps-required))
+ (message "%s files loaded"
+ (length cus-test-deps-loaded))
+ (if (not cus-test-deps-errors)
+ (message "No load problems encountered")
+ (message "The following load problems appeared:")
+ (cus-test-message cus-test-deps-errors))
+ (run-hooks 'cus-test-after-load-libs-hook))
+
+(defun cus-test-libs ()
+ "Load the libraries with autoloads in separate processes.
+This function is useful to detect load problems of libraries.
+It is suitable for batch mode. E.g., invoke
+
+ src/emacs -batch -l admin/cus-test.el -f cus-test-libs
+
+in the Emacs source directory."
+ (interactive)
+ (with-temp-buffer
+ (setq cus-test-libs-errors nil)
+ (setq cus-test-libs-loaded nil)
+ (cd source-directory)
+ (if (not (file-executable-p "src/emacs"))
+ (error "No Emacs executable in %ssrc" default-directory))
+ (mapc
+ (lambda (file)
+ (condition-case alpha
+ (let (fn cmd status)
+ (setq fn (locate-library file))
+ (if (not fn)
+ (error "Library %s not found" file))
+ (setq cmd (concat "src/emacs -batch -l " fn))
+ (setq status (call-process shell-file-name nil nil nil
+ shell-command-switch cmd))
+ (if (equal status 0)
+ (message "%s" file)
+ (error "%s" status))
+ (push file cus-test-libs-loaded))
+ (error
+ (push (cons file alpha) cus-test-libs-errors)
+ (message "Error for %s: %s" file alpha))))
+ (cus-test-get-autoload-deps))
+ (message "Default Directory: %s" default-directory)
+ (message "%s libraries had no load errors"
+ (length cus-test-libs-loaded))
+ (if (not cus-test-libs-errors)
+ (message "No load problems encountered")
+ (message "The following load problems appeared:")
+ (cus-test-message cus-test-libs-errors))
+ (run-hooks 'cus-test-after-load-libs-hook)))
+
+(defun cus-test-noloads ()
+ "Find custom options not loaded by `custom-load-symbol'.
+Calling this function after `cus-test-load-libs' is not meaningful.
+It is suitable for batch mode. E.g., invoke
+
+ src/emacs -batch -l admin/cus-test.el -f cus-test-noloads
+
+in the Emacs source directory."
+ (interactive)
+ (let (cus-loaded)
+
+ (message "Running %s" 'cus-test-load-custom-loads)
+ (cus-test-load-custom-loads)
+ (setq cus-loaded
+ (cus-test-get-options ""))
+
+ (message "Running %s" 'cus-test-load-libs)
+ (cus-test-load-libs)
+ (setq cus-test-vars-not-cus-loaded
+ (cus-test-get-options ""))
+
+ (dolist (o cus-loaded)
+ (setq cus-test-vars-not-cus-loaded
+ (delete o cus-test-vars-not-cus-loaded)))
+
+ (if (not cus-test-vars-not-cus-loaded)
+ (message "No options not loaded by custom-load-symbol found")
+ (message "The following options were not loaded by custom-load-symbol:")
+ (cus-test-message
+ (sort cus-test-vars-not-cus-loaded 'string<)))))
+
+;; And last but not least a quiz:
+;;
+;; Evaluation of the form (customize-option 'debug-on-error) yields a
+;; *Customize* buffer with a mismatch mess. Why?