diff options
| author | Clément Pit--Claudel | 2016-12-05 00:52:14 -0500 |
|---|---|---|
| committer | Clément Pit--Claudel | 2016-12-12 17:41:27 -0500 |
| commit | 27cada035a79b633e856a437dd0e037acc1d61c6 (patch) | |
| tree | b02c80fe4e7b4ce9fe54912118e4fa5e723723c5 /test | |
| parent | a41ded87b318ce3cbeb0ba3624bcb83ae3b8a437 (diff) | |
| download | emacs-27cada035a79b633e856a437dd0e037acc1d61c6.tar.gz emacs-27cada035a79b633e856a437dd0e037acc1d61c6.zip | |
Move backtrace to ELisp using a new mapbacktrace primitive
* src/eval.c (get_backtrace_starting_at, backtrace_frame_apply)
(Fmapbacktrace, Fbacktrace_frame_internal): New functions.
(get_backtrace_frame, Fbacktrace_debug): Use `get_backtrace_starting_at'.
* lisp/subr.el (backtrace--print-frame): New function.
(backtrace): Reimplement using `backtrace--print-frame' and `mapbacktrace'.
(backtrace-frame): Reimplement using `backtrace-frame--internal'.
* lisp/emacs-lisp/debug.el (debugger-setup-buffer): Pass a base to
`mapbacktrace' instead of searching for "(debug" in the output of
`backtrace'.
* test/lisp/subr-tests.el (subr-test-backtrace-simple-tests)
(subr-test-backtrace-integration-test): New tests.
* doc/lispref/debugging.texi (Internals of Debugger): Document
`mapbacktrace' and missing argument BASE of `backtrace-frame'.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/subr-tests.el | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index ce212903c9d..82a70ca072b 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el | |||
| @@ -224,5 +224,52 @@ | |||
| 224 | (error-message-string (should-error (version-to-list "beta22_8alpha3"))) | 224 | (error-message-string (should-error (version-to-list "beta22_8alpha3"))) |
| 225 | "Invalid version syntax: `beta22_8alpha3' (must start with a number)")))) | 225 | "Invalid version syntax: `beta22_8alpha3' (must start with a number)")))) |
| 226 | 226 | ||
| 227 | (defun subr-test--backtrace-frames-with-backtrace-frame (base) | ||
| 228 | "Reference implementation of `backtrace-frames'." | ||
| 229 | (let ((idx 0) | ||
| 230 | (frame nil) | ||
| 231 | (frames nil)) | ||
| 232 | (while (setq frame (backtrace-frame idx base)) | ||
| 233 | (push frame frames) | ||
| 234 | (setq idx (1+ idx))) | ||
| 235 | (nreverse frames))) | ||
| 236 | |||
| 237 | (defun subr-test--frames-2 (base) | ||
| 238 | (let ((_dummy nil)) | ||
| 239 | (progn ;; Add a few frames to top of stack | ||
| 240 | (unwind-protect | ||
| 241 | (cons (mapcar (pcase-lambda (`(,evald ,func ,args ,_)) | ||
| 242 | `(,evald ,func ,@args)) | ||
| 243 | (backtrace-frames base)) | ||
| 244 | (subr-test--backtrace-frames-with-backtrace-frame base)))))) | ||
| 245 | |||
| 246 | (defun subr-test--frames-1 (base) | ||
| 247 | (subr-test--frames-2 base)) | ||
| 248 | |||
| 249 | (ert-deftest subr-test-backtrace-simple-tests () | ||
| 250 | "Test backtrace-related functions (simple tests). | ||
| 251 | This exercises `backtrace-frame', and indirectly `mapbacktrace'." | ||
| 252 | ;; `mapbacktrace' returns nil | ||
| 253 | (should (equal (mapbacktrace #'ignore) nil)) | ||
| 254 | ;; Unbound BASE is silently ignored | ||
| 255 | (let ((unbound (make-symbol "ub"))) | ||
| 256 | (should (equal (backtrace-frame 0 unbound) nil)) | ||
| 257 | (should (equal (mapbacktrace #'error unbound) nil))) | ||
| 258 | ;; First frame is backtrace-related function | ||
| 259 | (should (equal (backtrace-frame 0) '(t backtrace-frame 0))) | ||
| 260 | (should (equal (catch 'ret | ||
| 261 | (mapbacktrace (lambda (&rest args) (throw 'ret args)))) | ||
| 262 | '(t mapbacktrace ((lambda (&rest args) (throw 'ret args))) nil))) | ||
| 263 | ;; Past-end NFRAMES is silently ignored | ||
| 264 | (should (equal (backtrace-frame most-positive-fixnum) nil))) | ||
| 265 | |||
| 266 | (ert-deftest subr-test-backtrace-integration-test () | ||
| 267 | "Test backtrace-related functions (integration test). | ||
| 268 | This exercises `backtrace-frame', `backtrace-frames', and | ||
| 269 | indirectly `mapbacktrace'." | ||
| 270 | ;; Compare two implementations of backtrace-frames | ||
| 271 | (let ((frame-lists (subr-test--frames-1 'subr-test--frames-2))) | ||
| 272 | (should (equal (car frame-lists) (cdr frame-lists))))) | ||
| 273 | |||
| 227 | (provide 'subr-tests) | 274 | (provide 'subr-tests) |
| 228 | ;;; subr-tests.el ends here | 275 | ;;; subr-tests.el ends here |