Mercurial > emacs
annotate lisp/eshell/esh-test.el @ 63711:34f124e4af5e
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 23 Jun 2005 17:30:56 +0000 |
parents | b7ea6515f1ba |
children | 18a818a2ee7c b7da78284d4c |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33020
diff
changeset
|
1 ;;; esh-test.el --- Eshell test suite |
29876 | 2 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2005 Free Software Foundation |
29876 | 4 |
32526 | 5 ;; Author: John Wiegley <johnw@gnu.org> |
6 | |
29876 | 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 2, or (at your option) | |
12 ;; 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; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 (provide 'esh-test) | |
25 | |
26 (eval-when-compile (require 'esh-maint)) | |
27 | |
28 (defgroup eshell-test nil | |
29 "This module is meant to ensure that Eshell is working correctly." | |
30 :tag "Eshell test suite" | |
31 :group 'eshell) | |
32 | |
33 ;;; Commentary: | |
34 | |
35 ;; The purpose of this module is to verify that Eshell works as | |
36 ;; expected. To run it on your system, use the command | |
37 ;; \\[eshell-test]. | |
38 | |
39 ;;; Code: | |
40 | |
41 (require 'esh-mode) | |
42 | |
43 ;;; User Variables: | |
44 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
45 (defface eshell-test-ok |
29876 | 46 '((((class color) (background light)) (:foreground "Green" :bold t)) |
47 (((class color) (background dark)) (:foreground "Green" :bold t))) | |
48 "*The face used to highlight OK result strings." | |
49 :group 'eshell-test) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
50 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
51 (put 'eshell-test-ok-face 'face-alias 'eshell-test-ok) |
29876 | 52 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
53 (defface eshell-test-failed |
29876 | 54 '((((class color) (background light)) (:foreground "OrangeRed" :bold t)) |
55 (((class color) (background dark)) (:foreground "OrangeRed" :bold t)) | |
56 (t (:bold t))) | |
57 "*The face used to highlight FAILED result strings." | |
58 :group 'eshell-test) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
59 ;; backward-compatibility alias |
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
60 (put 'eshell-test-failed-face 'face-alias 'eshell-test-failed) |
29876 | 61 |
62 (defcustom eshell-show-usage-metrics nil | |
63 "*If non-nil, display different usage metrics for each Eshell command." | |
64 :set (lambda (symbol value) | |
65 (if value | |
66 (add-hook 'eshell-mode-hook 'eshell-show-usage-metrics) | |
67 (remove-hook 'eshell-mode-hook 'eshell-show-usage-metrics)) | |
68 (set symbol value)) | |
69 :type '(choice (const :tag "No metrics" nil) | |
70 (const :tag "Cons cells consumed" t) | |
71 (const :tag "Time elapsed" 0)) | |
72 :group 'eshell-test) | |
73 | |
74 ;;; Code: | |
75 | |
76 (eval-when-compile | |
77 (defvar test-buffer)) | |
78 | |
79 (defun eshell-insert-command (text &optional func) | |
80 "Insert a command at the end of the buffer." | |
81 (goto-char eshell-last-output-end) | |
82 (insert-and-inherit text) | |
83 (funcall (or func 'eshell-send-input))) | |
84 | |
85 (defun eshell-match-result (regexp) | |
86 "Insert a command at the end of the buffer." | |
87 (goto-char eshell-last-input-end) | |
88 (looking-at regexp)) | |
89 | |
90 (defun eshell-command-result-p (text regexp &optional func) | |
91 "Insert a command at the end of the buffer." | |
92 (eshell-insert-command text func) | |
93 (eshell-match-result regexp)) | |
94 | |
95 (defvar eshell-test-failures nil) | |
96 | |
97 (defun eshell-run-test (module funcsym label command) | |
98 "Test whether FORM evaluates to a non-nil value." | |
99 (when (let ((sym (intern-soft (concat "eshell-" (symbol-name module))))) | |
100 (or (memq sym (eshell-subgroups 'eshell)) | |
101 (eshell-using-module sym))) | |
102 (with-current-buffer test-buffer | |
103 (insert-before-markers | |
104 (format "%-70s " (substring label 0 (min 70 (length label))))) | |
105 (insert-before-markers " ....") | |
106 (eshell-redisplay)) | |
107 (let ((truth (eval command))) | |
108 (with-current-buffer test-buffer | |
109 (delete-backward-char 6) | |
110 (insert-before-markers | |
111 "[" (let (str) | |
112 (if truth | |
113 (progn | |
114 (setq str " OK ") | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
115 (put-text-property 0 6 'face 'eshell-test-ok str)) |
29876 | 116 (setq str "FAILED") |
117 (setq eshell-test-failures (1+ eshell-test-failures)) | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
118 (put-text-property 0 6 'face 'eshell-test-failed str)) |
29876 | 119 str) "]") |
120 (add-text-properties (line-beginning-position) (point) | |
121 (list 'test-func funcsym)) | |
122 (eshell-redisplay))))) | |
123 | |
124 (defun eshell-test-goto-func () | |
125 "Jump to the function that defines a particular test." | |
126 (interactive) | |
127 (let ((fsym (get-text-property (point) 'test-func))) | |
128 (when fsym | |
129 (let* ((def (symbol-function fsym)) | |
59120
b79ba69139eb
(eshell-test-goto-func): Call symbol-file with `defun'.
Richard M. Stallman <rms@gnu.org>
parents:
55581
diff
changeset
|
130 (library (locate-library (symbol-file fsym 'defun))) |
29876 | 131 (name (substring (symbol-name fsym) |
132 (length "eshell-test--"))) | |
133 (inhibit-redisplay t)) | |
134 (find-file library) | |
135 (goto-char (point-min)) | |
136 (re-search-forward (concat "^(eshell-deftest\\s-+\\w+\\s-+" | |
137 name)) | |
138 (beginning-of-line))))) | |
139 | |
140 (defun eshell-run-one-test (&optional arg) | |
141 "Jump to the function that defines a particular test." | |
142 (interactive "P") | |
143 (let ((fsym (get-text-property (point) 'test-func))) | |
144 (when fsym | |
145 (beginning-of-line) | |
146 (delete-region (point) (line-end-position)) | |
147 (let ((test-buffer (current-buffer))) | |
148 (set-buffer (let ((inhibit-redisplay t)) | |
149 (save-window-excursion (eshell t)))) | |
150 (funcall fsym) | |
151 (unless arg | |
152 (kill-buffer (current-buffer))))))) | |
153 | |
154 ;;;###autoload | |
155 (defun eshell-test (&optional arg) | |
156 "Test Eshell to verify that it works as expected." | |
157 (interactive "P") | |
158 (let* ((begin (eshell-time-to-seconds (current-time))) | |
159 (test-buffer (get-buffer-create "*eshell test*"))) | |
160 (set-buffer (let ((inhibit-redisplay t)) | |
161 (save-window-excursion (eshell t)))) | |
162 (with-current-buffer test-buffer | |
163 (erase-buffer) | |
164 (setq major-mode 'eshell-test-mode) | |
165 (setq mode-name "EShell Test") | |
166 (set (make-local-variable 'eshell-test-failures) 0) | |
167 (local-set-key [(control ?c) (control ?c)] 'eshell-test-goto-func) | |
168 (local-set-key [(control ?c) (control ?r)] 'eshell-run-one-test) | |
169 (local-set-key [(control ?m)] 'eshell-test-goto-func) | |
170 (local-set-key [return] 'eshell-test-goto-func) | |
171 | |
55581
a9bcae5bca8e
2004-05-13 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
172 (insert "Testing Eshell under " (emacs-version)) |
29876 | 173 (switch-to-buffer test-buffer) |
174 (delete-other-windows)) | |
33020 | 175 (eshell-for funcname (sort (all-completions "eshell-test--" |
176 obarray 'functionp) | |
177 'string-lessp) | |
29876 | 178 (with-current-buffer test-buffer |
179 (insert "\n")) | |
180 (funcall (intern-soft funcname))) | |
181 (with-current-buffer test-buffer | |
182 (insert (format "\n\n--- %s --- (completed in %d seconds)\n" | |
183 (current-time-string) | |
184 (- (eshell-time-to-seconds (current-time)) | |
185 begin))) | |
186 (message "Eshell test suite completed: %s failure%s" | |
187 (if (> eshell-test-failures 0) | |
188 (number-to-string eshell-test-failures) | |
189 "No") | |
190 (if (= eshell-test-failures 1) "" "s")))) | |
191 (goto-char eshell-last-output-end) | |
192 (unless arg | |
193 (kill-buffer (current-buffer)))) | |
194 | |
195 | |
196 (defvar eshell-metric-before-command 0) | |
197 (defvar eshell-metric-after-command 0) | |
198 | |
199 (defun eshell-show-usage-metrics () | |
200 "If run at Eshell mode startup, metrics are shown after each command." | |
201 (set (make-local-variable 'eshell-metric-before-command) | |
202 (if (eq eshell-show-usage-metrics t) | |
203 0 | |
204 (current-time))) | |
205 (set (make-local-variable 'eshell-metric-after-command) | |
206 (if (eq eshell-show-usage-metrics t) | |
207 0 | |
208 (current-time))) | |
209 | |
210 (add-hook 'eshell-pre-command-hook | |
211 (function | |
212 (lambda () | |
213 (setq eshell-metric-before-command | |
214 (if (eq eshell-show-usage-metrics t) | |
215 (car (memory-use-counts)) | |
216 (current-time))))) nil t) | |
217 | |
218 (add-hook 'eshell-post-command-hook | |
219 (function | |
220 (lambda () | |
221 (setq eshell-metric-after-command | |
222 (if (eq eshell-show-usage-metrics t) | |
223 (car (memory-use-counts)) | |
224 (current-time))) | |
225 (eshell-interactive-print | |
226 (concat | |
227 (int-to-string | |
228 (if (eq eshell-show-usage-metrics t) | |
229 (- eshell-metric-after-command | |
230 eshell-metric-before-command 7) | |
231 (- (eshell-time-to-seconds | |
232 eshell-metric-after-command) | |
233 (eshell-time-to-seconds | |
234 eshell-metric-before-command)))) | |
235 "\n")))) | |
236 nil t)) | |
237 | |
52401 | 238 ;;; arch-tag: 6e32275a-8285-4a4e-b7cf-819aa7c86b8e |
29876 | 239 ;;; esh-test.el ends here |