aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGemini Lasswell2018-06-19 07:27:41 -0700
committerGemini Lasswell2018-08-03 08:53:02 -0700
commite09120d68694272ea5efbe13b16936b4382389d8 (patch)
tree99f072a54e22202ee74969370722564a519e27a7 /test
parent8a7620955b4d859caecd9a5dc9f2a986baf994fd (diff)
downloademacs-e09120d68694272ea5efbe13b16936b4382389d8.tar.gz
emacs-e09120d68694272ea5efbe13b16936b4382389d8.zip
Add backtrace-mode and use it in the debugger, ERT and Edebug
* doc/lispref/debugging.texi (Using Debugger): Remove explanation of backtrace buffer. Refer to new node. (Backtraces): New node. (Debugger Commands): Refer to new node. Remove 'v'. * doc/lispref/edebug.texi (Edebug Misc): Refer to new node. * doc/misc/ert.texi (Running Tests Interactively): Refer to new node. * lisp/emacs-lisp-backtrace.el: New file. * test/lisp/emacs-lisp/backtrace-tests.el: New file. * lisp/emacs-lisp/debug.el: (debugger-buffer-state): New cl-defstruct. (debugger--restore-buffer-state): New function. (debug): Use a debugger-buffer-state object to save and restore buffer state. Fix bug#15749 by leaving an unused buffer in debugger-mode, empty, instead of in fundamental-mode, and then when reusing a buffer, not calling debugger-mode if the buffer is already in debugger-mode. (debugger-insert-backtrace): Remove. (debugger-setup-buffer): Use backtrace-mode. (debugger--insert-header): New function. (debugger-continue, debugger-return-value): Change check for flags to use backtrace-frames. (debugger-frame-number): Determine backtrace frame number from backtrace-frames. (debugger--locals-visible-p, debugger--insert-locals) (debugger--show-locals, debugger--hide-locals) (debugger-toggle-locals): Remove. (debugger-mode-map): Make a child of backtrace-mode-map. Move navigation commands to backtrace-mode-map. Bind 'q' to debugger-quit instead of top-level. Make Help Follow menu item call backtrace-help-follow-symbol. (debugger-mode): Derive from backtrace-mode. (debug-help-follow): Remove. Move body of this function to 'backtrace-help-follow-symbol' in backtrace.el. (debugger-quit): New function. * lisp/emacs-lisp/edebug.el (edebug-unwrap-results): Remove warning in docstring about circular results. (edebug-unwrap): Use pcase. (edebug-unwrap1): New function to unwrap circular objects. (edebug-unwrap*): Use it. (edebug--frame): New cl-defstruct. (edebug-backtrace): Call the buffer *Edebug Backtrace* and use backtrace-mode. Get the frames from edebug--backtrace-frames. (edebug--backtrace-frames, edebug--unwrap-and-add-info) (edebug--symbol-not-prefixed-p): New functions. * lisp/emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-for-backtraces) (lisp-el-font-lock-keywords-for-backtraces-1) (lisp-el-font-lock-keywords-for-backtraces-2): New constants. * lisp/emacs-lisp/ert.el (ert--print-backtrace): Remove. (ert--run-test-debugger): Use backtrace-get-frames. (ert-run-tests-batch): Use backtrace-to-string. (ert-results-pop-to-backtrace-for-test-at-point): Use backtrace-mode. (ert--insert-backtrace-header): New function. * tests/lisp/emacs-lisp/ert-tests.el (ert-test--which-file): Use backtrace-frame slot accessor.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/backtrace-tests.el89
-rw-r--r--test/lisp/emacs-lisp/ert-tests.el2
2 files changed, 90 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el b/test/lisp/emacs-lisp/backtrace-tests.el
new file mode 100644
index 00000000000..75da468494b
--- /dev/null
+++ b/test/lisp/emacs-lisp/backtrace-tests.el
@@ -0,0 +1,89 @@
1;;; backtrace-tests.el --- Tests for emacs-lisp/backtrace.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2018 Free Software Foundation, Inc.
4
5;; Author: Gemini Lasswell
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Code:
23
24(require 'backtrace)
25(require 'ert)
26(require 'seq)
27
28;; Create a backtrace frames list with several frames.
29;; TODO load this from an el file in backtrace-resources/ so the tests
30;; can be byte-compiled.
31(defvar backtrace-tests--frames nil)
32
33(defun backtrace-tests--func1 (arg1 arg2)
34 (setq backtrace-tests--frames (backtrace-get-frames nil))
35 (list arg1 arg2))
36
37(defun backtrace-tests--func2 (arg)
38 (list arg))
39
40(defun backtrace-tests--func3 (arg)
41 (let ((foo (list 'a arg 'b)))
42 (list foo (backtrace-tests--func2 arg) (backtrace-tests--func1 arg 0))))
43
44(defun backtrace-tests--create-backtrace-frames ()
45 (backtrace-tests--func3 "string")
46 ;; Discard frames before this one.
47 (let (this-index)
48 (dotimes (index (length backtrace-tests--frames))
49 (when (eq (backtrace-frame-fun (nth index backtrace-tests--frames))
50 'backtrace-tests--create-backtrace-frames)
51 (setq this-index index)))
52 (setq backtrace-tests--frames (seq-subseq backtrace-tests--frames
53 0 (1+ this-index)))))
54
55(backtrace-tests--create-backtrace-frames)
56
57;; TODO check that debugger-batch-max-lines still works
58
59(defun backtrace-tests--insert-header ()
60 (insert "Test header\n"))
61
62(defmacro backtrace-tests--with-buffer (&rest body)
63 `(with-temp-buffer
64 (backtrace-mode)
65 (setq backtrace-frames backtrace-tests--frames)
66 (setq backtrace-insert-header-function #'backtrace-tests--insert-header)
67 (backtrace-print)
68 ,@body))
69
70;;; Tests
71(ert-deftest backtrace-tests--to-string ()
72 (should (string= (backtrace-to-string backtrace-tests--frames)
73 " backtrace-get-frames(nil)
74 (setq backtrace-tests--frames (backtrace-get-frames nil))
75 backtrace-tests--func1(\"string\" 0)
76 (list foo (backtrace-tests--func2 arg) (backtrace-tests--func1 arg 0))
77 (let ((foo (list 'a arg 'b))) (list foo (backtrace-tests--func2 arg) (backtrace-tests--func1 arg 0)))
78 backtrace-tests--func3(\"string\")
79 backtrace-tests--create-backtrace-frames()
80")))
81
82(provide 'backtrace-tests)
83
84;; These tests expect to see non-byte compiled stack frames.
85;; Local Variables:
86;; no-byte-compile: t
87;; End:
88
89;;; backtrace-tests.el ends here
diff --git a/test/lisp/emacs-lisp/ert-tests.el b/test/lisp/emacs-lisp/ert-tests.el
index cb957bd9fd6..1fe5b79ef36 100644
--- a/test/lisp/emacs-lisp/ert-tests.el
+++ b/test/lisp/emacs-lisp/ert-tests.el
@@ -376,7 +376,7 @@ This macro is used to test if macroexpansion in `should' works."
376 (test (make-ert-test :body test-body)) 376 (test (make-ert-test :body test-body))
377 (result (ert-run-test test))) 377 (result (ert-run-test test)))
378 (should (ert-test-failed-p result)) 378 (should (ert-test-failed-p result))
379 (should (eq (nth 1 (car (ert-test-failed-backtrace result))) 379 (should (eq (backtrace-frame-fun (car (ert-test-failed-backtrace result)))
380 'signal)))) 380 'signal))))
381 381
382(ert-deftest ert-test-messages () 382(ert-deftest ert-test-messages ()