diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/backtrace-tests.el | 89 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/ert-tests.el | 2 |
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 () |