aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2017-06-01 22:15:50 +0200
committerStephen Berman2017-06-01 22:15:50 +0200
commit8c0f845b34ff3fc9622fa7a433d8272d94698c44 (patch)
tree48f9747270d19370b490d018f7ec8c94be2f4956
parent6cd374085caa1c506555eef72535a47b91a4b4da (diff)
downloademacs-8c0f845b34ff3fc9622fa7a433d8272d94698c44.tar.gz
emacs-8c0f845b34ff3fc9622fa7a433d8272d94698c44.zip
Correct and isolate the todo-mode test environment
This avoids having to set todo-mode variables globally in the test file and prevents any exisiting user todo-mode files from influencing the tests. * test/lisp/calendar/todo-mode-tests.el: (with-todo-test): New macro. (todo-test-todo-quit01, todo-test-todo-quit02) (todo-test-item-highlighting): Use it.
-rw-r--r--test/lisp/calendar/todo-mode-tests.el110
1 files changed, 59 insertions, 51 deletions
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
index a0d5f01617c..5e1a22b37be 100644
--- a/test/lisp/calendar/todo-mode-tests.el
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -22,11 +22,6 @@
22 22
23;;; Commentary: 23;;; Commentary:
24 24
25;; FIXME:
26;; In its current form this file changes global variables defined in
27;; todo-mode.el, so to avoid problems, these tests should not be run
28;; if todo-mode.el is already loaded.
29
30;;; Code: 25;;; Code:
31 26
32(require 'ert) 27(require 'ert)
@@ -47,12 +42,28 @@
47 todo-test-data-dir) 42 todo-test-data-dir)
48 "Todo Archive mode test file.") 43 "Todo Archive mode test file.")
49 44
50;; (setq todo-directory-orig todo-directory) 45(defmacro with-todo-test (&rest body)
51 46 "Set up an isolated todo-mode test environment."
52(setq todo-directory todo-test-data-dir) 47 `(let* ((todo-test-home (make-temp-file "todo-test-home-"))
48 (process-environment (cons (format "HOME=%s" todo-test-home)
49 process-environment))
50 (todo-directory todo-test-data-dir)
51 (todo-default-todo-file (todo-short-file-name
52 (car (funcall todo-files-function)))))
53 ,@body))
54
55;; (defun todo-test-show (num &optional archive)
56;; "Display category NUM of test todo file.
57;; With non-nil ARCHIVE argument, display test archive file category."
58;; (let* ((file (if archive todo-test-archive-1 todo-test-file-1))
59;; (buf (find-file-noselect file)))
60;; (set-buffer buf)
61;; (if archive (todo-archive-mode) (todo-mode))
62;; (setq todo-category-number num)
63;; (todo-category-select)))
53 64
54(defun todo-test-get-archive (num) 65(defun todo-test-get-archive (num)
55 "Make buffer displaying archive category NUM current." 66 "Display category NUM of todo archive test file."
56 (let ((archive-buf (find-file-noselect todo-test-archive-1))) 67 (let ((archive-buf (find-file-noselect todo-test-archive-1)))
57 (set-buffer archive-buf) 68 (set-buffer archive-buf)
58 (todo-archive-mode) 69 (todo-archive-mode)
@@ -71,58 +82,55 @@ corresponding todo-mode category current, if it exits, otherwise
71the current todo-mode category. Quitting todo-mode without an 82the current todo-mode category. Quitting todo-mode without an
72intermediate buffer switch should not make the archive buffer 83intermediate buffer switch should not make the archive buffer
73current again." 84current again."
74 (todo-test-get-archive 2) 85 (with-todo-test
75 (let ((cat-name (todo-current-category))) 86 (todo-test-get-archive 2)
76 (todo-quit) 87 (let ((cat-name (todo-current-category)))
77 (should (todo-test-is-current-buffer todo-test-file-1)) 88 (todo-quit)
78 (should (equal (todo-current-category) cat-name)) 89 (should (todo-test-is-current-buffer todo-test-file-1))
79 (todo-test-get-archive 1) 90 (should (equal (todo-current-category) cat-name))
80 (setq cat-name (todo-current-category)) 91 (todo-test-get-archive 1)
81 (todo-quit) 92 (setq cat-name (todo-current-category))
82 (should (todo-test-is-current-buffer todo-test-file-1)) 93 (todo-quit)
83 (should (equal todo-category-number 1)) 94 (should (todo-test-is-current-buffer todo-test-file-1))
84 (todo-forward-category) ; Category 2 in todo file now current. 95 (should (equal todo-category-number 1))
85 (todo-test-get-archive 3) ; No corresponding category in todo file. 96 (todo-forward-category) ; Category 2 in todo file now current.
86 (setq cat-name (todo-current-category)) 97 (todo-test-get-archive 3) ; No corresponding category in todo file.
87 (todo-quit) 98 (setq cat-name (todo-current-category))
88 (should (todo-test-is-current-buffer todo-test-file-1)) 99 (todo-quit)
89 (should (equal todo-category-number 2)) 100 (should (todo-test-is-current-buffer todo-test-file-1))
90 (todo-quit) 101 (should (equal todo-category-number 2))
91 (should-not (todo-test-is-current-buffer todo-test-archive-1)))) 102 (todo-quit)
103 (should-not (todo-test-is-current-buffer todo-test-archive-1)))))
92 104
93(ert-deftest todo-test-todo-quit02 () ; bug#27121 105(ert-deftest todo-test-todo-quit02 () ; bug#27121
94 "Test the behavior of todo-quit with todo and non-todo buffers. 106 "Test the behavior of todo-quit with todo and non-todo buffers.
95If the buffer made current by invoking todo-quit in a todo-mode 107If the buffer made current by invoking todo-quit in a todo-mode
96buffer is buried by quit-window, the todo-mode buffer should not 108buffer is buried by quit-window, the todo-mode buffer should not
97become current." 109become current."
98 (todo-test-get-archive 2) 110 (with-todo-test
99 (todo-show) 111 (todo-show)
100 (should (todo-test-is-current-buffer todo-test-file-1)) 112 (should (todo-test-is-current-buffer todo-test-file-1))
101 (let ((dir (dired default-directory))) 113 (let ((dir (dired default-directory)))
102 (todo-show) 114 (todo-show)
103 (todo-quit) 115 (todo-quit)
104 (should (equal (current-buffer) dir)) 116 (should (equal (current-buffer) dir))
105 (quit-window) 117 (quit-window)
106 (should-not (todo-test-is-current-buffer todo-test-file-1)))) 118 (should-not (todo-test-is-current-buffer todo-test-file-1)))))
107 119
108(ert-deftest todo-test-item-highlighting () ; bug#27133 120(ert-deftest todo-test-item-highlighting () ; bug#27133
109 "Test whether `todo-toggle-item-highlighting' highlights whole item. 121 "Test whether `todo-toggle-item-highlighting' highlights whole item.
110In particular, all lines of a multiline item should be highlighted." 122In particular, all lines of a multiline item should be highlighted."
111 (todo-test-get-archive 2) 123 (with-todo-test
112 (todo-show) 124 (todo-show)
113 (todo-jump-to-category nil "testcat1") ; For test rerun. 125 (todo-jump-to-category nil "testcat1") ; For test rerun.
114 (todo-toggle-item-highlighting) 126 (todo-toggle-item-highlighting)
115 (let ((end (1- (todo-item-end))) 127 (let ((end (1- (todo-item-end)))
116 (beg (todo-item-start))) 128 (beg (todo-item-start)))
117 (should (eq (get-char-property beg 'face) 'hl-line)) 129 (should (eq (get-char-property beg 'face) 'hl-line))
118 (should (eq (get-char-property end 'face) 'hl-line)) 130 (should (eq (get-char-property end 'face) 'hl-line))
119 (should (> (count-lines beg end) 1)) 131 (should (> (count-lines beg end) 1))
120 (should (eq (next-single-char-property-change beg 'face) (1+ end)))) 132 (should (eq (next-single-char-property-change beg 'face) (1+ end))))
121 (todo-toggle-item-highlighting)) ; Turn off highlighting (for test rerun). 133 (todo-toggle-item-highlighting))) ; Turn off highlighting (for test rerun).
122
123
124;; FIXME: must do this only after running all tests!
125;; (setq todo-directory todo-directory-orig)
126 134
127(provide 'todo-mode-tests) 135(provide 'todo-mode-tests)
128;;; todo-mode-tests.el ends here 136;;; todo-mode-tests.el ends here