Mercurial > emacs
annotate lisp/eshell/esh-test.el @ 95523:3c4256715c94
(font_prop_validate_spacing): Fix last change.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Tue, 03 Jun 2008 20:37:41 +0000 |
parents | b5b0801a7637 |
children | 45dbb3c749a6 |
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 |
74509 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
79707 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29876 | 11 ;; it under the terms of the GNU General Public License as published by |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
29876 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29876 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; The purpose of this module is to verify that Eshell works as | |
26 ;; expected. To run it on your system, use the command | |
27 ;; \\[eshell-test]. | |
28 | |
29 ;;; Code: | |
30 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
31 (eval-when-compile |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
32 (require 'eshell) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
33 (require 'esh-util)) |
29876 | 34 (require 'esh-mode) |
35 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
36 (defgroup eshell-test nil |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
37 "This module is meant to ensure that Eshell is working correctly." |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
38 :tag "Eshell test suite" |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
39 :group 'eshell) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
40 |
29876 | 41 ;;; User Variables: |
42 | |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
43 (defface eshell-test-ok |
29876 | 44 '((((class color) (background light)) (:foreground "Green" :bold t)) |
45 (((class color) (background dark)) (:foreground "Green" :bold t))) | |
46 "*The face used to highlight OK result strings." | |
47 :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
|
48 ;; 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
|
49 (put 'eshell-test-ok-face 'face-alias 'eshell-test-ok) |
29876 | 50 |
63533
b7ea6515f1ba
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-431
Miles Bader <miles@gnu.org>
parents:
59120
diff
changeset
|
51 (defface eshell-test-failed |
29876 | 52 '((((class color) (background light)) (:foreground "OrangeRed" :bold t)) |
53 (((class color) (background dark)) (:foreground "OrangeRed" :bold t)) | |
54 (t (:bold t))) | |
55 "*The face used to highlight FAILED result strings." | |
56 :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
|
57 ;; 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
|
58 (put 'eshell-test-failed-face 'face-alias 'eshell-test-failed) |
29876 | 59 |
60 (defcustom eshell-show-usage-metrics nil | |
61 "*If non-nil, display different usage metrics for each Eshell command." | |
62 :set (lambda (symbol value) | |
63 (if value | |
64 (add-hook 'eshell-mode-hook 'eshell-show-usage-metrics) | |
65 (remove-hook 'eshell-mode-hook 'eshell-show-usage-metrics)) | |
66 (set symbol value)) | |
67 :type '(choice (const :tag "No metrics" nil) | |
68 (const :tag "Cons cells consumed" t) | |
69 (const :tag "Time elapsed" 0)) | |
70 :group 'eshell-test) | |
71 | |
72 ;;; Code: | |
73 | |
74 (eval-when-compile | |
75 (defvar test-buffer)) | |
76 | |
77 (defun eshell-insert-command (text &optional func) | |
78 "Insert a command at the end of the buffer." | |
79 (goto-char eshell-last-output-end) | |
80 (insert-and-inherit text) | |
81 (funcall (or func 'eshell-send-input))) | |
82 | |
83 (defun eshell-match-result (regexp) | |
84 "Insert a command at the end of the buffer." | |
85 (goto-char eshell-last-input-end) | |
86 (looking-at regexp)) | |
87 | |
88 (defun eshell-command-result-p (text regexp &optional func) | |
89 "Insert a command at the end of the buffer." | |
90 (eshell-insert-command text func) | |
91 (eshell-match-result regexp)) | |
92 | |
93 (defvar eshell-test-failures nil) | |
94 | |
95 (defun eshell-run-test (module funcsym label command) | |
96 "Test whether FORM evaluates to a non-nil value." | |
97 (when (let ((sym (intern-soft (concat "eshell-" (symbol-name module))))) | |
98 (or (memq sym (eshell-subgroups 'eshell)) | |
99 (eshell-using-module sym))) | |
100 (with-current-buffer test-buffer | |
101 (insert-before-markers | |
102 (format "%-70s " (substring label 0 (min 70 (length label))))) | |
103 (insert-before-markers " ....") | |
104 (eshell-redisplay)) | |
105 (let ((truth (eval command))) | |
106 (with-current-buffer test-buffer | |
107 (delete-backward-char 6) | |
108 (insert-before-markers | |
109 "[" (let (str) | |
110 (if truth | |
111 (progn | |
112 (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
|
113 (put-text-property 0 6 'face 'eshell-test-ok str)) |
29876 | 114 (setq str "FAILED") |
115 (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
|
116 (put-text-property 0 6 'face 'eshell-test-failed str)) |
29876 | 117 str) "]") |
118 (add-text-properties (line-beginning-position) (point) | |
119 (list 'test-func funcsym)) | |
120 (eshell-redisplay))))) | |
121 | |
122 (defun eshell-test-goto-func () | |
123 "Jump to the function that defines a particular test." | |
124 (interactive) | |
125 (let ((fsym (get-text-property (point) 'test-func))) | |
126 (when fsym | |
127 (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
|
128 (library (locate-library (symbol-file fsym 'defun))) |
29876 | 129 (name (substring (symbol-name fsym) |
130 (length "eshell-test--"))) | |
131 (inhibit-redisplay t)) | |
132 (find-file library) | |
133 (goto-char (point-min)) | |
134 (re-search-forward (concat "^(eshell-deftest\\s-+\\w+\\s-+" | |
135 name)) | |
136 (beginning-of-line))))) | |
137 | |
138 (defun eshell-run-one-test (&optional arg) | |
139 "Jump to the function that defines a particular test." | |
140 (interactive "P") | |
141 (let ((fsym (get-text-property (point) 'test-func))) | |
142 (when fsym | |
143 (beginning-of-line) | |
144 (delete-region (point) (line-end-position)) | |
145 (let ((test-buffer (current-buffer))) | |
146 (set-buffer (let ((inhibit-redisplay t)) | |
147 (save-window-excursion (eshell t)))) | |
148 (funcall fsym) | |
149 (unless arg | |
150 (kill-buffer (current-buffer))))))) | |
151 | |
152 ;;;###autoload | |
153 (defun eshell-test (&optional arg) | |
154 "Test Eshell to verify that it works as expected." | |
155 (interactive "P") | |
156 (let* ((begin (eshell-time-to-seconds (current-time))) | |
157 (test-buffer (get-buffer-create "*eshell test*"))) | |
158 (set-buffer (let ((inhibit-redisplay t)) | |
159 (save-window-excursion (eshell t)))) | |
160 (with-current-buffer test-buffer | |
161 (erase-buffer) | |
162 (setq major-mode 'eshell-test-mode) | |
163 (setq mode-name "EShell Test") | |
164 (set (make-local-variable 'eshell-test-failures) 0) | |
165 (local-set-key [(control ?c) (control ?c)] 'eshell-test-goto-func) | |
166 (local-set-key [(control ?c) (control ?r)] 'eshell-run-one-test) | |
167 (local-set-key [(control ?m)] 'eshell-test-goto-func) | |
168 (local-set-key [return] 'eshell-test-goto-func) | |
169 | |
55581
a9bcae5bca8e
2004-05-13 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
52401
diff
changeset
|
170 (insert "Testing Eshell under " (emacs-version)) |
29876 | 171 (switch-to-buffer test-buffer) |
172 (delete-other-windows)) | |
33020 | 173 (eshell-for funcname (sort (all-completions "eshell-test--" |
174 obarray 'functionp) | |
175 'string-lessp) | |
29876 | 176 (with-current-buffer test-buffer |
177 (insert "\n")) | |
178 (funcall (intern-soft funcname))) | |
179 (with-current-buffer test-buffer | |
180 (insert (format "\n\n--- %s --- (completed in %d seconds)\n" | |
181 (current-time-string) | |
182 (- (eshell-time-to-seconds (current-time)) | |
183 begin))) | |
184 (message "Eshell test suite completed: %s failure%s" | |
185 (if (> eshell-test-failures 0) | |
186 (number-to-string eshell-test-failures) | |
187 "No") | |
188 (if (= eshell-test-failures 1) "" "s")))) | |
189 (goto-char eshell-last-output-end) | |
190 (unless arg | |
191 (kill-buffer (current-buffer)))) | |
192 | |
193 | |
194 (defvar eshell-metric-before-command 0) | |
195 (defvar eshell-metric-after-command 0) | |
196 | |
197 (defun eshell-show-usage-metrics () | |
198 "If run at Eshell mode startup, metrics are shown after each command." | |
199 (set (make-local-variable 'eshell-metric-before-command) | |
200 (if (eq eshell-show-usage-metrics t) | |
201 0 | |
202 (current-time))) | |
203 (set (make-local-variable 'eshell-metric-after-command) | |
204 (if (eq eshell-show-usage-metrics t) | |
205 0 | |
206 (current-time))) | |
207 | |
208 (add-hook 'eshell-pre-command-hook | |
209 (function | |
210 (lambda () | |
211 (setq eshell-metric-before-command | |
212 (if (eq eshell-show-usage-metrics t) | |
213 (car (memory-use-counts)) | |
214 (current-time))))) nil t) | |
215 | |
216 (add-hook 'eshell-post-command-hook | |
217 (function | |
218 (lambda () | |
219 (setq eshell-metric-after-command | |
220 (if (eq eshell-show-usage-metrics t) | |
221 (car (memory-use-counts)) | |
222 (current-time))) | |
223 (eshell-interactive-print | |
224 (concat | |
225 (int-to-string | |
226 (if (eq eshell-show-usage-metrics t) | |
227 (- eshell-metric-after-command | |
228 eshell-metric-before-command 7) | |
229 (- (eshell-time-to-seconds | |
230 eshell-metric-after-command) | |
231 (eshell-time-to-seconds | |
232 eshell-metric-before-command)))) | |
233 "\n")))) | |
234 nil t)) | |
235 | |
87088
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
236 (provide 'esh-test) |
ddc1d773fb48
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
237 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
238 ;; arch-tag: 6e32275a-8285-4a4e-b7cf-819aa7c86b8e |
29876 | 239 ;;; esh-test.el ends here |