diff options
| author | Gemini Lasswell | 2018-07-14 08:05:51 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-08-03 08:53:02 -0700 |
| commit | a3ba34aeac1b41ca5d12bfe5644d3fdfa894ddda (patch) | |
| tree | 3a04c22cc9f55cc2c8b629f9b4df9f316c8d2117 /test | |
| parent | 2ede75c49b62439e15be3ab8be2c14594f846da6 (diff) | |
| download | emacs-a3ba34aeac1b41ca5d12bfe5644d3fdfa894ddda.tar.gz emacs-a3ba34aeac1b41ca5d12bfe5644d3fdfa894ddda.zip | |
Add new command to expand all "..."s in a backtrace frame
* doc/lispref/debugging.texi (Backtraces): Document new keybinding.
* lisp/emacs-lisp/backtrace.el (backtrace-line-length): Add the
option of unlimited line length.
(backtrace--match-ellipsis-in-string): Add a comment to explain
why this function is necessary.
(backtrace-mode-map): Add keybinding for 'backtrace-expand-ellipses'.
(backtrace-expand-ellipsis): Use 'cl-print-to-string-with-limit'.
(backtrace-expand-ellipses): New command.
(backtrace-print-to-string): Use 'cl-print-to-string-with-limit'.
Tag the printed forms with a gensym instead of the values of
print-length and print-level.
(backtrace--print): Add 'stream' argument.
* test/lisp/emacs-lisp/backtrace-tests.el
(backtrace-tests--expand-ellipsis): Make the test less dependent
on the implementation.
(backtrace-tests--expand-ellipses): New test.
Move the fitting of a printed representation into a limited number of
characters using appropriate values of print-level and print-length
from 'backtrace-print-to-string' to cl-print.el for future use by
other parts of Emacs.
* lisp/emacs-lisp/cl-print.el (cl-print-to-string-with-limit): New
function.
* test/lisp/emacs-lisp/cl-print-tests.el
(cl-print-tests-print-to-string-with-limit): New test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/backtrace-tests.el | 60 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/cl-print-tests.el | 36 |
2 files changed, 87 insertions, 9 deletions
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el b/test/lisp/emacs-lisp/backtrace-tests.el index ba2d33a9d5c..ff26112ab9a 100644 --- a/test/lisp/emacs-lisp/backtrace-tests.el +++ b/test/lisp/emacs-lisp/backtrace-tests.el | |||
| @@ -349,32 +349,74 @@ digit and replace with #[0-9]." | |||
| 349 | (buffer-string))) | 349 | (buffer-string))) |
| 350 | 350 | ||
| 351 | (ert-deftest backtrace-tests--expand-ellipsis () | 351 | (ert-deftest backtrace-tests--expand-ellipsis () |
| 352 | "Backtrace buffers ellipsify large forms and can expand the ellipses." | 352 | "Backtrace buffers ellipsify large forms as buttons which expand the ellipses." |
| 353 | ;; make a backtrace with an ellipsis | 353 | ;; make a backtrace with an ellipsis |
| 354 | ;; expand the ellipsis | 354 | ;; expand the ellipsis |
| 355 | (ert-with-test-buffer (:name "variables") | 355 | (ert-with-test-buffer (:name "variables") |
| 356 | (let* ((print-level nil) | 356 | (let* ((print-level nil) |
| 357 | (print-length nil) | 357 | (print-length nil) |
| 358 | (arg (let ((long (make-list 100 'a)) | 358 | (backtrace-line-length 300) |
| 359 | (deep '(0 (1 (2 (3 (4 (5 (6 (7 (8 (9)))))))))))) | 359 | (arg (make-list 40 (make-string 10 ?a))) |
| 360 | (setf (nth 1 long) deep) | ||
| 361 | long)) | ||
| 362 | (results (backtrace-tests--result arg))) | 360 | (results (backtrace-tests--result arg))) |
| 363 | (backtrace-tests--make-backtrace arg) | 361 | (backtrace-tests--make-backtrace arg) |
| 364 | (backtrace-print) | 362 | (backtrace-print) |
| 365 | 363 | ||
| 366 | ;; There should be two ellipses. Find and expand them. | 364 | ;; There should be an ellipsis. Find and expand it. |
| 367 | (goto-char (point-min)) | 365 | (goto-char (point-min)) |
| 368 | (search-forward "...") | 366 | (search-forward "...") |
| 369 | (backward-char) | 367 | (backward-char) |
| 370 | (push-button) | 368 | (push-button) |
| 371 | (search-forward "...") | ||
| 372 | (backward-char) | ||
| 373 | (push-button) | ||
| 374 | 369 | ||
| 375 | (should (string= (backtrace-tests--get-substring (point-min) (point-max)) | 370 | (should (string= (backtrace-tests--get-substring (point-min) (point-max)) |
| 376 | results))))) | 371 | results))))) |
| 377 | 372 | ||
| 373 | (ert-deftest backtrace-tests--expand-ellipses () | ||
| 374 | "Backtrace buffers ellipsify large forms and can expand the ellipses." | ||
| 375 | (ert-with-test-buffer (:name "variables") | ||
| 376 | (let* ((print-level nil) | ||
| 377 | (print-length nil) | ||
| 378 | (backtrace-line-length 300) | ||
| 379 | (arg (let ((outer (make-list 40 (make-string 10 ?a))) | ||
| 380 | (nested (make-list 40 (make-string 10 ?b)))) | ||
| 381 | (setf (nth 39 nested) (make-list 40 (make-string 10 ?c))) | ||
| 382 | (setf (nth 39 outer) nested) | ||
| 383 | outer)) | ||
| 384 | (results (backtrace-tests--result-with-locals arg))) | ||
| 385 | |||
| 386 | ;; Make a backtrace with local variables visible. | ||
| 387 | (backtrace-tests--make-backtrace arg) | ||
| 388 | (backtrace-print) | ||
| 389 | (backtrace-toggle-locals '(4)) | ||
| 390 | |||
| 391 | ;; There should be two ellipses. | ||
| 392 | (goto-char (point-min)) | ||
| 393 | (should (search-forward "...")) | ||
| 394 | (should (search-forward "...")) | ||
| 395 | (should-error (search-forward "...")) | ||
| 396 | |||
| 397 | ;; Expanding the last frame without argument should expand both | ||
| 398 | ;; ellipses, but the expansions will contain one ellipsis each. | ||
| 399 | (let ((buffer-len (- (point-max) (point-min)))) | ||
| 400 | (goto-char (point-max)) | ||
| 401 | (backtrace-backward-frame) | ||
| 402 | (backtrace-expand-ellipses) | ||
| 403 | (should (> (- (point-max) (point-min)) buffer-len)) | ||
| 404 | (goto-char (point-min)) | ||
| 405 | (should (search-forward "...")) | ||
| 406 | (should (search-forward "...")) | ||
| 407 | (should-error (search-forward "..."))) | ||
| 408 | |||
| 409 | ;; Expanding with argument should remove all ellipses. | ||
| 410 | (goto-char (point-max)) | ||
| 411 | (backtrace-backward-frame) | ||
| 412 | (backtrace-expand-ellipses '(4)) | ||
| 413 | (goto-char (point-min)) | ||
| 414 | |||
| 415 | (should-error (search-forward "...")) | ||
| 416 | (should (string= (backtrace-tests--get-substring (point-min) (point-max)) | ||
| 417 | results))))) | ||
| 418 | |||
| 419 | |||
| 378 | (ert-deftest backtrace-tests--to-string () | 420 | (ert-deftest backtrace-tests--to-string () |
| 379 | "Backtraces can be produced as strings." | 421 | "Backtraces can be produced as strings." |
| 380 | (let ((frames (ert-with-test-buffer (:name nil) | 422 | (let ((frames (ert-with-test-buffer (:name nil) |
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el index 7594d2466b5..a469b5526c0 100644 --- a/test/lisp/emacs-lisp/cl-print-tests.el +++ b/test/lisp/emacs-lisp/cl-print-tests.el | |||
| @@ -233,5 +233,41 @@ | |||
| 233 | (let ((print-circle t)) | 233 | (let ((print-circle t)) |
| 234 | (should (equal "(0 . #1=(0 . #1#))" (cl-prin1-to-string x)))))) | 234 | (should (equal "(0 . #1=(0 . #1#))" (cl-prin1-to-string x)))))) |
| 235 | 235 | ||
| 236 | (ert-deftest cl-print-tests-print-to-string-with-limit () | ||
| 237 | (let* ((thing10 (make-list 10 'a)) | ||
| 238 | (thing100 (make-list 100 'a)) | ||
| 239 | (thing10x10 (make-list 10 thing10)) | ||
| 240 | (nested-thing (let ((val 'a)) | ||
| 241 | (dotimes (_i 20) | ||
| 242 | (setq val (list val))) | ||
| 243 | val)) | ||
| 244 | ;; Make a consistent environment for this test. | ||
| 245 | (print-circle nil) | ||
| 246 | (print-level nil) | ||
| 247 | (print-length nil)) | ||
| 248 | |||
| 249 | ;; Print something that fits in the space given. | ||
| 250 | (should (string= (cl-prin1-to-string thing10) | ||
| 251 | (cl-print-to-string-with-limit #'cl-prin1 thing10 100))) | ||
| 252 | |||
| 253 | ;; Print something which needs to be abbreviated and which can be. | ||
| 254 | (should (< (length (cl-print-to-string-with-limit #'cl-prin1 thing100 100)) | ||
| 255 | 100 | ||
| 256 | (length (cl-prin1-to-string thing100)))) | ||
| 257 | |||
| 258 | ;; Print something resistant to easy abbreviation. | ||
| 259 | (should (string= (cl-prin1-to-string thing10x10) | ||
| 260 | (cl-print-to-string-with-limit #'cl-prin1 thing10x10 100))) | ||
| 261 | |||
| 262 | ;; Print something which should be abbreviated even if the limit is large. | ||
| 263 | (should (< (length (cl-print-to-string-with-limit #'cl-prin1 nested-thing 1000)) | ||
| 264 | (length (cl-prin1-to-string nested-thing)))) | ||
| 265 | |||
| 266 | ;; Print with no limits. | ||
| 267 | (dolist (thing (list thing10 thing100 thing10x10 nested-thing)) | ||
| 268 | (let ((rep (cl-prin1-to-string thing))) | ||
| 269 | (should (string= rep (cl-print-to-string-with-limit #'cl-prin1 thing 0))) | ||
| 270 | (should (string= rep (cl-print-to-string-with-limit #'cl-prin1 thing nil))))))) | ||
| 271 | |||
| 236 | 272 | ||
| 237 | ;;; cl-print-tests.el ends here. | 273 | ;;; cl-print-tests.el ends here. |