diff options
Diffstat (limited to 'admin/cus-test.el')
| -rw-r--r-- | admin/cus-test.el | 134 |
1 files changed, 102 insertions, 32 deletions
diff --git a/admin/cus-test.el b/admin/cus-test.el index bce5f5da3cf..6b8ec9abe02 100644 --- a/admin/cus-test.el +++ b/admin/cus-test.el | |||
| @@ -30,11 +30,11 @@ | |||
| 30 | ;; | 30 | ;; |
| 31 | ;; The basic tests can be run in batch mode. Invoke them with | 31 | ;; The basic tests can be run in batch mode. Invoke them with |
| 32 | ;; | 32 | ;; |
| 33 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-opts | 33 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-opts [all] |
| 34 | ;; | 34 | ;; |
| 35 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-deps | 35 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-deps |
| 36 | ;; | 36 | ;; |
| 37 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-libs | 37 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-libs [all] |
| 38 | ;; | 38 | ;; |
| 39 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-noloads | 39 | ;; src/emacs -batch -l admin/cus-test.el -f cus-test-noloads |
| 40 | ;; | 40 | ;; |
| @@ -99,8 +99,14 @@ | |||
| 99 | (defvar cus-test-skip-list nil | 99 | (defvar cus-test-skip-list nil |
| 100 | "List of variables to disregard by `cus-test-apropos'.") | 100 | "List of variables to disregard by `cus-test-apropos'.") |
| 101 | 101 | ||
| 102 | ;; Loading dunnet in batch mode leads to a Dead end. | 102 | (defvar cus-test-libs-noloads |
| 103 | (defvar cus-test-libs-noloads '("play/dunnet.el") | 103 | ;; Loading dunnet in batch mode leads to a Dead end. |
| 104 | ;; blessmail writes a file. | ||
| 105 | ;; characters cannot be loaded twice ("Category `a' is already defined"). | ||
| 106 | '("play/dunnet.el" "emulation/edt-mapper.el" | ||
| 107 | "loadup.el" "mail/blessmail.el" "international/characters.el" | ||
| 108 | "cedet/ede/loaddefs.el" "cedet/semantic/loaddefs.el" | ||
| 109 | "net/tramp-loaddefs.el") | ||
| 104 | "List of files not to load by `cus-test-load-libs'. | 110 | "List of files not to load by `cus-test-load-libs'. |
| 105 | Names should be as they appear in loaddefs.el.") | 111 | Names should be as they appear in loaddefs.el.") |
| 106 | 112 | ||
| @@ -226,17 +232,38 @@ The detected problematic options are stored in `cus-test-errors'." | |||
| 226 | (length cus-test-tested-variables)) | 232 | (length cus-test-tested-variables)) |
| 227 | (cus-test-errors-display)) | 233 | (cus-test-errors-display)) |
| 228 | 234 | ||
| 229 | (defun cus-test-get-options (regexp) | 235 | (defun cus-test-cus-load-groups (&optional cus-load) |
| 230 | "Return a list of custom options matching REGEXP." | 236 | "Return a list of current custom groups. |
| 231 | (let (found) | 237 | If CUS-LOAD is non-nil, include groups from cus-load.el." |
| 238 | (append (mapcar 'cdr custom-current-group-alist) | ||
| 239 | (if cus-load | ||
| 240 | (with-temp-buffer | ||
| 241 | (insert-file-contents (locate-library "cus-load.el")) | ||
| 242 | (search-forward "(put '") | ||
| 243 | (beginning-of-line) | ||
| 244 | (let (res) | ||
| 245 | (while (and (looking-at "^(put '\\(\\S-+\\)") | ||
| 246 | (zerop (forward-line 1))) | ||
| 247 | (push (intern (match-string 1)) res)) | ||
| 248 | res))))) | ||
| 249 | |||
| 250 | (defun cus-test-get-options (regexp &optional group) | ||
| 251 | "Return a list of custom options matching REGEXP. | ||
| 252 | If GROUP is non-nil, return groups rather than options. | ||
| 253 | If GROUP is `cus-load', include groups listed in cus-loads as well as | ||
| 254 | currently defined groups." | ||
| 255 | (let ((groups (if group (cus-test-cus-load-groups (eq group 'cus-load)))) | ||
| 256 | found) | ||
| 232 | (mapatoms | 257 | (mapatoms |
| 233 | (lambda (symbol) | 258 | (lambda (symbol) |
| 234 | (and | 259 | (and |
| 235 | (or | 260 | (if group |
| 236 | ;; (user-variable-p symbol) | 261 | (memq symbol groups) |
| 237 | (get symbol 'standard-value) | 262 | (or |
| 238 | ;; (get symbol 'saved-value) | 263 | ;; (user-variable-p symbol) |
| 239 | (get symbol 'custom-type)) | 264 | (get symbol 'standard-value) |
| 265 | ;; (get symbol 'saved-value) | ||
| 266 | (get symbol 'custom-type))) | ||
| 240 | (string-match regexp (symbol-name symbol)) | 267 | (string-match regexp (symbol-name symbol)) |
| 241 | (not (member symbol cus-test-skip-list)) | 268 | (not (member symbol cus-test-skip-list)) |
| 242 | (push symbol found)))) | 269 | (push symbol found)))) |
| @@ -276,9 +303,11 @@ The detected problematic options are stored in `cus-test-errors'." | |||
| 276 | (run-hooks 'cus-test-after-load-libs-hook))) | 303 | (run-hooks 'cus-test-after-load-libs-hook))) |
| 277 | 304 | ||
| 278 | ;; This is just cus-test-libs, but loading in the current Emacs process. | 305 | ;; This is just cus-test-libs, but loading in the current Emacs process. |
| 279 | (defun cus-test-load-libs () | 306 | (defun cus-test-load-libs (&optional more) |
| 280 | "Load the libraries with autoloads. | 307 | "Load the libraries with autoloads. |
| 281 | Don't load libraries in `cus-test-libs-noloads'." | 308 | Don't load libraries in `cus-test-libs-noloads'. |
| 309 | If optional argument MORE is \"defcustom\", load all files with defcustoms. | ||
| 310 | If it is \"all\", load all Lisp files." | ||
| 282 | (interactive) | 311 | (interactive) |
| 283 | (cus-test-load-1 | 312 | (cus-test-load-1 |
| 284 | (let ((lispdir (file-name-directory (locate-library "loaddefs")))) | 313 | (let ((lispdir (file-name-directory (locate-library "loaddefs")))) |
| @@ -291,7 +320,9 @@ Don't load libraries in `cus-test-libs-noloads'." | |||
| 291 | (error | 320 | (error |
| 292 | (push (cons file alpha) cus-test-libs-errors) | 321 | (push (cons file alpha) cus-test-libs-errors) |
| 293 | (message "Error for %s: %s" file alpha)))) | 322 | (message "Error for %s: %s" file alpha)))) |
| 294 | (cus-test-get-autoload-deps))))) | 323 | (if more |
| 324 | (cus-test-get-lisp-files (equal more "all")) | ||
| 325 | (cus-test-get-autoload-deps)))))) | ||
| 295 | 326 | ||
| 296 | (defun cus-test-get-autoload-deps () | 327 | (defun cus-test-get-autoload-deps () |
| 297 | "Return the list of files with autoloads." | 328 | "Return the list of files with autoloads." |
| @@ -302,6 +333,24 @@ Don't load libraries in `cus-test-libs-noloads'." | |||
| 302 | (push (buffer-substring (match-end 0) (line-end-position)) files)) | 333 | (push (buffer-substring (match-end 0) (line-end-position)) files)) |
| 303 | files))) | 334 | files))) |
| 304 | 335 | ||
| 336 | (defun cus-test-get-lisp-files (&optional all) | ||
| 337 | "Return list of all Lisp files with defcustoms. | ||
| 338 | Optional argument ALL non-nil means list all (non-obsolete) Lisp files." | ||
| 339 | (let ((default-directory (expand-file-name "lisp/" source-directory)) | ||
| 340 | (msg "Finding files...")) | ||
| 341 | (message "%s" msg) | ||
| 342 | (prog1 | ||
| 343 | ;; Hack to remove leading "./". | ||
| 344 | (mapcar (lambda (e) (substring e 2)) | ||
| 345 | (apply 'process-lines find-program | ||
| 346 | "-name" "obsolete" "-prune" "-o" | ||
| 347 | "-name" "[^.]*.el" ; ignore .dir-locals.el | ||
| 348 | (if all | ||
| 349 | '("-print") | ||
| 350 | (list "-exec" grep-program | ||
| 351 | "-l" "^[ \t]*(defcustom" "{}" "+")))) | ||
| 352 | (message "%sdone" msg)))) | ||
| 353 | |||
| 305 | (defun cus-test-message (list) | 354 | (defun cus-test-message (list) |
| 306 | "Print the members of LIST line by line." | 355 | "Print the members of LIST line by line." |
| 307 | (dolist (m list) (message "%s" m))) | 356 | (dolist (m list) (message "%s" m))) |
| @@ -309,16 +358,21 @@ Don't load libraries in `cus-test-libs-noloads'." | |||
| 309 | 358 | ||
| 310 | ;;; The routines for batch mode: | 359 | ;;; The routines for batch mode: |
| 311 | 360 | ||
| 312 | (defun cus-test-opts () | 361 | (defun cus-test-opts (&optional all) |
| 313 | "Test custom options. | 362 | "Test custom options. |
| 314 | This function is suitable for batch mode. E.g., invoke | 363 | This function is suitable for batch mode. E.g., invoke |
| 315 | 364 | ||
| 316 | src/emacs -batch -l admin/cus-test.el -f cus-test-opts | 365 | src/emacs -batch -l admin/cus-test.el -f cus-test-opts |
| 317 | 366 | ||
| 318 | in the Emacs source directory." | 367 | in the Emacs source directory. |
| 368 | Normally only tests options belonging to files in loaddefs.el. | ||
| 369 | If optional argument ALL is non-nil, test all files with defcustoms." | ||
| 319 | (interactive) | 370 | (interactive) |
| 371 | (and noninteractive | ||
| 372 | command-line-args-left | ||
| 373 | (setq all (pop command-line-args-left))) | ||
| 320 | (message "Running %s" 'cus-test-load-libs) | 374 | (message "Running %s" 'cus-test-load-libs) |
| 321 | (cus-test-load-libs) | 375 | (cus-test-load-libs (if all "defcustom")) |
| 322 | (message "Running %s" 'cus-test-load-custom-loads) | 376 | (message "Running %s" 'cus-test-load-custom-loads) |
| 323 | (cus-test-load-custom-loads) | 377 | (cus-test-load-custom-loads) |
| 324 | (message "Running %s" 'cus-test-apropos) | 378 | (message "Running %s" 'cus-test-apropos) |
| @@ -401,21 +455,27 @@ in the Emacs source directory." | |||
| 401 | (cus-test-message cus-test-deps-errors)) | 455 | (cus-test-message cus-test-deps-errors)) |
| 402 | (run-hooks 'cus-test-after-load-libs-hook)) | 456 | (run-hooks 'cus-test-after-load-libs-hook)) |
| 403 | 457 | ||
| 404 | (defun cus-test-libs () | 458 | (defun cus-test-libs (&optional more) |
| 405 | "Load the libraries with autoloads in separate processes. | 459 | "Load the libraries with autoloads in separate processes. |
| 406 | This function is useful to detect load problems of libraries. | 460 | This function is useful to detect load problems of libraries. |
| 407 | It is suitable for batch mode. E.g., invoke | 461 | It is suitable for batch mode. E.g., invoke |
| 408 | 462 | ||
| 409 | ./src/emacs -batch -l admin/cus-test.el -f cus-test-libs | 463 | ./src/emacs -batch -l admin/cus-test.el -f cus-test-libs |
| 410 | 464 | ||
| 411 | in the Emacs source directory." | 465 | in the Emacs source directory. |
| 466 | |||
| 467 | If optional argument MORE is \"defcustom\", load all files with defcustoms. | ||
| 468 | If it is \"all\", load all Lisp files." | ||
| 412 | (interactive) | 469 | (interactive) |
| 470 | (and noninteractive | ||
| 471 | command-line-args-left | ||
| 472 | (setq more (pop command-line-args-left))) | ||
| 413 | (cus-test-load-1 | 473 | (cus-test-load-1 |
| 414 | (let ((default-directory source-directory) | 474 | (let* ((default-directory source-directory) |
| 415 | (emacs (expand-file-name "src/emacs")) | 475 | (emacs (expand-file-name "src/emacs")) |
| 416 | skipped) | 476 | skipped) |
| 417 | (or (file-executable-p emacs) | 477 | (or (file-executable-p emacs) |
| 418 | (error "No Emacs executable in %ssrc" default-directory)) | 478 | (error "No such executable `%s'" emacs)) |
| 419 | (mapc | 479 | (mapc |
| 420 | (lambda (file) | 480 | (lambda (file) |
| 421 | (if (member file cus-test-libs-noloads) | 481 | (if (member file cus-test-libs-noloads) |
| @@ -436,7 +496,9 @@ in the Emacs source directory." | |||
| 436 | (error | 496 | (error |
| 437 | (push (cons file alpha) cus-test-libs-errors) | 497 | (push (cons file alpha) cus-test-libs-errors) |
| 438 | (message "Error for %s: %s" file alpha))))) | 498 | (message "Error for %s: %s" file alpha))))) |
| 439 | (cus-test-get-autoload-deps)) | 499 | (if more |
| 500 | (cus-test-get-lisp-files (equal more "all")) | ||
| 501 | (cus-test-get-autoload-deps))) | ||
| 440 | (message "Default directory: %s" default-directory) | 502 | (message "Default directory: %s" default-directory) |
| 441 | (when skipped | 503 | (when skipped |
| 442 | (message "The following libraries were skipped:") | 504 | (message "The following libraries were skipped:") |
| @@ -451,17 +513,17 @@ It is suitable for batch mode. E.g., invoke | |||
| 451 | 513 | ||
| 452 | in the Emacs source directory." | 514 | in the Emacs source directory." |
| 453 | (interactive) | 515 | (interactive) |
| 454 | (let (cus-loaded) | 516 | (let ((groups-loaded (cus-test-get-options "" 'cus-load)) |
| 517 | cus-loaded groups-not-loaded) | ||
| 455 | 518 | ||
| 456 | (message "Running %s" 'cus-test-load-custom-loads) | 519 | (message "Running %s" 'cus-test-load-custom-loads) |
| 457 | (cus-test-load-custom-loads) | 520 | (cus-test-load-custom-loads) |
| 458 | (setq cus-loaded | 521 | (setq cus-loaded (cus-test-get-options "")) |
| 459 | (cus-test-get-options "")) | ||
| 460 | 522 | ||
| 461 | (message "Running %s" 'cus-test-load-libs) | 523 | (message "Running %s" 'cus-test-load-libs) |
| 462 | (cus-test-load-libs) | 524 | (cus-test-load-libs "all") |
| 463 | (setq cus-test-vars-not-cus-loaded | 525 | (setq cus-test-vars-not-cus-loaded (cus-test-get-options "") |
| 464 | (cus-test-get-options "")) | 526 | groups-not-loaded (cus-test-get-options "" t)) |
| 465 | 527 | ||
| 466 | (dolist (o cus-loaded) | 528 | (dolist (o cus-loaded) |
| 467 | (setq cus-test-vars-not-cus-loaded | 529 | (setq cus-test-vars-not-cus-loaded |
| @@ -471,7 +533,15 @@ in the Emacs source directory." | |||
| 471 | (message "No options not loaded by custom-load-symbol found") | 533 | (message "No options not loaded by custom-load-symbol found") |
| 472 | (message "The following options were not loaded by custom-load-symbol:") | 534 | (message "The following options were not loaded by custom-load-symbol:") |
| 473 | (cus-test-message | 535 | (cus-test-message |
| 474 | (sort cus-test-vars-not-cus-loaded 'string<))))) | 536 | (sort cus-test-vars-not-cus-loaded 'string<))) |
| 537 | |||
| 538 | (dolist (o groups-loaded) | ||
| 539 | (setq groups-not-loaded (delete o groups-not-loaded))) | ||
| 540 | |||
| 541 | (if (not groups-not-loaded) | ||
| 542 | (message "No groups not in cus-load.el found") | ||
| 543 | (message "The following groups are not in cus-load.el:") | ||
| 544 | (cus-test-message (sort groups-not-loaded 'string<))))) | ||
| 475 | 545 | ||
| 476 | (provide 'cus-test) | 546 | (provide 'cus-test) |
| 477 | 547 | ||